Repository navigation
fix: Claude CLI backend drops a backgrounded Bash call's follow-up turn and denies its tools - #149967
Conversation
…n the background Claude Code moves a foreground Bash call to the background after its timeout, emits an interim result, then delivers a task_notification turn with a second result. The CLI runtime only held the turn for local_agent and local_workflow tasks, so the interim result completed the OpenClaw run and the notification turn ran with no admitted run: every tool call in it was denied with "The OpenClaw run is no longer active" and its reply never reached the session. Hold the turn for a local_bash task only when Claude Code reported it started in the foreground and it then appears in the background task list. Explicit run_in_background calls may never finish and are not held. Task ids are cleared when the turn completes.
|
🦞👀 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. Reviewed September 19, 2026, 1:36 PM ET / 17:36 UTC (Revision 4). ClawSweeper reviewWhat this changesThe Anthropic plugin retains timeout-backgrounded Bash continuations until Claude processes their completion, with matching subprocess cleanup, tests, and documentation. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main and the latest release retain the premature-completion path. No actionable introduced defect was found, and the supplied live observation plus focused lifecycle coverage support the repair. Priority: P2 Review scores
Verification
How this fits togetherThe Anthropic CLI backend connects admitted OpenClaw turns to a Claude Code subprocess. It mediates tool permissions and streams results into OpenClaw’s reply parser and session delivery. flowchart TD
A[Admitted OpenClaw turn] --> B[Claude Code subprocess]
B --> C[Background task tracking]
C --> D{Continuation consumed?}
D -->|No| C
D -->|Yes| E[Final result and reply parser]
B --> F[Current host permission checks]
E --> G[Session answer]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +84, Tests +206, Docs +6. Total +296 across 5 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep continuation settlement inside the Anthropic runtime while preserving current-turn permissions, canonical reply merging, and process retirement on failure. Do we have a high-confidence way to reproduce the issue? Yes: current-main source completes an interim result when only local_bash work remains, matching the supplied timeout-and-follow-up live observation. This review did not execute a current-main reproduction. Is this the best way to solve the issue? Yes: turn-local pending-task tracking repairs the existing lifecycle owner and reuses established permission and reply-delivery paths without adding configuration or persistent state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 89938348684e. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
Track foreground Bash continuations with their admitted turn until native replay confirms consumption. Retire pending processes on terminal failure and preserve the model response after batched completion acknowledgements.
|
Fixed: foreground Bash commands automatically backgrounded by Claude Code retain their follow-up tools and final answer within the original run. With thanks to @Marvinthebored. |
…rn and denies its tools (openclaw#149967) Keep foreground Bash commands automatically backgrounded by Claude Code admitted through completion processing and final replies. Retire unfinished native work on failure before starting the next turn. Refs openclaw#149966. Reviewed-by: @shakkernerd Co-authored-by: Peter Lindsey <[email protected]> Co-authored-by: Shakker <[email protected]>
Refs #149966
What Problem This Solves
Fixes premature run completion when Claude Code moves a foreground Bash command to the background after its tool timeout. The command can finish after an interim answer, but OpenClaw previously closed the admitted run before Claude processed its completion. Follow-up tools then received “The OpenClaw run is no longer active,” and the final answer did not reach the session.
The completion boundary also needs to distinguish a finished command from a processed notification. Claude can report completion while its notification is still queued, consume the notification during the current query, or batch several notifications into a later model call. Each case must keep the original run alive for exactly its remaining work.
User Impact
Automatically backgrounded foreground commands retain the same admitted run, host tool permissions, and final answer. Interim and final replies continue through the existing output merger. Commands deliberately started in the background retain prompt completion, including commands that may never finish; this repair does not add independent delivery for those commands.
Terminal failures and malformed raw tool results retire a native child that still has a required continuation. Cancellation and process exit settle the run before another turn can start, while ordinary completed turns and failures without pending work still reuse their warm process. No configuration or state migration is required.
Why This Change Was Made
The Anthropic runtime already holds successful interim results for native background agents and workflows. Bash needs a narrower rule: track tasks that started in the foreground and subsequently appeared as
local_bashin the background list. Intentionally backgrounded tasks never enter that pending set.The tracking now belongs to the admitted turn. This also fixes the incoming completion ordering, which cleared foreground task IDs before deciding whether the child could safely be reused. A failed turn keeps its pending-work evidence through the process-retirement decision.
A task disappearing from the live list, or emitting
system/task_notification, does not mean Claude has processed its completion. The runtime enables Claude’s existing user-message replay option and consumes only a root replay acknowledgement for an already tracked task ID. This handles both queued and inline notifications, including the older receipt shape that omits origin. Ordinary prompts, unrelated origins, and subagent receipts cannot settle that work. Existing host permission checks remain authoritative before and after asynchronous decisions and at the transport’s final write.Claude Code 2.1.274 also began batching queued completions: earlier notifications can produce an empty result with
num_turns: 0before the final notification triggers the shared model call. The runtime preserves that continuation while retaining normal terminal error handling. The distinction is documented in the official SDK changelog.Evidence
Process-boundary regression proof
The focused harness starts a real subprocess and drives the production stdio transport and host permission callbacks with producer-shaped records. On the original PR head, tests-only overlays reproduced five failures: premature completion on a batched empty result; reuse of a child after terminal error or malformed raw tool output; completion before an early-finished command’s queued notification; and unsafe reuse after that queued work receives a terminal error.
The corrected candidate covers foreground and intentional-background commands, queued and inline completion, batched notifications, allowed and denied follow-up tools, misleading replay records, terminal failures, cancellation, process exit, and subsequent-turn process reuse or replacement. Remote validation uses isolated synthetic state with no provider credentials.
The final candidate passed all 129 focused tests: 37 runtime, 33 output validation, 2 instruction-isolation, 35 streaming output, and 22 JSONL tests. The same content passed formatting, typed lint with no warnings or errors, conflict and assertion ratchets, plugin boundary guards, and independent review through P2. Both extension type graphs and all 25 selected changed-path checks passed on the published head. Hosted CI is green, and ClawSweeper assessed this exact head as Platinum with no findings.
The composition with main at f2dff0d also passed 77 caller and reply-settlement checks. Two of those drive the actual Anthropic subprocess through the generic CLI executor and canonical parser with required and optional reply expectations: the run remains attached during the empty interim result, the continuation receives host approval, final settlement produces one answer payload, and cleanup removes the child process.
Retained contributor live observation
The author reported a real before/after run through a loopback Gateway and Claude Code 2.1.272 at original head 6e4ba86. One
chat.sendrequested a 60-second Bash command with a 30-second tool timeout, an interimWAITINGresponse, and a marker-file read after the completion notification.WAITINGReadcallWAITINGWAITINGandmarker-alpha-7431, then becomes idleThat author-reported live observation establishes the original single-command failure and success path. The additional lifecycle and batching corrections above are backed by controlled subprocess reproductions and inspection of the official 2.1.272 SDK/native artifact and the 2.1.277 producer. No new live-provider run is claimed.