Skip to content

fix: keep Claude CLI alive across turns so background tasks survive settle (#8) - #9

Merged
currentbits merged 3 commits into
mainfrom
coder/thread-runner-kills-agent-child-processe-7efec7
Aug 14, 2026
Merged

currentbits merged 3 commits into
mainfrom
coder/thread-runner-kills-agent-child-processe-7efec7

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Fixes #8.

Problem

Two failure modes for long-running agent work in a thread, both traced to one defect:

  1. Background tasks were SIGTERMed the moment a turn settled. The runner ended the Claude CLI's stdin on every result event ("one-turn-per-process"), the CLI exited, and Claude Code kills its tracked background tasks on exit — a ~15-min npm ci/packaging build died at every turn boundary.
  2. Permission requests failed with AbortError: Stream closed while settling. That same stdin is the permission control channel: closing it aborted in-flight can_use_tool requests, 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: new keepAlive option skips the stdin close on result; new send() delivers a follow-up user turn on stdin (resetting per-turn result tracking).
  • electron/runner.js: per-thread claudeSessions map 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 still nohup).
  • Retryable permission errors: a control_request arriving 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:delete disposes 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 --test on claude/runner/services files: 67/67 pass. Full npm 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 --noEmit clean.

  • PR created by the Claude Code agent

Willem and others added 3 commits August 14, 2026 11:33
… 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]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit 9fd049f into main Aug 14, 2026
@currentbits
currentbits deleted the coder/thread-runner-kills-agent-child-processe-7efec7 branch October 3, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thread runner kills agent child processes on turn settle; permission requests fail while settling

1 participant