feat: add stale device claim release and dead-end recovery guidance

Merged
TH
3mo ago
+881-26

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 --stale settles a provably dead owner's durable resources through the same exact-owner reconciliation open and 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 canonical createDeviceClaimReconciler/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 reports changed instead of racing.
  • Dead-end removal in the error contract: a DEVICE_IN_USE conflict whose recorded owner provably cannot release (dead, or superseded daemon) now carries the exact device release --stale command as its recovery, instead of a status inspection that led nowhere. Live/uncertain owners keep inspection-only recovery.
  • device status --stale now appends the matching release command when provably dead owners are listed.
  • daemon stop now 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) —

  1. device status --stale listed it and offered the exact release command;
  2. device release without --stale refused with INVALID_ARGS and the live-owner guidance;
  3. device release --stale reported released ios Dead Validation iPhone session=dead-validate … and the claim file was gone.

Part of #1320.