Skip to content

fix(anthropic): Claude CLI conversations hang silently after the process owner is lost - #195082

Merged
vincentkoc merged 6 commits into
openclaw:mainfrom
machine3at:fix/claude-cli-live-session-wedge
Nov 14, 2026
Merged

vincentkoc merged 6 commits into
openclaw:mainfrom
machine3at:fix/claude-cli-live-session-wedge

Conversation

@machine3at

@machine3at machine3at commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

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() in extensions/anthropic/cli-transport.ts awaited only the child's exit event. A lost process owner reports an error (service child cleanup identity lost), never an exit event, and its wait() and waitForExtinction() both reject. The wait stayed pending forever. The live-session registry joins that wait before it lets a fresh turn start (remove() then restartCliLiveSession()), so each later turn sat behind it. That matches the issue: no claude process present, no cli 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:

Evidence

Real Gateway built from this branch, isolated state (temporary HOME, OPENCLAW_STATE_DIR, own port), claude-cli runtime, and a small stand-in claude executable on PATH that speaks the stream-json protocol. Turns were driven with openclaw agent. The fault: after two normal turns, SIGKILL the 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.

# fault: SIGKILL the process-owner helper (pid <helper>) of the warm fake claude (pid <claude>)
# fake claude still alive? no
$ openclaw agent --session-id proof-before --timeout 40 --message "T3 turn right after the fault"
CLI produced no output for 39s and was terminated. | cli_no_output_timeout      [elapsed 40s]
$ ... --message "T4 next turn"
Input <id> was withdrawn before its turn started and was not delivered.          [elapsed 41s]
$ ... --message "T5 turn after that"
Input <id> was withdrawn before its turn started and was not delivered.          [elapsed 41s]
gateway: lane task error: ... durationMs=360000 error="Reply operation stalled"

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.

$ openclaw agent --session-id proof-after --timeout 40 --message "T3 turn right after the fault"
Claude CLI process cleanup could not be confirmed; restart the Gateway before retrying. | service child cleanup identity lost: anchor channel closed without a matching closing receipt   [elapsed 1s]
$ ... --message "T4 next turn"      (same error, elapsed 1s)
$ ... --message "T5 turn after that" (same error, elapsed 1s)

The full harness (stand-in claude and 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:

#!/usr/bin/env node
// Fake Claude Code for the wedge proof: speaks stream-json just enough for one warm session.
const fs = require("node:fs");
const readline = require("node:readline");
const args = process.argv.slice(2);
const dir = process.env.FAKE_CLAUDE_DIR || "/tmp";
const log = (m) => fs.appendFileSync(`${dir}/fake-claude.log`, `${new Date().toISOString()} pid=${process.pid} ${m}\n`);
if (args[0] === "auth") { console.log(JSON.stringify({ loggedIn: true, authMethod: "claude.ai", email: "[email protected]" })); process.exit(0); }
if (args.includes("--version") || args[0] === "-v") { console.log("2.1.318 (Claude Code)"); process.exit(0); }
const mode = () => { try { return fs.readFileSync(`${dir}/mode`, "utf8").trim(); } catch { return "normal"; } };
log(`start mode=${mode()}`);
if (mode() === "never-start") { setInterval(() => {}, 1000); } // hangs before reading stdin
else {
  const send = (v) => process.stdout.write(JSON.stringify(v) + "\n");
  let n = 0;
  process.on("SIGTERM", () => { log("SIGTERM"); if (mode() !== "ignore-term") process.exit(0); });
  const rl = readline.createInterface({ input: process.stdin });
  rl.on("line", (line) => {
    const m = JSON.parse(line);
    if (m.type === "control_request" && m.request.subtype === "initialize") {
      send({ type: "control_response", response: { subtype: "success", request_id: m.request_id, response: { commands: [], models: [] } } });
    } else if (m.type === "user") {
      n++; log(`turn ${n}`);
      send({ type: "system", subtype: "init", tools: [], session_id: "fake-session" });
      send({ type: "result", subtype: "success", is_error: false, result: `fake-reply-${n} pid=${process.pid}`, session_id: "fake-session" });
    }
  });
  rl.on("close", () => { log("stdin EOF"); process.exit(0); });
}

run-proof.sh:

#!/bin/bash
# usage: run-proof.sh <label> <session-id>   (gateway must already be running on :18991 with the fake claude on PATH)
P=<proof-dir>; . $P/env.sh; cd <home>/.t3/worktrees/openclaw-upstream/fix-claude-cli-live-session-wedge-v2
label=$1; sid=$2
ask(){ s=$(date +%s); out=$(timeout 150 node openclaw.mjs agent --agent main --session-id "$sid" --timeout "$2" --message "$1" 2>&1 | grep -v fnm_multishells | head -c 400); echo "\$ openclaw agent --session-id $sid --timeout $2 --message \"$1\""; echo "$out"; echo "[elapsed $(( $(date +%s)-s ))s]"; echo; }
echo "== $label: $(git rev-parse --short HEAD) =="
ask "T1 first turn" 60
ask "T2 second turn (warm session reused)" 60
CP=$(pgrep -f "^node $P/bin/claude --mcp-config" | tail -1); HP=$(ps -o ppid= -p "$CP" | tr -d ' ')
echo "# fault: SIGKILL the process-owner helper (pid $HP) of the warm fake claude (pid $CP)"; kill -9 "$HP"; sleep 2
echo "# fake claude still alive? $(kill -0 "$CP" 2>/dev/null && echo yes || echo no)"; echo
ask "T3 turn right after the fault" 40
ask "T4 next turn" 40
ask "T5 turn after that" 40

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.ts and cli-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 in config/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-ratchet passes and the shared scalar is unchanged. pnpm -s tsgo:core, run-tsgo.mjs -p test/tsconfig/tsconfig.extensions.test.json, oxlint and oxfmt --check are clean.

Not covered:

  • The owner loss is an injected fault. It is the only way I found to leave the exit wait pending, but I could not show it is what happened on the reporter's host.
  • No automatic recovery. A follow-up could let a non-subreaper owner use 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.

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.
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Nov 8, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Makes 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.

  • Before: The next turn waits for its timeout because cleanup never observes an exit event.
  • After: Cleanup rejects promptly and tells the user to retry the message, with Gateway restart guidance if failures repeat.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, supported mitigation with the previous finding resolved; overall scope remains partial against the broader linked report.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied isolated-Gateway trace exercises the production CLI transport and process owner through openclaw agent with an injected owner-loss fault, changing timeout stalls into prompt cleanup errors; subsequent edits preserve that settlement mechanism.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: A conversation can silently stall when its retired Claude process owner rejects cleanup without reporting an exit.
Reason: Prompt failure with retry guidance is valuable and narrowly scoped; using Related preserves #195030 for the unproven remainder.

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
Reviewed head: bdfb5a3cd7ca3566d577876b26477eb27fbc7ca4

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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
Loading

Technical review

Best 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

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +14, Tests +38, Other +4. Total +56 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 16 2 +14
Tests 1 38 0 +38
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 4 0 +4
Total 3 58 2 +56

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The established failure path blocks conversation progress behind a cleanup wait and leaves users waiting through message timeouts.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-08T07:05:00.375Z sha 1f79ff4 :: needs real behavior proof before merge. :: [P2] Account for the added regression lines in the test budget
  • reviewed 2026-11-08T08:10:41.632Z sha 9ee02bd :: needs maintainer review before merge. :: none
  • reviewed 2026-11-14T02:36:08.393Z sha 4a1abf3 :: needs changes before merge. :: [P2] Tell users to retry before requiring a Gateway restart

Reviewed November 13, 2026, 9:59 PM ET / November 14, 2026, 02:59 UTC (Revision 4).

machine3at and others added 2 commits November 8, 2026 13:14
… 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]>
@machine3at machine3at changed the title fix(agents): aborted Claude CLI turns stay stuck waiting for an unexited live session fix(anthropic): Claude CLI conversations hang silently after the process owner is lost Nov 8, 2026
@machine3at

Copy link
Copy Markdown
Contributor Author

@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.

@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Nov 14, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 14, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 14, 2026
@vincentkoc
vincentkoc merged commit 4f7b426 into openclaw:main Nov 14, 2026
86 of 87 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: anthropic P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants