refactor: settle remaining single-deadline races through settleWithin

Merged
TH
7d ago
+41-80

Summary

Finishes the settleWithin migration that #4766 started in the daemon. Stacked on #4766; retarget to main once it merges.

Seven more sites raced work against a hand-rolled timer and now settle through settleWithin (@agent-device/host-kit/retry). Three of them left a timer armed for the full budget after the work had settled: the screen-recording stop wait (settlesWithin), the snapshot bridge exit wait (waitForProcess), and the CLI exit flush (sleep(FLUSH_TIMEOUT_MS)).

  • 8 files. No public API, wire, or docs change.
  • Promise.race( count (R88): 41 → 34.
  • Not migrated on purpose: races with an abort signal or a poll tick as a racer, sites on an injected clock, and provider-limrun (no host-kit dependency).
  • Tried and reverted: capture-fact-grace.ts and perf-xctrace.ts. Importing host-kit/retry there grows a startup closure and the eager-closure budget refuses it.

Validation

Tested head: 3581b99b94 (base 844e719685). Device run and vitest related were at 584e2acde3; the later commit changes only process-exit.test.ts, which fails when the drain wait is removed.

  • pnpm typecheck: pass.
  • vitest related on the 7 files: 1,230 files, 12,213 tests pass (the eager-closure budget passes after the two reverts).
  • scripts/layering/check.ts: OK, R88 34 remaining.
  • Device, branch CLI 0.21.42-dev, iPhone 17e simulator (iOS 27.0), isolated state dir: open com.apple.Preferences, record start --scope device --hide-touches, record stop (MP4 exported, 41 kB), snapshot -i, close, daemon stop (graceful). All succeeded.
  • CI owns the full gate for this head.

Risk: the abort-rollback path in the simulator recording host has unit coverage only.

šŸ¤– Generated with Claude Code


Autofix with [code]smith
Open in [code]smith Ā· Need help on this PR? Tag @codesmith-bot with what you need.