Repository navigation
fix(node-claude): keep long node runs alive and resume stalled sessions - #69
Merged
Merged
Conversation
A node-placed Claude run capped forwarded stdout at 200 KB. After the cap the Gateway saw no further progress, so a long session went blind and the stall classifier aborted it about 600 s later. The Gateway parses the stream incrementally and bounds its own buffers, so forward every chunk and drop the truncation and terminal-result re-injection machinery. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The CLI session binding was written only at settlement. A fresh turn that stalled-run recovery aborted left no binding, so the recovery continuation started a new Claude session with no history and answered that it had no request. Publish the binding through the session store owner when the stream reports the session id, under the turn's commit guard. Settlement still writes the full binding afterwards. Room-event and preserved-provenance turns stay excluded, matching settlement, and an early binding follows the established failure-clear policy. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Narrow the docs to aborted reply turns, since a managed live session interrupted after partial text still drops an unfinished fresh session. Mark the gateway truncation guard as old-node compatibility, and test that preserved-provenance turns never publish an early binding. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This was referenced Oct 14, 2026
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.
Problem
On 2026-10-13 Workboard node ticket UX-7 ran a
claude-cliturn placed on the Mac node. Claude made tool calls every few seconds for 10 minutes, but the Gateway saw no progress after about 20 s. The stall classifier marked the runstalled_agent_run(lastProgress=model_call:stream_progress), and stuck-session recovery aborted it at 633 s (the Mac process exited with 137). The stalled-turn continuation then ran as a fresh Claude session (useResume=false session=none historyPrompt=none) with no brief, and Claude replied that it had no request.There were two root causes:
invoke-agent-cli-claude.tsstopped forwarding stdout after 200 KB. Forwarded chunks are the Gateway's only progress and liveness signal for a node run, so any node run that streamed more than 200 KB went quiet to the Gateway and was aborted about 600 s later. The cap came from feat(nodes): continue Claude catalog sessions on paired nodes via streaming CLI agent runs openclaw/openclaw#105833 ("caps streamed output consistently with system.run"). That analogy doesn't hold:system.runreturns its whole output, but this stream is parsed incrementally.The Workboard side of the incident (the card staying
runningafter the aborted run) is fixed in a separate PR.Solution
Fix 1: forward every chunk (node host).
onStdoutRawforwards every decoded chunk. This removes the byte cap, the terminal-result re-injection, and the truncation bookkeeping, which only existed to work around the cap. The node now always reportstruncated: false. The Gateway already bounds its own buffers, as local runs do: the stdout capture head is capped atCLI_RUNNER_OUTPUT_PARSE_BYTES, and the stream-json parser enforces 8 MiB / 20,000 lines per turn. The Gateway's truncation guard stays as compatibility for older node hosts, and its comment now says so.Fix 2: publish a fresh session binding as soon as the CLI reports it. When the stream reports a fresh session id (
system/init), the reply path writes the binding through the session-store owner. A new store function,persistStartedCliSessionInStore, handles the write.sessionMode: none. The reply path also excludes room events and preserved-provenance turns.session_expiredclears it.buildCliSessionBindingis extracted from settlement so both writes use the same reuse facts.Docs:
docs/gateway/cli-backends.mdnow says that an aborted reply turn's fresh session is kept, and that a managed live session interrupted after partial text still drops it.Impact
Tradeoffs, deliberate and noted from review:
formaterror local runs already get. Before, the node never sent enough for the Gateway to reach that limit.session_expiredfailover follows the early write, the fresh binding stays. That matches what already happens to a binding the turn started with. A later same-provider fallback candidate resumes that session instead of starting fresh.agent_endis unchanged. The aborted run still reports a failedagent_end. The recovery run builds hook messages and its success flag the same way. It now resumes the session (useResume=true) instead of starting fresh.Evidence
Each regression test failed before its fix and passed after it. I checked red by restoring only the production file from the parent commit:
src/node-host/invoke-agent-cli-claude.test.ts, "forwards every stdout byte as progress past the former 200 KB cap". Red: the progress stream stopped at 200 KB. Green: the full 300 KB stream arrives, including the split multibyte character, the latetool_useline and the result line, withtruncated: false.src/auto-reply/reply/agent-runner-execution-cli-admission.test.ts, "keeps an aborted %s turn's fresh session only when it may establish continuity". This test runs the real reply candidate against a real SQLite session store. Red (ordinary):expected undefined to deeply equal {…}. Green: an ordinary aborted fresh turn keeps the binding, and room-event and preserved-provenance turns publish none.src/agents/cli-runner/execute.supervisor-capture.test.ts, "publishes a fresh session as soon as the CLI reports it, even if the turn then fails". Red: the callback was called 0 times. Green: it is called once with the streamed session id, before the failure settles.Wall time with
pnpm test <file> --maxWorkers=1(warm, this host):src/node-host/invoke-agent-cli-claude.test.ts: 33 s wall, 10.7 s Vitest. The new case takes about 50 ms.src/auto-reply/reply/agent-runner-execution-cli-admission.test.ts: 32 s wall, 30.5 s Vitest. The three new cases take about 0.5 s each.src/agents/cli-runner/execute.supervisor-capture.test.ts: 39 s wall, 37 s Vitest. The new case takes about 30 ms.The new tests add about 2 CI seconds in total and use no real timers or sleeps.
Suites:
src/node-host,src/agents/cli-runner/,src/agents/cli-session*,cli-runner.reliability,cli-runner.spawn, the admission suite andcommand/attempt-execution.cliall pass.cli-runner.spawn.test.tsfailed to load once while tsgo shards were running in parallel. It passed alone (37/37).Typecheck:
pnpm tsgo:coreis clean. The test shardsagents-root,agents-other,agents-tools,messaging,other,gateway-*andinfraare clean. One pre-existing unrelated error appears instate-logging:src/audit/message-delivery-progress-store.test.tscannot find.github/actions/git-owner/test-prerequisites.json.Lint and format:
scripts/run-oxlint.mjson the touched files,oxfmt,pnpm format:docs:checkandgit diff --checkare clean.Not verified: a live node run against the Mac. This PR is not deployed.
🤖 Generated with Claude Code