Repository navigation
fix(anthropic): Claude CLI conversations hang silently after the process owner is lost - #195082
Conversation
A fresh turn's restart joined the previous owner's process exit with no abort race. When that exit never settled, aborting the run did not release it, so every later turn of the conversation stalled. Race the joins with the run signal; the unexited process still blocks registration.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesMakes Claude CLI cleanup fail promptly when its process owner disappears without emitting an exit event. Example: The owner of a warm Claude CLI process disappears before the third conversation turn.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review This PR provides a useful, focused mitigation. The previous retry-guidance finding is fixed, and no introduced correctness or security defects were found; exact-head CI remains incomplete. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Anthropic plugin translates Gateway turns into Claude Code stream-json requests; its transport joins process completion and descendant cleanup before the host releases the conversation's process slot. flowchart LR
A[Gateway turn] --> B[Live session registry]
B --> C[Anthropic CLI runtime]
C --> D[CLI transport]
D --> E[Owned process lifecycle]
E --> F[Claude Code process]
E --> G[Cleanup outcome]
G --> B
Technical reviewBest possible solution: Land the focused transport repair once exact-head CI passes, retaining the broader recovery investigation separately. Do we have a high-confidence way to reproduce the issue? Source establishes the missing-exit cleanup hang, and the contributor supplied an older-head Gateway reproduction; the original reporter sequence and the same injection on current main are not independently reproduced. Is this the best way to solve the issue? The patch repairs settlement at the existing transport owner, preserves completion and extinction joins, and avoids an unrelated abort race or new timeout machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 72f90dde293d. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +14, Tests +38, Other +4. Total +56 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed November 13, 2026, 9:59 PM ET / November 14, 2026, 02:59 UTC (Revision 4). |
… lost waitForExit awaited only the exit event. A lost process owner reports an error and never an exit event, so the wait stayed pending and every later turn of that conversation stalled silently with no process left. Join the owner's own wait and extinction outcome, and reject with an actionable error when closure cannot be confirmed. Related: openclaw#195030 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The abort race only bounded a wait that the real hang does not depend on: the exit wait stalls because a lost process owner never reports an exit event, so the next commit fixes the wait itself. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@clawsweeper re-review Updated: root cause moved to the Claude CLI transport (exit wait never settled after the process owner was lost), the earlier registry change is reverted, real isolated-Gateway before/after proof is in the PR body, and the new regression lines have their own test-lines allocation. |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…ess owner is lost (openclaw#195082) * fix(agents): release aborted CLI live-session restarts A fresh turn's restart joined the previous owner's process exit with no abort race. When that exit never settled, aborting the run did not release it, so every later turn of the conversation stalled. Race the joins with the run signal; the unexited process still blocks registration. * fix(anthropic): settle Claude CLI exit wait when the process owner is lost waitForExit awaited only the exit event. A lost process owner reports an error and never an exit event, so the wait stayed pending and every later turn of that conversation stalled silently with no process left. Join the owner's own wait and extinction outcome, and reject with an actionable error when closure cannot be confirmed. Related: openclaw#195030 * Revert "fix(agents): release aborted CLI live-session restarts" The abort race only bounded a wait that the real hang does not depend on: the exit wait stalls because a lost process owner never reports an exit event, so the next commit fixes the wait itself. * test: allocate regression lines for Claude CLI owner-loss exit wait * fix(anthropic): suggest retry after CLI cleanup rejection --------- Co-authored-by: machine3at <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
Related: #195030
What Problem This Solves
Fixes: a Claude CLI conversation stalls silently, with no Claude process left, when the process owner that launched the warm Claude process is lost.
User Impact
User impact: when the owner of a warm Claude process dies, the affected message now fails promptly with "Claude CLI process cleanup could not be confirmed; retry the message. If it fails again, restart the Gateway." Before, the message waited until its timeout without useful output.
This is a partial mitigation. The failed turn still reports unconfirmed cleanup. Current main removes a rejected retired cleanup entry after it settles (#198224), so a later message can retry with a fresh process. Recovery of the reporter's original sequence is not proven; #195030 remains open.
Why This Change Was Made
waitForExit()inextensions/anthropic/cli-transport.tsawaited only the child's exit event. A lost process owner reports an error (service child cleanup identity lost), never an exit event, and itswait()andwaitForExtinction()both reject. The wait stayed pending forever. The live-session registry joins that wait before it lets a fresh turn start (remove()thenrestartCliLiveSession()), so each later turn sat behind it. That matches the issue: noclaudeprocess present, nocli live session start,released=0.waitForExit()now also settles on the owner's own wait and extinction result. A rejection becomes an actionable error. A normal exit still waits for both, as before.The abort-aware restart from the earlier commit (
1f79ff4de98) is reverted. It bounded a wait the real hang does not depend on, and the transport already guarantees SIGTERM/SIGKILL escalation for a live process. Its test came out with it.Provenance for the changed behavior:
waitForExitwaiting onchild.wait()andchild.waitForExtinction()came from fix: stop Claude CLI sessions when the Gateway is killed #171016 (321f4d3ded5, stop Claude CLI sessions when the Gateway is killed). This change keeps both waits and stops the wait from depending on an event a lost owner never sends. The later registry repair in fix(cli): Claude CLI conversation keeps failing after one live-session cleanup failure #198224 clears a settled cleanup rejection so a later turn can retry.exitedpromise and the exit-error handling come from refactor(anthropic): replace Agent SDK with direct CLI transport #138707 (58d8871d18c, direct CLI transport) and fix(anthropic): preserve process exit errors after stdin closes #165769 (89792e5aeb9). They are unchanged;exitedis still awaited on the normal path.1f79ff4de98returnsrestartCliLiveSessionto its state at base90dfe90f3c8.Evidence
Real Gateway built from this branch, isolated state (temporary
HOME,OPENCLAW_STATE_DIR, own port),claude-cliruntime, and a small stand-inclaudeexecutable onPATHthat speaks the stream-json protocol. Turns were driven withopenclaw agent. The fault: after two normal turns,SIGKILLthe process-owner helper that launched the warm Claude process.Before (PR head
1f79ff4de98): the next turns stall until their timeout, and the lane is reported stalled after 360 s.After (historical head
9ee02bd15fada32dae71c82f2ce9bc5d511a6440, before the #198224 base update): the affected turns failed promptly with the error then in the branch. This trace was not rerun after the retry-first wording and registry update.The full harness (stand-in
claudeand run script) is in the details below. No screen recording was made; no recorder is installed on the test host.Proof harness
fake-claude-wrapper.js:run-proof.sh:Regression test (red on the base transport, green here; re-verified independently):
cli-transport.close.test.ts"rejects waitForExit when the process owner is lost and never reports an exit". On the base transport it times out; with the fix it passes. Adjacent suites pass:execute-plugin.test.tsandcli-live-session-registry.test.ts(81),cli-runtime.test.ts(70),cli-transport.close.test.ts(2). Test-line budget: the 38 new regression lines are allocated inconfig/test-lines-allocations/claude-cli-owner-loss-exit-wait.txt(the earlier registry test and its 37 lines were removed with the revert);pnpm check:test-lines-ratchetpasses and the shared scalar is unchanged.pnpm -s tsgo:core,run-tsgo.mjs -p test/tsconfig/tsconfig.extensions.test.json, oxlint andoxfmt --checkare clean.Not covered:
confirmExtinction()(the node-host worker lifecycle already does) to prove the process group gone after loss. On Linux with the native owner it always reports unconfirmed, so it would not help the reporter's host.Maintainer correction and open follow-up
At
bdfb5a3cd7ca3566d577876b26477eb27fbc7ca4, the cleanup error now tells the operator to retry the message first, with Gateway restart guidance only for repeated failure. The transport close test and live-session registry test passed locally (2 and 43 tests respectively); the exact-head hosted gates are pending.Full recovery of the original reporter sequence remains unproven. Keep #195030 open for that separate investigation.