fix(device): recover cached agent daemons after exit#23441

merged2
main
GitHub fork: fix/device-daemon-recovery
openedOct 22, 2026byYyashranaway
View on GitHubTwo-way sync enabledPR last imported 22d ago

After the local device agent daemon exits, opening a device keeps returning its cached dead endpoint. Run the existing health check and startup path for cached daemons too, then save the refreshed endpoint. Healthy daemons are reused without reinstalling tools.

The regression first reuses a healthy daemon, then makes its health check fail and verifies a new endpoint is returned. It fails before the fix. All 18 host tests, targeted lint, and the server typecheck pass. No simulator was launched.

Checks

1 cancelled · 23 successful · 16 skipped
Some checks were not successful

Cancelled1

03b913b

Added 1 commit

  • fix(device): recover cached agent daemons after exit0c0b36e
Synced from GitHub

Warning

Review limit reached

Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.

Next included review available in 40 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 3b95e7831b11b17627dff16843bc087bfca397ec and 0c0b36ef22326b414ec1a2fc5829c2c39ea4f55a.

📒 Files selected for processing: 2
  • apps/server/src/device/LocalDeviceHost.test.ts
  • apps/server/src/device/LocalDeviceHost.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Synced from GitHub

Approvability

Verdict: Approved at 03b913b

Macroscope's review found this PR approvable — Cached local device-agent daemons are now health-checked and restarted when needed instead of returning a dead endpoint. Recovery reuses the existing bounded startup path and preserves current access settings and product defaults.

You can add or adjust custom eligibility rules. Learn more.

Note

Written by gpt-6.1-sol on behalf of Maria

Verified in a real dev environment

verified as-is at 0c0b36ef22326b414ec1a2fc5829c2c39ea4f55a, using the real web client in Playwright with /usr/bin/google-chrome and real Codex gpt-6.1-sol turns through the local proxy. projects, threads, and turns were created through the app, with no mocks or demo data. only one dev server ran at a time, with isolated state.

  • reproduced on github/main (32ecd71726): stop the daemon, then call device_open again. it reports success, but its returned command fails with ECONNREFUSED at the cached port 39073.
  • on this head, the same flow starts a new daemon and the returned agent-device devices --json exits 0, listing the real Android 11 emulator recovery-verify.
  • also passed after SIGKILL, with stale daemon.json retained: the daemon moved from port 46095 to 37439, and the real provider command exited 0 again. no t3 restart or settings toggle was needed.
  • nearby behavior passed: healthy daemon reuse kept its pid/port; device close without shutdown and reopen succeeded; launching com.android.settings exited 0.
  • all 18 LocalDeviceHost.test.ts tests passed on Blacksmith. existing CI has no failing or pending checks. no code changes or pushes were needed.

short transcript:

text
1main: daemon stop -> device_open -> returned devices --json: exit 1, ECONNREFUSED
2pr: daemon stop -> device_open -> returned devices --json: exit 0, success=true
3pr: SIGKILL + stale daemon.json -> device_open -> returned devices --json: exit 0
4pr: healthy daemon pid/port unchanged across close/reopen

command transcript

Not verified

native T3 iOS/Android clients, Electron, macOS/iOS Simulator, Windows, SSH hosts, and cloud devices were not exercised on this Linux VM.

full interaction with Android settings controls remains unverified: this emulator displayed an application-not-responding warning for com.android.systemui. the snapshot command succeeded and exposed the warning controls, but pressing Wait was blocked by that system dialog. the Device panel also intermittently reported no video. these limitations did not prevent device discovery, close/reopen, either daemon recovery, or successful commands through the refreshed endpoint. the warning is visible in the evidence.

cleanup finding: device_close(shutdown: true) reported Device shutdown failed: Could not communicate with device support. Try refreshing devices. the emulator process subsequently exited and its console ports closed. shutdown completion reporting is not verified; this was not changed in this pass.

Added 1 commit