Skip to content

fix(android): keep an ended USB entry until its replacement is admitted; read reconnect supersession stably - #1042

Merged
egerev merged 2 commits into
mainfrom
bb/usb-reconnect-diagnosis-thr_ngb3g9karf
Nov 18, 2026
Merged

egerev merged 2 commits into
mainfrom
bb/usb-reconnect-diagnosis-thr_ngb3g9karf

Conversation

@egerev

@egerev egerev commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

test_usb_loss_keeps_phone_collection_held_until_reconnected_normal_request_supersedes_it_once (test_usb_order_restart_recovery.py:342) failed in merge-group run 44280383848 (job 134719532952) and PR run 44266637409. Its until waited for exactly two forward rows.

Mechanism (traced on the real lifecycle with fake ADB and listener). After the reconnect, later ordinary acquisitions always add forward rows, and rows are never removed. A healthy run of the unchanged test ends with three rows. len(rows) == 2 held only for about 0.4–0.6 s after second_request returned, so a late first poll can never succeed and the wait times out at 5 s. This is a deterministic false-negative mechanism of the old predicate, and it matches the CI symptom. The retained CI logs have no state dump, so the historical runs' actual first-poll timing and row count remain unknown; this PR does not claim their exact cause.

A (test, line 342 only). Read the first two rows once at least two exist: len(r) >= 2, returning r[:2]. The name, deadline, parameters and every later assertion are unchanged: old id, collection_superseded, reason, new ≠ old, acquisition count, no removal before acquisition, at most one wake per order. Lines 236 and 256 are not touched.

B (production, one line). The trace also showed a real flaw in UsbLifecycle.refresh. The settled branch deleted the ended entry before the replacement request was admitted. When that admission was refused (the new request's native turn was not yet admitted), the key was popped. In the same pass, the ended request's own retained handle acquired a second forward, contrary to #1032's "retaining that request never reacquires its ended connector". The settled branch now keeps the previous entry through the existing kept mechanism until a replacement is actually admitted.

Tests (new files; existing IDs unchanged)

  • test_usb_reconnect_generation_diagnostics.py holds only the new request's app-skill offer, which runs before turn admission. On the parent source it fails every time: "the ended request reacquired". With B it passes.
  • test_usb_reconnect_late_observation.py is a deterministic late observation. A second USB loss and another ordinary request add a third row before the first reconnect is read; its supersession is then checked from the first two rows. The same flow with the original == 2 predicate times out every time with 3 rows. There is no sleep-based delay.

Validation. Proofs on the real source tree, not an in-memory patch:

  • Without B the diagnostic fails; with A and B the 57 USB tests pass.
  • The full Android suite passes: 1059 passed, 5 skipped. Ruff is clean.
  • order_usb_host.py is 341 lines, below the size-budget threshold. The change-path greps are empty.
  • No phone, ADB device, model, native, MCP or production action.

Not changed, separate follow-up. After the new request's own entry ends, request R1 can still acquire again later. That is the same request, source and epoch as the connector that ended on USB loss, through its retained handle. The #1032 contract already forbids it. This PR does not change that path.

Spec: ANYM-997
Change path: AUTO (lifecycle entry retention and one test predicate; no permissions, configuration, migration or live action)
Review record: none (owner 11-11: no reviews)

🤖 Generated with Claude Code

egerev and others added 2 commits November 18, 2026 18:32
…uest awaits admission

Diagnostic regression (fails on current source): after USB loss ends request
A's connector, refresh deletes A's settled entry for the new request B; B's
admission is refused before its native turn starts, the key is popped, and
A's retained handle acquires a second forward in the same pass.

Spec: ANYM-997

Signed-off-by: egerev <egor@gosync.ai>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed; read reconnect supersession stably

refresh deleted a settled ended entry before the candidate replacement was
admitted. When that admission was refused (the new request's native turn not
yet admitted), the key was popped and, in the same pass, the ended request's
retained handle acquired a second forward. Keep the previous entry through the
existing kept mechanism until a replacement is actually admitted.

test_usb_loss_keeps_phone_collection_held_until_reconnected_normal_request_supersedes_it_once
waited for exactly two forward rows. Later ordinary acquisitions always add
rows and rows are never removed, so a late first poll could never succeed
(merge-group run 44280383848, PR run 44266637409). Read the first two rows once
at least two exist; every later assertion is unchanged. A new regression
observes the first reconnect only after a later reconnect added a third row.

Spec: ANYM-997

Signed-off-by: egerev <egor@gosync.ai>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@egerev egerev added the ship Small-fix rule: orchestrator Diff read at head; merge-keeper may enqueue label Nov 18, 2026
@egerev
egerev added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 5c4abf6 Nov 18, 2026
31 checks passed
@egerev
egerev deleted the bb/usb-reconnect-diagnosis-thr_ngb3g9karf branch November 18, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ship Small-fix rule: orchestrator Diff read at head; merge-keeper may enqueue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant