Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bdraco
Copy link
Member

@bdraco bdraco commented Oct 18, 2025

What does this implement/fix?

This reverts the change made in #1401 as it turned out to not scale well. It was simple enough to continue use container_pointer, but add a new version for non-template values called container_pointer_no_template

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

  • fixes

Pull request in esphome (if applicable):

  • esphome/esphome#

Checklist:

  • The code change is tested and works locally.
  • If api.proto was modified, a linked pull request has been made to esphome with the same changes.
  • Tests have been added to verify that the new code works (under tests/ folder).

This reverts the change made in #1401 as it turned out to
not scale well. It was simple enough to continue use container_pointer,
but add a new version for non-template values called container_pointer_no_template
@bdraco bdraco added the minor label Oct 18, 2025
@codecov
Copy link

codecov bot commented Oct 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7b4afd0) to head (df10a5f).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1402   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         3310      3310           
=========================================
  Hits          3310      3310           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 18, 2025

CodSpeed Performance Report

Merging #1402 will not alter performance

Comparing fix_light_bitmask (df10a5f) with main (7b4afd0)1

Summary

✅ 11 untouched

Footnotes

  1. No successful run was found on main (3585ffe) during the generation of this report, so 7b4afd0 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@bdraco bdraco merged commit 42a5cf8 into main Oct 18, 2025
12 of 13 checks passed
@bdraco bdraco deleted the fix_light_bitmask branch October 18, 2025 22:43
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 18, 2025

Walkthrough

Protobuf schema changes replace an enum bitmask field option with a container pointer approach across three files. The ListEntitiesLightResponse.supported_color_modes field is updated from enum_as_bitmask annotation to container_pointer_no_template in api.proto. The custom field option definition is correspondingly updated in api_options.proto, with generated Python descriptor bindings regenerated.

Changes

Cohort / File(s) Summary
Protobuf Schema Updates
aioesphomeapi/api.proto, aioesphomeapi/api_options.proto
Replaces enum_as_bitmask field option with container_pointer_no_template. The supported_color_modes field in ListEntitiesLightResponse changes annotation from [(enum_as_bitmask) = true] to [(container_pointer_no_template) = "light::ColorModeMask"]. Custom field option 50014 in google.protobuf.FieldOptions extension changes from optional bool to optional string.
Generated Protobuf Bindings
aioesphomeapi/api_options_pb2.py
Serialized descriptor DESCRIPTOR is updated to reflect field option type change from bool to string at index 50014.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • esphome/aioesphomeapi#1284: Modifies protobuf field options and repeated-field annotations to control generated container types for repeated fields.
  • esphome/aioesphomeapi#1187: Modifies the ListEntitiesLightResponse.supported_color_modes field type annotation in the same api.proto file.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "Replace enum_as_bitmask with container_pointer_no_template" directly and accurately describes the primary change across the modified files. The raw summary confirms that the field option enum_as_bitmask is being replaced with container_pointer_no_template in both the api.proto and api_options.proto files, and the PR description explicitly states this is the intended change. The title is concise, specific, and clearly conveys the main modification to someone reviewing the version history.
Description Check ✅ Passed The pull request description is clearly related to the changeset. It explains that the PR reverts a previous approach from #1401 and implements a new container_pointer_no_template solution instead of enum_as_bitmask, which directly aligns with the modifications shown in the raw summary. The description provides context about why the change is needed (scalability concerns) and categorizes it as a bugfix, demonstrating understanding of the purpose behind the changes.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix_light_bitmask

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3585ffe and df10a5f.

📒 Files selected for processing (3)
  • aioesphomeapi/api.proto (1 hunks)
  • aioesphomeapi/api_options.proto (1 hunks)
  • aioesphomeapi/api_options_pb2.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

  • Do not generate or add any sequence diagrams

Files:

  • aioesphomeapi/api_options.proto
  • aioesphomeapi/api.proto
  • aioesphomeapi/api_options_pb2.py
🔇 Additional comments (2)
aioesphomeapi/api.proto (1)

509-509: LGTM on switching to container_pointer_no_template; confirm generator + type exist.

Change aligns with the new option. Please verify the C++ symbol light::ColorModeMask exists and the codegen path for container_pointer_no_template is implemented and tested end-to-end.

aioesphomeapi/api_options.proto (1)

74-82: Based on my verification:

