Repository navigation
fix: keep Claude CLI alive across turns so background tasks survive settle (#8) - #9
Merged
currentbits merged 3 commits intoAug 14, 2026
Conversation
… When we click a dropdown next to the treads the context wind
… Let's implement an auto updater i want 2 channels prod and n
…ettle Fixes #8. The runner ended the CLI's stdin on every result event (one-turn-per-process), so the CLI exited at turn settle and killed its tracked background tasks (npm ci SIGTERMed mid-build), and any can_use_tool control_request in flight aborted with "Stream closed". The CLI already runs with --input-format stream-json, which supports multiple user turns per process. Now: - claude.js: keepAlive option skips the stdin close on result; send() delivers a follow-up user turn on stdin (resetting per-turn result tracking). - runner.js: per-thread claudeSessions map keeps the interactive CLI process across turns and reuses it when spawn params (cwd, model, permission mode, effort, mcp, remote, binary) are unchanged; otherwise the old process is killed and a fresh one spawns with --resume. Sessions die on stop, param change, thread delete, process exit, app quit, or a 30-min idle reap (unref'd timer). - control_requests arriving with no active turn are answered with a retryable error response instead of being dropped, so the agent can distinguish "settling, retry" from a user deny. - ipc.js: threads:delete disposes the thread's kept-alive session. Co-Authored-By: Claude Fable 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/thread-runner-kills-agent-child-processe-7efec7
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.
Fixes #8.
Problem
Two failure modes for long-running agent work in a thread, both traced to one defect:
resultevent ("one-turn-per-process"), the CLI exited, and Claude Code kills its tracked background tasks on exit — a ~15-minnpm ci/packaging build died at every turn boundary.AbortError: Stream closedwhile settling. That same stdin is the permission control channel: closing it aborted in-flightcan_use_toolrequests, and once the run slot was cleared, later control_requests were silently dropped.The CLI already runs with
--input-format stream-json, which supports multiple user turns per process — the per-turn teardown was purely Solenta's choice.Change
electron/claude.js: newkeepAliveoption skips the stdin close onresult; newsend()delivers a follow-up user turn on stdin (resetting per-turn result tracking).electron/runner.js: per-threadclaudeSessionsmap keeps the interactive CLI process across turns and reuses it when spawn parameters (cwd, model, permission mode, effort, MCP config, remote host, binary) are unchanged; otherwise the old process is killed and a fresh one spawns with--resume. Sessions die on user stop, param change, thread delete, process exit, app quit, or a 30-minute idle reap (unref'd timer; longer detached work should stillnohup).control_requestarriving with no active turn is answered with an error response — "No active turn in Solenta (run settling); retry on the next turn" — distinguishable from a user deny, instead of being dropped or transport-aborted.electron/ipc.js:threads:deletedisposes the thread's kept-alive session.Non-interactive claude-stream providers (e.g. grok) keep the old per-turn lifecycle.
Testing
Two new fake-CLI scenarios in
electron/test/claude.test.js, written failing-first:multi-turn: asserts the CLI process survives turn settle (same PID, no SIGTERM) and handles turn two over stdin with no second spawn.late-permission: asserts a control_request raised after settle gets a retryable error response.node --teston claude/runner/services files: 67/67 pass. Fullnpm run test:electron: 669 pass / 9 fail — the same 9 fail on the base branch (pre-existing parallel-run flakiness in orchServer/store; they pass in isolation both before and after).tsc --noEmitclean.PR created by the Claude Code agent