feat: add stale device claim release and dead-end recovery guidance
Merged
TH
3mo ago+881+881+012345678901234567890123456789-26-26-01234567890123456789
Summary
Stacked on #2160. Closes the #1320 recovery loop for claims no daemon can settle on its own — the corrected scope's device release closure criterion (stale-only; no --force, per the 2026-07-24 scope decision).
agent-device device release --stalesettles a provably dead owner's durable resources through the same exact-owner reconciliationopenand daemon startup use, then clears the claim last — daemonlessly. The CLI composes a local-only platform gateway (provider runtimes stay out entirely; claims exist only for local devices) plus the canonicalcreateDeviceClaimReconciler/createDaemonRecoveryPlatformScope. Live, uncertain, PID-reused, and corrupt claims always fail closed and are reported per claim with the reason and a next step; releasing runs under the per-device claim lock with an ownerToken re-check, so a concurrent owner transition reportschangedinstead of racing.- Dead-end removal in the error contract: a
DEVICE_IN_USEconflict whose recorded owner provably cannot release (dead, or superseded daemon) now carries the exactdevice release --stalecommand as its recovery, instead of a status inspection that led nowhere. Live/uncertain owners keep inspection-only recovery. device status --stalenow appends the matching release command when provably dead owners are listed.daemon stopnow warns in text output when a claim was orphaned (previously visible only via--json) and names the status/release commands.
Validation
pnpm check:affected --run: every check green except one provider-scenario test timeout (ios-lifecycle.test.ts, 5s budget) that reproduces identically on origin/main under the same load — a parallel agent session was running a full suite on this host (load avg ~29); this is the documented host-contention signature, not a regression.
Real-binary validation (pnpm build + isolated AGENT_DEVICE_CLAIMS_DIR): planted a dead-owner claim (hashed path, dead PID, existing state dir) —
device status --stalelisted it and offered the exact release command;device releasewithout--stalerefused withINVALID_ARGSand the live-owner guidance;device release --stalereportedreleased ios Dead Validation iPhone session=dead-validate …and the claim file was gone.
Part of #1320.