Skip to content

fix: Claude CLI backend drops a backgrounded Bash call's follow-up turn and denies its tools - #149967

Merged
shakkernerd merged 2 commits into
openclaw:mainfrom
Marvinthebored:fix/hold-turn-for-backgrounded-bash
Sep 19, 2026
Merged

shakkernerd merged 2 commits into
openclaw:mainfrom
Marvinthebored:fix/hold-turn-for-backgrounded-bash

Conversation

@Marvinthebored

@Marvinthebored Marvinthebored commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

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_bash in 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: 0 before 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.send requested a 60-second Bash command with a 30-second tool timeout, an interim WAITING response, and a marker-file read after the completion notification.

Result Original main runtime Contributor’s initial patch
After Bash moves to the background Run becomes idle after WAITING Run remains active
Notification’s Read call Rejected as an inactive run Allowed through host policy
Session answer Stops at WAITING Includes WAITING and marker-alpha-7431, then becomes idle

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

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

clawsweeper Bot commented Sep 16, 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 19, 2026, 1:36 PM ET / 17:36 UTC (Revision 4).

ClawSweeper review

What this changes

The 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
Reviewed head: 53305c0c1cf8baa3bf7430609d71fd632712157f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with useful live before/after evidence, substantial boundary coverage, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The retained Gateway/Claude Code 2.1.272 observation shows the original timeout-backgrounded command retaining tools and delivering its final marker. Current-head production-transport subprocess evidence covers the subsequent batching and lifecycle corrections; it is not presented as another live-provider run.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The retained Gateway/Claude Code 2.1.272 observation shows the original timeout-backgrounded command retaining tools and delivering its final marker. Current-head production-transport subprocess evidence covers the subsequent batching and lifecycle corrections; it is not presented as another live-provider run.
Evidence reviewed 9 items Current main still needs the repair: Current main recognizes only local_agent and local_workflow as result-holding tasks; an interim result with only local_bash work completes the turn.
Latest-release comparison: The v2026.9.5 source contains the same task-list and interim-result completion logic without foreground Bash continuation tracking.
Continuation and authority lifecycle: The introduced tracking is turn-local. Completion retains pending-work evidence for process retirement, while existing authorization rechecks the admitted turn after awaited decisions and synchronously before the transport writes its response.
Findings None None.
Security None None.

How this fits together

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

Before merge

None.

Agent review details

Security

None.

PR surface

Source +84, Tests +206, Docs +6. Total +296 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 96 12 +84
Tests 2 211 5 +206
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 313 17 +296

Review metrics

Metric Value Why it matters
Production versus regression coverage production net +84 lines; tests and fixtures net +206 lines Production growth is justified by tracking notification consumption and safe subprocess reuse across distinct completion orderings.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #149966
Summary: This PR addresses the paired report’s timeout-backgrounded foreground Bash failure; independent delivery for deliberately backgrounded commands is explicitly outside its scope.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

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

Labels

Label justifications:

  • P2: This repairs a concrete continuation failure limited to the Claude CLI backend’s timeout-backgrounded Bash path.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The retained Gateway/Claude Code 2.1.272 observation shows the original timeout-backgrounded command retaining tools and delivering its final marker. Current-head production-transport subprocess evidence covers the subsequent batching and lifecycle corrections; it is not presented as another live-provider run.
  • proof: sufficient: Contributor real behavior proof is sufficient. The retained Gateway/Claude Code 2.1.272 observation shows the original timeout-backgrounded command retaining tools and delivering its final marker. Current-head production-transport subprocess evidence covers the subsequent batching and lifecycle corrections; it is not presented as another live-provider run.

Evidence

What I checked:

  • Current main still needs the repair: Current main recognizes only local_agent and local_workflow as result-holding tasks; an interim result with only local_bash work completes the turn. (extensions/anthropic/cli.runtime.ts:216, 89938348684e)
  • Latest-release comparison: The v2026.9.5 source contains the same task-list and interim-result completion logic without foreground Bash continuation tracking. (extensions/anthropic/cli.runtime.ts:216, ec9c1a13db89)
  • Continuation and authority lifecycle: The introduced tracking is turn-local. Completion retains pending-work evidence for process retirement, while existing authorization rechecks the admitted turn after awaited decisions and synchronously before the transport writes its response. (extensions/anthropic/cli.runtime.ts:225, 53305c0c1cf8)
  • Relevant upstream protocol contract: The PR depends on Claude Code’s replay and result protocol, not Codex. The pinned official SDK changelog documents the previously missing inline notification origin and the 2.1.274 change that batches completions with empty zero-turn results. These directly support the compatibility branches in the patch. (CHANGELOG.md:28, 18661edde449)
  • Captured behavior proof and review continuity: The supplied body snapshot reports a loopback Gateway chat.send run with Claude Code 2.1.272: a 60-second command exceeded its 30-second foreground timeout, followed by WAITING and a marker-file Read. The initial patch retained admission and delivered marker-alpha-7431. The current revision adds reported production-transport subprocess coverage for batching, inline and queued receipts, host denial, cancellation, process exit, and reuse. The previous same-head review contains no findings. The captured context sourceRevision is 682aa3bd1f12b079eea7611ca5e04846986f5007dfeb5ffc537a05edc7e2c8a1; no new live-provider execution is claimed. (53305c0c1cf8)
  • Meaningful boundary regression coverage: The complete runtime tests and subprocess fixture exercise pending-turn settlement, allowed and denied follow-up requests, misleading receipts, intentional background work, terminal failures, child termination, and fresh-process replacement. Existing tests cover revoked and late approvals. These tests were inspected, not executed during this read-only review. (extensions/anthropic/cli-runtime.test.ts:240, 53305c0c1cf8)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • shakkernerd: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-16T10:13:44.235Z sha 6e4ba86 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-16T10:53:22.540Z sha 6e4ba86 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-19T17:02:54.955Z sha 53305c0 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 16, 2026
@shakkernerd shakkernerd self-assigned this Sep 17, 2026
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.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M and removed size: S labels Sep 19, 2026
@shakkernerd
shakkernerd merged commit aef87fb into openclaw:main Sep 19, 2026
110 of 113 checks passed
@shakkernerd

Copy link
Copy Markdown
Contributor

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.

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

Labels

docs Improvements or additions to documentation extensions: anthropic gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

3 participants