Skip to content

fix(daemon-client): say that a hung daemon is stopped before ensureDaemon starts a new one - #4803

Merged
thymikee merged 2 commits into
mainfrom
t3/ensure-replaces-unresponsive-daemon
Nov 20, 2026
Merged

thymikee merged 2 commits into
mainfrom
t3/ensure-replaces-unresponsive-daemon

Conversation

@thymikee

@thymikee thymikee commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Problem

When an attach client's request times out and the daemon answers no liveness probe, the hint said: "Stop it with <stop command>, then retry. SDK clients call ensureDaemon() to start a fresh one." Two comments said "ensureDaemon is where an unresponsive one is replaced".

Both read as if ensureDaemon() replaces a same-version daemon that answers nothing. It does not: a compatible daemon that accepts a connection is reused without a question. An SDK client that follows the hint without the stop receives the same daemon again.

Change

The hint states the order: stop the daemon, then retry, and an SDK client calls ensureDaemon() after the stop. The two comments say what ensureDaemon does with a compatible daemon. No behavior changes.

Why not replace the daemon in ensureDaemon()

An earlier version of this PR made ensureDaemon() force-retire a compatible daemon that failed three 1 s liveness probes. That was withdrawn (maintainer decision): every other use of the probe follows a request that already timed out, and this path had no such evidence. About 3.4 s of silence on an overloaded shared host is not proof of a hang, and the retirement ends every other client's sessions.

Evidence

  • packages/daemon-client/src/__tests__/daemon-client-timeout-route.test.ts (10 tests) passes; "an attach client leaves a daemon that answers no probe running" pins the hint.
  • Lint and typecheck pass locally.

Size

Production: +5 −4, net +1 line (comment text). No startup cost change.

Part of #4649.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.46 MB 6.46 MB +56 B
Package (unpacked) 6.45 MB 6.45 MB +56 B
Package (download) 1.97 MB 1.97 MB +26 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 20.9 ms 22.9 ms +2.0 ms
CLI --help 45.7 ms 45.9 ms +0.3 ms

@thymikee
thymikee force-pushed the t3/ensure-replaces-unresponsive-daemon branch from f4b4bd5 to 58aa019 Compare November 20, 2026 11:37
@thymikee
thymikee marked this pull request as draft November 20, 2026 11:38
@thymikee

Copy link
Copy Markdown
Member Author

Coordinator review: held as a draft for a maintainer decision.

The code does what the brief asked, and the brief is mine. On review I think the brief under-weighted one risk.

Every existing use of the liveness probe follows a request that already timed out, so the daemon has been silent for a long window before three probes are allowed to end it. This path has no such earlier evidence. Any ensureDaemon() call force-retires a compatible daemon that fails three 1 s probes, about 3.4 s in total. On an overloaded shared host a healthy daemon can go unscheduled for longer than that (the startup path allows 60 s of silence for this reason), and the retirement ends every other client's sessions. daemon-client-liveness-probe.ts states the cost: a wrong "unresponsive" verdict kills a live shared daemon.

The defect is real: the timeout hint tells SDK clients to call ensureDaemon(), and for a hung same-version daemon that returns the same daemon. No hung daemon of this kind has been reported from the field.

Options:

  1. Reduce this PR to a correct hint and comments (name daemon stop for this case), with no new retirement path.
  2. Keep the retirement, but require a longer silent window on this path before it.
  3. Merge as is.

Also to fix in any option: the commands.md sentence says a CLI command replaces such a daemon when it ensures one. The CLI route does not call ensureDaemon(); it retires an unresponsive daemon only after a request timeout.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 58aa019. The verdict and the full list are in the summary comment.

…emon starts a new one

The timeout hint and two comments read as if ensureDaemon() replaced a
compatible daemon that answers nothing. It reuses that daemon. The hint now
states the order: stop, then ensure.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@thymikee
thymikee force-pushed the t3/ensure-replaces-unresponsive-daemon branch from 58aa019 to 483a8d6 Compare November 20, 2026 11:52
@thymikee thymikee changed the title fix(daemon-client): ensureDaemon replaces a compatible daemon that answers nothing fix(daemon-client): say that a hung daemon is stopped before ensureDaemon starts a new one Nov 20, 2026
@thymikee
thymikee marked this pull request as ready for review November 20, 2026 11:52
@thymikee

Copy link
Copy Markdown
Member Author

This PR is ready at 483a8d6. It changes only the timeout hint and two comments in daemon-client: the hint now gives the order (stop the daemon, then retry, and an SDK client calls ensureDaemon() after the stop), and the comments say that ensureDaemon reuses a compatible daemon without asking it anything. That matches the code, so a caller no longer reads the hint as "ensureDaemon replaces a hung daemon". Checks are still running.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 20, 2026
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 483a8d6. The verdict and the full list are in the summary comment.

…nections

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 38fb136

Since the review of 483a8d6: 0 new · 0 still open · 1 no longer raised (1 marked fixed)

No open findings.

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (7de4587536f8).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee
thymikee merged commit 7d9d8aa into main Nov 20, 2026
22 of 23 checks passed
@thymikee
thymikee deleted the t3/ensure-replaces-unresponsive-daemon branch November 20, 2026 12:29
thymikee added a commit that referenced this pull request Nov 20, 2026
* origin/main:
  feat(gesture): hold before the move with gesture pan --hold-ms (#4767)
  docs: clarify device verification and security proposals (#4805)
  fix(daemon-client): say that a hung daemon is stopped before ensureDaemon starts a new one (#4803)
  test: remove five timing races from CI (#4800)
  refactor(remote): save a remote script from memory with the local publisher (#4802)
  refactor(apple-runner): one RUNNER_ERROR_CODES row per runner error code with parity/docs gates (#4774)
  fix(android): require acknowledgements for test IME typing (#4722)
  feat(scroll): add scroll refresh for pull-to-refresh (#4770)
  refactor(host-kit): add request Scope and use it for the wait capture deadline (#4794)
  fix(android): let permission all change nothing on an app that declares no permissions (#4796)
  fix(cli): replace the CLI session and generated remote config instead of rewriting them in place (#4797)
  fix(host-kit): accept a group-writable script directory the user owns (#4799)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant