fix(android): stop accepting screen-record rotations once a stop is claimed
Summary
record stop for adb screenrecord could start a new recorder on the device after the recording had ended. A rotation awaiting native work still published its chunk and armed another 170 s timer after finish or forceCleanup had awaited it and finalized, because both awaited the in-flight rotation before refusing further work.
The fix splits the boundary by what each side can actually prove. A stop claims the phase synchronously and arms an abort-based launch admission: startPendingChunk checks it before every candidate dispatch (concurrent start and sequential fallback alike), so no recorder starts after a stop was claimed. The rotation's commit write runs to its real outcome and nothing else decides it: aborting the host command cannot undo the on-device mv -f tmp manifest or prove it never ran, so a commit that succeeds is adopted and the stop collects that chunk like any other committed chunk, and a commit that genuinely fails rolls back with its real result — an unconfirmed rollback keeps the child's path in the marker as pending, and the failure surfaces through rotationFailure instead of a clean stop. A sequential fallback that confirmed it stopped the current recorder records that retirement, so finalization reads the recorder's absence as this recording's own doing rather than as the 180 s platform limit truncating a live recording; a retirement that found the recorder already gone records nothing and the limit disclosure stands. No shim, no new package.
Scope expansion: manifest.ts gained recordingRequestFields, owning the requested-option fields the native marker and descriptor both carry. fallow flagged that duplication plus a rotate complexity breach, so those got owners rather than an allowlist. No CLI, SDK or MCP surface change. No linked issue.
Validation
Branch base f7879cf2d2, head c4760a56722479c6759305fcfac2956da59b2630.
pnpm exec vitest run --project unit-core packages/platform-android/src/recording/runtime.test.ts:
- base + the first three rotation tests: 3 failed | 7 passed —
expected 3 to be 2(extra launch afterfinish, and afterforceCleanup), and 2 committed chunks where a claimed stop must publish none. - head
91c753b658: 10 passed. - head
91c753b658+ the round-2 tests: 3 failed | 10 passed (expected 2 to be 1, rejectionconcurrent start unavailable, adoption of a refused commit) → round-2 headfa0effc59c: 13 passed. - head
fa0effc59c+ the round-3 tests: 3 failed | 12 passed —collects a chunk whose commit published while the stop was in flight:expected [ Array(1) ] to deeply equal [ …(2) ](a chunk the device committed before the stop was discarded);retains the child when the rotation commit fails after the stop was claimedand its remove-failure variant:promise resolved "{ status: 'completed' }" instead of rejecting(an unconfirmed rollback reported a clean stop). - head
a49c253de2: 15 passed. - head
a49c253de2+ the round-4 assertion (no platform-limit warning after an intentional fallback retirement): 1 failed | 14 skipped for that test —AssertionError: expected 'Android adb screenrecord stopped befo…' not to match /platform limit/— → head5bfb20e738: 15 passed. - head
5bfb20e738+ the round-5 test (still discloses the platform limit when the recorder a fallback retired had already exited): 1 failed —AssertionError: expected '' to match /platform limit/(a genuinely limit-expired recorder lost its disclosure) — → headc4760a5672: 16 passed; recording suite 104 passed (14 files);packages/platform-android134 files / 1337 tests passed.
Gate pnpm check:affected --run --head c4760a56722479c6759305fcfac2956da59b2630: all runnable checks passed, exactCommit: true (format, lint, typecheck, layering, fallow, build, vitest-related, unit; coverage skipped, provider-integration deduplicated, replay-android skipped). Receipt: .tmp/validation/run-FGdXbb/receipt.json. The first gate run for this head failed only on test/integration/provider-scenarios/apple-platform-output-guard.test.ts exceeding its 15 s time budget (32.47 s) under full-lane load — an unrelated Apple-simulator timing flake, recorded here rather than touching it; an earlier round's run likewise failed only in src/__tests__/daemon-registration-owner.test.ts (manual graceful stop observed mode forced on a 30 ms grace window), which passes in isolation. CI owns full coverage, native builds and device lanes.
Live (overlap run closed at head 5bfb20e7382d36f05fa0cb256264cfc494886c7f): worktree build verified in the daemon command line (.../t3-ade45b54/dist/src/internal/daemon.js, pid 21604), emulator-5554 (Pixel_9_Pro_XL_API_37, Android 17.0) viewed via device_open, private daemon --state-dir /private/tmp/sm6-r4-state, record start --scope device 11:10:27 (chunk 1 pid 5230). A stopper script sharing the exact --session sm6-r4 --state-dir /private/tmp/sm6-r4-state --serial emulator-5554 constants the start used caught the rotation in flight at 11:13:21.441 — marker holding pendingRemotePath: /sdcard/agent-device-recording-1793528000098.mp4 with two live screenrecord processes (5230 launching child 9229) — and issued record stop in the same millisecond; the stop was accepted (the round-3 miss was a stale session name in the stopper, fixed by one shared constants block). It returned completed, recorder: confirmed, nativePathDisposition: retired, durationMs: 183302, capturedDurationMs: 163659 after 11.3 s: the launch admission refused the rotation's retried launch, the pending child was rolled back, and the output holds the one committed chunk (sm6-run.mp4, 7,176,187 B, ffprobe 163.659 s; final marker: chunk 1 pid 5230, pendingRemotePath null). The only warning is the idle-tail disclosure; no platform-limit/truncation warning. ps -A | grep screenrecord (adb, evidence only): no match immediately after the stop and none at 11:19:06, 334 s after it — past the 200 s requirement and the 170 s rotation window; no *.mp4 left on device beyond the completion journal the next start retires. Sessions [], daemon stop for every state dir used, device_close.
Earlier runs on the same route (previous round, head a49c253de2): a stop 5 s behind an observed in-flight rotation completed with both committed chunks collected (sm6-run.mp4 169.007 s + sm6-run.part-002.mp4 4.178 s, marker pids 19932/27942), no recorder immediately or 200 s after stop. That round's automated overlapping stop itself had failed with a stale session name (no active recording) — the run above closes exactly that gap.
Independent review is arranged by the coordinator; round-1 through round-5 dispositions are in the comment threads. Risk: the unconfirmed-rollback marker path (uncertain stop or failed removal of a rotation child) has unit coverage only — the live overlap exercised its confirmed counterpart (pending child rolled back, marker rewritten without the pending path).