fix(daemon): settle orphaned recording records when a recording starts
Summary
A device that restarts mid-recording can leave its screen recording record open/cleanup-pending with reason ownership-fence-lost. This happens when daemon recovery runs while the device is still booting: Android reports the manifest as missing while /sdcard is not mounted, and recovery then retains the record. Only daemon start and device-claim reconciliation retry it, and a recovered record stop cannot finish it because the recording died with the device. After the claim is gone, every record start on that device fails with cleanup-unconfirmed.
The start preflight now lists the records it refuses on, and record start settles the ones on its own device whose session the daemon no longer holds:
- The settle does what the record's own stop would. It finishes the record with
finishRecoveredDurableCapture, so a video that can still be exported (an iOS simulator recording whose daemon died) lands at its output path, and a laterrecord stopin that session returns it. Only a record that cannot finish, such as the Android reboot case, falls back to the existing exact-owner recovery. - A record on another device is never recovered through the start device. A record that another device left under the start's own session name still refuses. The refusal names that device: stop it in that session, or start under another session name.
- A record whose session the daemon still holds is never touched, so a failed
record stopkeeps its retry. - If the record cannot be confirmed cleaned, the start still refuses with
cleanup-unconfirmed, and the refusal names the session.
The retry sits at record start, not in device-claim reconciliation: claim reconciliation settles only the claim's own session, and Android screen recording is the only capture kind with a device-side manifest that can misread during boot.
Commits: d9ef23d18 adds the start-time settle. b18cb9fed keeps it on the start device. 570661e62 finishes a record before cleaning it. c254f79c9 says in the help that the fallback recovery discards what the recording left. 2482c01a9 lets the settle and the refusal read one onStartDevice flag from the conflict list.
Validation
Tested SHA: 2482c01a9f10265c1b589a4845844a4fb48e7559. pnpm check:affected --run --head 2482c01a9 passed (format, lint, typecheck, layering, fallow, build, vitest-related, unit), exactCommit=true.
Tests in record-runtime-orphan-recovery.test.ts (8 cases):
- An orphaned record that can still finish is finished, not force-cleaned, and the new start succeeds.
- An orphaned record whose finish fails is force-cleaned, and the new start succeeds.
- Reattach reports
missing: the record endscompletedand the start succeeds. - An orphan of another session on another device stays open and does not block the start.
- An unheld record under the start's own session name on another device is not completed,
reattachis not called, and the refusal names that device. - A record whose cleanup stays pending still refuses with
cleanup-unconfirmed. - A held session's record is never touched, with its live recording and after its binding is gone (a failed
record stop); the refusal names the session.
Live runs (commands and record states are in the review thread):
- Android (
Medium_PhoneAPI 36 as A,Pixel_2API 27 as B): the stuck record from a reboot refuses a start on B under its own session name and stays open. A start under another session name on B succeeds. A start on A settles the record tocompleted/cleanedand records normally. - iOS 18.3 simulators: a start on the same simulator exports the orphaned recording before it starts. A start on another simulator under the same session name refuses, and
record stopin that session then exports the video.
Known limits: on Android the failed finish leaves an unplayable <out>.collected.mp4 next to the old output path, as a failed record stop does today. Not covered: a physical iOS device, and two concurrent record start requests on one device.
š¤ Generated with Claude Code