Evidence gathered:

  • ✅ No enum_as_bitmask usages remain anywhere in the codebase (confirmed zero matches across all files)
  • ✅ Tag 50014 reuse is safe; the old bool-typed enum_as_bitmask is completely removed
  • container_pointer_no_template is already in active use in api.proto:509 with the new string-typed option at tag 50014, indicating the generator supports it
  • container_pointer documentation at lines 42–66 explicitly mentions lifetime requirements ("remains valid during message encoding"), but container_pointer_no_template (lines 74–82) omits this crucial detail

The documentation improvement is valid and necessary to prevent misuse. The tag reuse is safe.


Add explicit lifetime requirements to match container_pointer documentation.

The docs reference similarity to container_pointer but omit the lifetime constraint that exists there. Add the safety requirement to prevent accidental use-after-free:

    // container_pointer_no_template: Use a non-template container type for repeated fields
    // Similar to container_pointer, but for containers that don't take template parameters.
+    //
+    // The corresponding C++ code must provide const reference access to a container
+    // that remains valid during message encoding (same lifetime requirement as container_pointer).
     // The container type is used as-is without appending element type.
     // The container must have:
     // - begin() and end() methods returning iterators



DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x11\x61pi_options.proto\x1a google/protobuf/descriptor.proto\"\x06\n\x04void*F\n\rAPISourceType\x12\x0f\n\x0bSOURCE_BOTH\x10\x00\x12\x11\n\rSOURCE_SERVER\x10\x01\x12\x11\n\rSOURCE_CLIENT\x10\x02:E\n\x16needs_setup_connection\x12\x1e.google.protobuf.MethodOptions\x18\x8e\x08 \x01(\x08:\x04true:C\n\x14needs_authentication\x12\x1e.google.protobuf.MethodOptions\x18\x8f\x08 \x01(\x08:\x04true:/\n\x02id\x12\x1f.google.protobuf.MessageOptions\x18\x8c\x08 \x01(\r:\x01\x30:M\n\x06source\x12\x1f.google.protobuf.MessageOptions\x18\x8d\x08 \x01(\x0e\x32\x0e.APISourceType:\x0bSOURCE_BOTH:/\n\x05ifdef\x12\x1f.google.protobuf.MessageOptions\x18\x8e\x08 \x01(\t:3\n\x03log\x12\x1f.google.protobuf.MessageOptions\x18\x8f\x08 \x01(\x08:\x04true:9\n\x08no_delay\x12\x1f.google.protobuf.MessageOptions\x18\x90\x08 \x01(\x08:\x05\x66\x61lse:4\n\nbase_class\x12\x1f.google.protobuf.MessageOptions\x18\x91\x08 \x01(\t:3\n\x0b\x66ield_ifdef\x12\x1d.google.protobuf.FieldOptions\x18\x92\x08 \x01(\t:9\n\x10\x66ixed_array_size\x12\x1d.google.protobuf.FieldOptions\x18\xd7\x86\x03 \x01(\r:<\n\x0cno_zero_copy\x12\x1d.google.protobuf.FieldOptions\x18\xd8\x86\x03 \x01(\x08:\x05\x66\x61lse:E\n\x15\x66ixed_array_skip_zero\x12\x1d.google.protobuf.FieldOptions\x18\xd9\x86\x03 \x01(\x08:\x05\x66\x61lse:@\n\x17\x66ixed_array_size_define\x12\x1d.google.protobuf.FieldOptions\x18\xda\x86\x03 \x01(\t:G\n\x1e\x66ixed_array_with_length_define\x12\x1d.google.protobuf.FieldOptions\x18\xdb\x86\x03 \x01(\t:A\n\x11pointer_to_buffer\x12\x1d.google.protobuf.FieldOptions\x18\xdc\x86\x03 \x01(\x08:\x05\x66\x61lse::\n\x11\x63ontainer_pointer\x12\x1d.google.protobuf.FieldOptions\x18\xd1\x86\x03 \x01(\t:<\n\x0c\x66ixed_vector\x12\x1d.google.protobuf.FieldOptions\x18\xdd\x86\x03 \x01(\x08:\x05\x66\x61lse:?\n\x0f\x65num_as_bitmask\x12\x1d.google.protobuf.FieldOptions\x18\xde\x86\x03 \x01(\x08:\x05\x66\x61lse')
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x11\x61pi_options.proto\x1a google/protobuf/descriptor.proto\"\x06\n\x04void*F\n\rAPISourceType\x12\x0f\n\x0bSOURCE_BOTH\x10\x00\x12\x11\n\rSOURCE_SERVER\x10\x01\x12\x11\n\rSOURCE_CLIENT\x10\x02:E\n\x16needs_setup_connection\x12\x1e.google.protobuf.MethodOptions\x18\x8e\x08 \x01(\x08:\x04true:C\n\x14needs_authentication\x12\x1e.google.protobuf.MethodOptions\x18\x8f\x08 \x01(\x08:\x04true:/\n\x02id\x12\x1f.google.protobuf.MessageOptions\x18\x8c\x08 \x01(\r:\x01\x30:M\n\x06source\x12\x1f.google.protobuf.MessageOptions\x18\x8d\x08 \x01(\x0e\x32\x0e.APISourceType:\x0bSOURCE_BOTH:/\n\x05ifdef\x12\x1f.google.protobuf.MessageOptions\x18\x8e\x08 \x01(\t:3\n\x03log\x12\x1f.google.protobuf.MessageOptions\x18\x8f\x08 \x01(\x08:\x04true:9\n\x08no_delay\x12\x1f.google.protobuf.MessageOptions\x18\x90\x08 \x01(\x08:\x05\x66\x61lse:4\n\nbase_class\x12\x1f.google.protobuf.MessageOptions\x18\x91\x08 \x01(\t:3\n\x0b\x66ield_ifdef\x12\x1d.google.protobuf.FieldOptions\x18\x92\x08 \x01(\t:9\n\x10\x66ixed_array_size\x12\x1d.google.protobuf.FieldOptions\x18\xd7\x86\x03 \x01(\r:<\n\x0cno_zero_copy\x12\x1d.google.protobuf.FieldOptions\x18\xd8\x86\x03 \x01(\x08:\x05\x66\x61lse:E\n\x15\x66ixed_array_skip_zero\x12\x1d.google.protobuf.FieldOptions\x18\xd9\x86\x03 \x01(\x08:\x05\x66\x61lse:@\n\x17\x66ixed_array_size_define\x12\x1d.google.protobuf.FieldOptions\x18\xda\x86\x03 \x01(\t:G\n\x1e\x66ixed_array_with_length_define\x12\x1d.google.protobuf.FieldOptions\x18\xdb\x86\x03 \x01(\t:A\n\x11pointer_to_buffer\x12\x1d.google.protobuf.FieldOptions\x18\xdc\x86\x03 \x01(\x08:\x05\x66\x61lse::\n\x11\x63ontainer_pointer\x12\x1d.google.protobuf.FieldOptions\x18\xd1\x86\x03 \x01(\t:<\n\x0c\x66ixed_vector\x12\x1d.google.protobuf.FieldOptions\x18\xdd\x86\x03 \x01(\x08:\x05\x66\x61lse:F\n\x1d\x63ontainer_pointer_no_template\x12\x1d.google.protobuf.FieldOptions\x18\xde\x86\x03 \x01(\t')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Regenerate pb2: serialized descriptor looks corrupted (“void”).*

The AddSerializedFile payload contains a literal “void*” in the message name area, which strongly suggests a stray byte and a broken FileDescriptorProto. Hand-editing pb2 is unsafe and can cause import-time DecodeError or incorrect extension registration. Please re-generate this file with protoc (same compiler/runtime 6.30.0) and commit the unmodified output.

Run this read-only check to highlight the suspicious byte sequence:

I can help script a clean re-gen flow if needed.


🏁 Script executed:

#!/bin/bash
rg -nP -C2 'void\*' aioesphomeapi/api_options_pb2.py

Length of output: 1976


Regenerate pb2: serialized descriptor looks corrupted ("void").*

The api.proto file uses "void" as a return type in RPC method definitions (e.g., returns (void)), which is a keyword, not a message type. The AddSerializedFile payload in line 29 contains a literal "void*" string that should not exist in a legitimate serialized FileDescriptorProto. Do not edit the api_pb2 files manually; instead, regenerate using protoc to resolve this corruption.

🤖 Prompt for AI Agents
In aioesphomeapi/api_options_pb2.py around line 29 the serialized
FileDescriptorProto is corrupted (contains "void*"), so do not edit this
generated file; instead fix and regenerate the .pb2. Open the corresponding
.proto (api.proto), replace any RPCs that use the invalid returns (void) with a
proper message type (e.g., google.protobuf.Empty from
google/protobuf/empty.proto or a defined Void message), ensure import
"google/protobuf/empty.proto" if using Empty, then re-run protoc with the
correct include paths (protoc -I. -I<protobuf_include> --python_out=. api.proto)
to regenerate aioesphomeapi/api_options_pb2.py and verify the AddSerializedFile
payload no longer contains "void*".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants