Repository navigation
Detect a kept-alive claude CLI that stops reading stdin (#178) - #212
Merged
currentbits merged 2 commits intoAug 17, 2026
Merged
Conversation
… Corrupt store load silently discards all user data, with no
A reused interactive claude child that stops reading stdin without ever
exiting hung the turn on "Agent working…" forever: the stdin write lands
in the pipe buffer, nothing comes back, and the respawn recovery only
fires on process exit.
Probing the real CLI 2.1.219 shows a reused warm child acknowledges a
stdin turn in milliseconds — command_lifecycle{queued} at 0ms and
system/init at ~31-46ms after the write, before any model work. That is
first-LINE latency, unrelated to the first-TOKEN latency (48s on a 21MB
resumed session) that made every earlier wall-clock watchdog unsafe.
So: on the reuse path only, a 60s no-event timer disposes the wedged
child. Killing it produces the exit that the existing onExit respawn
already handles, which re-runs the turn with --resume. No new respawn
logic, no CLI flag, and nothing armed on a cold spawn.
Co-Authored-By: Claude Opus 5 <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
currentbits
deleted the
coder/a-kept-alive-claude-cli-that-stops-readi-e95202
branch
October 3, 2026 16:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #178.
The bug
electron/runner.jskeeps an interactiveclaudechild alive across turns and delivers the next turn by writing an NDJSON user line on its stdin instead of spawning. If that child stops reading stdin but never exits, the write still succeeds into the pipe buffer, nothing ever comes back, and the turn sits on "Agent working…" forever. The existing recovery (onExit→spawnForTurn()) only fires when the child actually exits, so this variant had no detection at all.This was the standing remainder in
docs/ISSUES.md— left open because wall-clock watchdogs had already been rejected: a legitimately slow turn's first token took 48s on a 21MB resumed session (issue #17), so no timeout could be short enough to catch a dead CLI and long enough to survive a slow one.Why a timer is safe here
I probed the real claude CLI 2.1.219 (logs quoted in #178). On a reused kept-alive child, turn two produces:
command_lifecycle {"state":"queued"}at +0ms after the stdin writesystem/initat +31ms (+46ms in a second run)thinking_tokensonly ~800ms laterThat is first-line latency, not first-token latency, and it is unrelated to how slow the model is. The old objection does not apply to it.
The change
electron/runner.js: on the reuse path only, arm a 60s "no event of any kind" timer (CLAUDE_ACK_MS, overridable viaCODER_CLAUDE_ACK_MS). On expiry, if the run is still current and nothing has arrived, call the existingdisposeClaudeSession().onExitrespawn branch already handles, which re-runs the turn with--resume. No new respawn logic was added — the timer's only job is to convert "wedged but alive" into "exited".clearRun,onExit,onError), and isunref()'d so it never holds the process open.Deliberately not done: no timer on cold spawns (a fresh
--resumeof a huge session has no proven sub-second ACK); no CLI flag —--replay-user-messagesdoes work but its echo arrives late, after thinking, and would feed our own prompt text back through the<task-notification>scan atrunner.js:1642.Known ceiling, recorded in the code and in
docs/ISSUES.md: any line counts as the ACK, so a stray background task-notification from an earlier turn could satisfy it and mask a hang. That fails safe (miss a hang, never kill a healthy turn); the upgrade path is correlating thecommand_lifecyclecommand_uuid.Verification
New test
respawns when the reused CLI stops reading stdin without exiting, with a fake-CLI scenariodeaf-reusethat completes turn one and then stays alive forever without reading stdin.Proven red before green: with the
runner.jshunk reverted the new test fails withwaitFor timed out(25/26), and passes with it (26/26).Full suite: core 38/38, renderer 716/716, memory 122/122. Electron is 803/804 — the one failure,
wireClient × webBridge over a real socket, reproduces identically on a clean tree atmainand is unrelated to this change.PR created by the Claude Code agent