Skip to content

fix(b01): isolate Q7 map response assemblers per subscription - #1051

Merged
allenporter merged 1 commit into
Python-roborock:mainfrom
allenporter:fix-b01-q7-map-reassembly
Nov 16, 2026
Merged

allenporter merged 1 commit into
Python-roborock:mainfrom
allenporter:fix-b01-q7-map-reassembly

Conversation

@allenporter

@allenporter allenporter commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #1048:

  1. Isolate map response assemblers per subscription: B01Q7Channel previously stored a single stateful _map_assembler shared between subscribe_map_pushes() (registered for the lifetime of a connected Q7 device in Q7PropertiesApi.start()) and send_map_command() (MapContentTrait.refresh()). When a fragmented (300, 301) frame arrived on MqttChannel, the push listener drained pending[key] on the final fragment before send_map_command's matcher saw it, causing send_map_command() to time out (or fail decoding if block-aligned). Each send_map_command() call and subscribe_map_pushes() registration now uses its own create_map_response_assembler() instance.
  2. Anchor multi-part completion at seq=1 and check B01_VERSION in the assembler: Unlike V1 (#1004), B01 map fragments have no header marker on seq=1. Checking range(1, seqs[-1] + 1) ensures 3+-part frames arriving out of order (e.g. [3, 2, 1]) do not prematurely emit a block-aligned suffix before seq=1 arrives. Checking message.version == B01_VERSION directly in create_map_response_assembler() also removes the wrapper helpers from B01Q7Channel.
  3. Add protocol mirror tests & concurrent listener regression coverage: Added unit tests for create_map_response_assembler() in tests/protocols/test_b01_q07_protocol.py and concurrent subscribe_map_pushes + send_map_command coverage (plus parametrized ordering) in tests/devices/rpc/test_b01_q7_channel.py.

Fixes #1043

Testing

  • Added failing reproduction tests first against main (6 failed across concurrent push+command timeouts, 3-part out-of-order suffixes, and version filtering), then applied fixes.
  • uv run pytest (2302 passed)
  • uv run pre-commit run --all-files (all hooks passed)

Copilot AI balanced review requested due to automatic review settings November 15, 2026 00:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Lash-L Lash-L added bug Something isn't working Q7 B01 Q7 platform labels Nov 15, 2026

@Lash-L Lash-L left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Automated code review by Gemini 4 Argon in Antigravity using our /review (/code-review) skill (.agents/skills/code-review/SKILL.md / AGENTS.md).

Summary by Layer

  • Protocol (roborock/protocols/b01_q7_protocol.py):
    • Anchors _complete_payload() at seq == 1 (seqs != list(range(1, seqs[-1] + 1))) so multi-part B01 map frames (protocols 300/301) cannot complete prematurely if trailing chunks (seq >= 2) arrive before seq = 1 and happen to form a 16-byte-aligned base64 suffix.
    • Moves the message.version == B01_VERSION guard into create_map_response_assembler() so each assembler instance is self-contained when used directly as a channel response_matcher.
  • Channel / RPC (roborock/devices/rpc/b01_q7_channel.py):
    • Replaces the shared self._map_assembler instance on B01Q7Channel with an isolated create_map_response_assembler() per send_map_command() invocation and per subscribe_map_pushes() subscription (consistent with v1_channel.py creating a fresh map decoder per command).
    • Fixes a race where an active subscribe_map_pushes callback (registered by Q7PropertiesApi.start()) drained pending fragments from the shared assembler before send_map_command()'s subscriber callback processed the completing 301 frame.
  • Tests (tests/devices/rpc/test_b01_q7_channel.py, tests/protocols/test_b01_q07_protocol.py):
    • Consolidates in-order and out-of-order channel reassembly tests with @pytest.mark.parametrize and adds test_send_map_command_with_active_map_push_subscription covering concurrent push subscription + map command execution.
    • Adds direct unit tests for create_map_response_assembler() covering single-part passthrough, 2-part and 3-part out-of-order arrival (including block-aligned suffix arrival before seq = 1), FIFO eviction past _MAX_PENDING_MAP_RESPONSES, and non-matching frames.

No blocking issues or defects found. LGTM!

@Lash-L Lash-L added /review run Code review skill (/review) has been run Passed /review Passed the /review skill check labels Nov 15, 2026
@allenporter
allenporter merged commit 251a1c4 into Python-roborock:main Nov 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Passed /review Passed the /review skill check Q7 B01 Q7 platform /review run Code review skill (/review) has been run

Projects

None yet

Development

Successfully merging this pull request may close these issues.

B01/Q7: fragmented live map responses (protocol 300 + 301) are not reassembled — map image freezes

3 participants