Skip to content

fix(android): a USB entry that never claimed or bound does not strand later requests - #1036

Merged
egerev merged 2 commits into
mainfrom
bb/usb-terminal-entry-release-thr_ngb3g9karf
Nov 18, 2026
Merged

egerev merged 2 commits into
mainfrom
bb/usb-terminal-entry-release-thr_ngb3g9karf

Conversation

@egerev

@egerev egerev commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

UsbLifecycle.refresh never replaced an ended Entry whose receipt is None. A connector cancelled or refused before its first serial claim therefore blocked every later, separately admitted request for the same owner/device until service restart (the open finding retained in #1029).

An entry is replaced only when all of these hold:

  • Its connector task is done and its cleanup never left not_needed. _run sets cleanup_unconfirmed synchronously after the serial claim and before bind_usb, so not_needed means no claim, no bind call, and therefore no forward, watch or receipt.
  • Its own close has settled.
  • The candidate is a different request: not its run, its handle, or any request whose own entry already ended this way. The lifecycle records those (owner, request) pairs, so an ended request cannot take the entry back after its replacement also ends untouched.

The old entry stays in place until the new request actually passes packages(), journal.blocked() and admit(). If the new request has no active order or is refused, the old entry is kept. Every receipt-bearing path is unchanged.

New real-service tests use the shared synthetic ADB forward table and phone listener. One barrier holds the first connector tasks before their first statement.

  • Cancellation. The lease is released while the first connector waits at the barrier: no ADB call, no receipt. A new lease request then acquires exactly once, with at most one wake per order. This test fails on the parent source; the new request never gets a forward.
  • Access epoch change. The original request, first as a run and then as its retained handle, never gets another entry or acquisition. A new request has no active order at the new epoch, so nothing is collected and the ended entry stays.
  • Pre-receipt bind failure. An unconfirmed listing before acquisition leaves cleanup_unconfirmed, so later requests stay held: no retry, no --no-rebind, no row.
  • Re-admission. Request A ends untouched and B replaces it; B also ends untouched and access is restored. Neither A nor B (run or retained handle) takes the entry back or acquires, and a third request then acquires once. Without the ended-request record, A takes the entry back.

Validation: the cancellation case fails on the parent source and the re-admission case fails without the ended-request record. All four pass after the fix. The full Android suite passes locally: 1057 passed, 5 skipped, existing tests unchanged. Ruff is clean. The source is 341 lines, below the size-budget threshold. No live phone, ADB, model or provider action.

First head 26746c4 (run 44266637409): checks / services failed on two Android tests.

  • My cancellation test wrongly forbade the new request's own ordinary forward removal; it is corrected here.
  • Unchanged test_usb_order_restart_recovery.py:342 timed out waiting for the superseding row. 22 local runs passed, including single-CPU runs. A local probe showed the new branch is never reached in that test, and that module runs before the new one, so this change did not plausibly cause it. Without a state dump the interleaving is unidentified; it is the same location as the earlier run 44045047078 race. Not retried; this new head runs normal CI.
  • Security report also fails on main's latest push: new advisory GHSA-fc5q-39xc-vjpf for picomatch 4.0.7 in services/calls/frontend/package-lock.json, unrelated to this diff.

Not covered: installed adb/listener behaviour remains live acceptance. Source and CI completion is not installation.

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

🤖 Generated with Claude Code

… later requests

UsbLifecycle.refresh kept an ended Entry with receipt=None forever, so a
connector cancelled or refused before its first serial claim blocked every
later, separately admitted request for that owner/device until restart.

Replace such an entry only when its connector never left cleanup
'not_needed' (no serial claim, no bind call, so no forward, watch or
receipt), its close has settled, and the candidate is a different request.
The old entry stays until the new request actually passes packages,
journal and admission checks. A bind that failed before its receipt, the
ended request itself (run or retained handle), epoch changes and every
receipt-bearing path keep their existing held/no-retry behaviour.

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
Record each request whose entry ended before claiming the serial or
calling bind, and never let it replace a later untouched entry: without
this, request A could take the entry back once B's replacement also ended
untouched. Correct the cancellation test, which wrongly forbade the new
request's own ordinary forward removal; it now asserts no removal before
the single acquisition.

Spec: ANYM-997

Signed-off-by: egerev <egor@gosync.ai>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@egerev
egerev added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit b2760dc Nov 18, 2026
30 of 31 checks passed
@egerev
egerev deleted the bb/usb-terminal-entry-release-thr_ngb3g9karf branch November 18, 2026 09:08
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