fix(daemon): take a foreign device claim the device's own reboot invalidated - #2570
fix(daemon): take a foreign device claim the device's own reboot invalidated#2570thymikee wants to merge 2 commits into
Conversation
Size Report
Startup median (7 runs, lower is better):
|
|
|
Two ownership cases still need fixing at f0ae9d7. In device-claim-reboot.ts:35, the original claim timestamp remains the only cutoff even after its owner successfully reopens the app after reboot. The existing-session open path preserves that claim, so a later foreign open can reclaim a device that the original session is actively using and clean up its resources. Renew or validate ownership against the current boot when the owner resumes, and cover owner reopen followed by foreign open. In packages/platform-android/src/device-boot.ts:18, subtracting sampled uptime from the time the ADB response arrives moves the inferred boot forward by response latency. Shortly after boot, this can make a valid newer claim look stale without another reboot. Use a conservative bound from before the probe and cover a delayed response. The diff is also 1,442 gross lines, above the repository’s 1,000-line PR limit; split the behavior-preserving extraction from the takeover change. The current smoke failure is the automation-longpress scroll assertion seen on #2565 before its successful retry, so it appears unrelated to these changes. |
21db6ff to
0dd2527
Compare
|
Both ownership cases are fixed at The bound is now the instant the owner last vouched for the device, not the first write. Android now samples the host clock before the adb round trip, so The diff is split as stack #2576: #2574 is the behavior-preserving claim-settlement move (772 gross), #2575 is the boot-observation contract, probes, and hub (489 gross), and this PR is the takeover alone at 957 gross lines. |
|
The Android timing fix and PR split resolve those two points, but the owner-reopen bug remains at 0dd2527. renewHeldClaim only runs through acquireDeviceClaim; the existing-session open path in session-open.ts:162–243 still calls completeOpenCommand directly and never renews the claim. The new regression calls acquireDeviceClaim twice, so it does not exercise the reported production path. Wire renewal into a successful existing-session reopen and cover that routed flow followed by a foreign open, with live confirmation. Checks are green; this remains a code blocker. |
|
Renewal now rides the production reopen at
Routed coverage: Live on a fresh iPhone 17 Pro simulator, two state dirs and one device, Safari as the app:
Sessions closed, daemons stopped, state dirs removed, simulator deleted, |
|
The sequential owner-reopen case is now fixed and has the requested live evidence. One ownership race remains at session-open-execution.ts:245: openApplication runs before renewal, so a foreign daemon can take the still-preboot claim while the owner is reopening. renewDeviceClaim then returns ownership-changed or absent, but the result is ignored and the old owner still reports success. The request execution locks are local to each daemon, so they do not serialize this case. Establish ownership across reopen and renewal, handle lost ownership, and cover a foreign takeover interleaved with owner reopen. The layer is also back over the 1,000-line budget: 848 additions plus 211 deletions, or 1,059 gross lines. Reduce it by at least 59 lines or move the behavior-preserving extraction into the lower layer. CI is green at 2f8cbfe; these remain the blockers. |
2f8cbfe to
512736c
Compare
|
Ownership now spans the reopen at Renewal moved ahead of all device work: Coverage: Live, two state dirs on one simulator: owner |
Summary
opennow settles a foreign device claim that the device's own reboot invalidated. Claims outlive the device they describe: shutting a Simulator or emulator down takes its app process, runner, and accessibility connection with it, while the claiming daemon and claim file stay healthy. Every lateropenrefused withDEVICE_IN_USE, naming an owner with nothing left to close.openasks the device when its current boot began, releases a claim predating that through the same exact-owner reconciliationdevice release --staleuses, and reports the release inwarnings. The bound is the lastopenits owner made, renewed before a reopen touches the device, so a session cannot lose a device it is coming back to. The probe runs only for a conflicting foreign claim, after owner-liveness has answered.Part 3 of 3 for #2538, on #2575 and #2574. 847 gross lines.
Closes #2538
Validation
Tested at
512736caf4.pnpm check:affected --runpasses format, lint, typecheck, layering, fallow, build, provider and node integration, wire-compat, command docs, and related vitest (1,985 tests).mutation-modelfails identically at baseab3d11e069locally, where CI is green.Live, two state dirs on one simulator: a pre-reboot foreign
openreturnedDEVICE_IN_USE; aftersimctl shutdownandbootthe owner's ownopensucceeded, so the next foreignopenstill returnedDEVICE_IN_USE; rebooting again without an owner reopen let a foreignopentake the device and say so, and an owner reopen whose claim that foreign session had taken was refused, naming it. Experiment device and sessions cleaned.