Repository navigation
fix(claude-cli): replies hang until the run times out when a background agent runs Bash - #165596
Conversation
|
🦞👀 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 October 6, 2026, 9:13 PM ET / October 7, 2026, 01:13 UTC (Revision 6). ClawSweeper reviewWhat this changesThe Anthropic plugin excludes a background agent’s own task completions from parent-reply accounting and extends the subprocess regression coverage so completed replies finish promptly. Merge readiness✅ Ready for maintainer review This PR remains useful: current main still has the notification-accounting defect, and the recorded proof supports the focused repair. No actionable correctness or security findings remain. Likely related people: @VACInc and @steipete are medium-confidence routing candidates based on prior merged work in this runtime. Priority: P1 Review scores
Verification
How this fits togetherThe Anthropic plugin connects OpenClaw agent turns to the installed Claude Code executable through structured subprocess messages. Its completion accounting determines whether an answer is interim or final and when the session becomes available for another turn. flowchart TD
A[OpenClaw agent turn] --> B[Claude Code subprocess]
B --> C[Task starts and completions]
C --> D[Anthropic completion accounting]
D --> E[Exclude subagent task notifications]
E --> F[Settle parent results in order]
F --> G[Final reply and reusable session]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -4, Tests +9. Total +5 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep parent completion accounting in the existing Anthropic runtime, excluding subagent-owned notifications while preserving ordered settlement and warm-session lifecycle. Do we have a high-confidence way to reproduce the issue? Yes: the captured subagent Bash completion followed by the agent completion and a single parent result deterministically leaves the agent pending on current main. The recorded negative control confirms this mechanism; this read-only review did not execute it. Is this the best way to solve the issue? Yes: filtering notifications at their existing accounting owner repairs the incorrect queue slot without changing reply delivery, permissions, configuration, or public APIs. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7b66485dcd9b. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
…urn open When a native background agent runs Bash itself, Claude Code reports that command on the main stream: task_started with owned_by_subagent: true, then a task_notification with no owner field, before the agent's own notification. The runtime queued that notification, so the agent's task-notification result consumed the Bash slot instead of the agent's. The agent stayed pending, the turn never completed, and the run ended at the CLI timeout and fell back to another model, which re-ran the prompt. Tasks started with owned_by_subagent are now recorded and their notifications dropped instead of queued: the subagent answers them, never the parent turn. Measured on Claude Code 2.1.289 (Opus 5.5 and Opus 5).
db1fef6 to
c3e35e4
Compare
Keep subagent-owned notifications out of the parent completion queue. Simplify single-use task predicates and remove the unused close-reason forwarding path. Replace the background-agent fixture's file polling with a protocol response barrier, and assert terminal output before waiting for iterator settlement so regressions fail on the misplaced interim marker instead of a timeout. Original fix by @adele-with-a-b; contributor ancestry is preserved.
|
Merged via squash.
|
…nd agent runs Bash (openclaw#165596) * fix(claude-cli): a background agent's own Bash no longer leaves the turn open When a native background agent runs Bash itself, Claude Code reports that command on the main stream: task_started with owned_by_subagent: true, then a task_notification with no owner field, before the agent's own notification. The runtime queued that notification, so the agent's task-notification result consumed the Bash slot instead of the agent's. The agent stayed pending, the turn never completed, and the run ended at the CLI timeout and fell back to another model, which re-ran the prompt. Tasks started with owned_by_subagent are now recorded and their notifications dropped instead of queued: the subagent answers them, never the parent turn. Measured on Claude Code 2.1.289 (Opus 5.5 and Opus 5). * fix(anthropic): prove subagent Bash replies complete without a timeout Keep subagent-owned notifications out of the parent completion queue. Simplify single-use task predicates and remove the unused close-reason forwarding path. Replace the background-agent fixture's file polling with a protocol response barrier, and assert terminal output before waiting for iterator settlement so regressions fail on the misplaced interim marker instead of a timeout. Original fix by @adele-with-a-b; contributor ancestry is preserved. --------- Co-authored-by: Peter Steinberger <[email protected]>
Backport the approved Doctor/update and Claude CLI fixes to the frozen 2026.9.9 cut. Preserve release-local migration prelude and recovery paths. Include the landed WhatsApp fixture synchronization repair uncovered by validation. No version, dependency, schema, or publication change. Sources: #164868, #163369, #165837, #165596, and #166531. Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Víctor Gurbani Carballo <[email protected]> Co-authored-by: Abdel Gomez-Perez <[email protected]>
Audit all 253 September-only commits against da0cbcc. Port only applicable fixes and final companions, preserving October owners and shipped upgrade contracts. Exclude September-specific waivers, schema rollback, dependency changes, and credential-absence pass conditions. Adapt retained ACP archive receipts without reopening retired custody; retain SDK1.30.1 issuer fencing and explicit re-registration; exclude standalone worker copies from beta.2 updater compatibility bridges. Report settled Doctor release failures before the no-config early return. Sources below are whole backports or scoped repair selections: fix(discord): keep health inspection from blocking Gateway connections (openclaw#166736) Source-commit: dc26366 fix: avoid foreign-listener race in Gateway acquisition proof (openclaw#166883) Source-commit: bd0b97d fix(ci): admit workspace package tests in Windows replay (openclaw#166895) Source-commit: 9bc88a6 fix(release): restore beta.2 updater inventory and Podman control (openclaw#166872) Source-commit: e203c64 fix(copilot): plugin tool calls fail from the second turn of a session (openclaw#164598) Source-commit: c6e5ae8 fix(test): await WhatsApp inbound drain (openclaw#165842) Source-commit: 05170cd fix(qa-lab): keep SUT CLI in isolated launcher Source-commit: 6681bcd test(qa-lab): assert resolved companion CLI cwd Source-commit: a60b458 fix(release): accept candidate-owned child evidence (openclaw#165357) Source-commit: 500c95a fix(acp): migrate metadata from retained sessions Source-commit: 16398dc fix(release): isolate first-hop service containment (openclaw#164898) Source-commit: 85124fe fix(release): isolate upgrade survivor scenarios (openclaw#165007) Source-commit: aad828f test(release): expect isolated survivor scenarios (openclaw#165009) Source-commit: 02e7f91 fix(release): split restart auth validation (openclaw#165048) Source-commit: 6160d9f test: serialize PowerShell completion process suites (openclaw#166229) Source-commit: 320e52b fix(update): settle only this Doctor's commands in managed custody (openclaw#164868) Source-commit: bdb44e2 fix(claude-cli): replies hang until the run times out when a background agent runs Bash (openclaw#165596) Source-commit: 889611b fix(whatsapp): synchronize shutdown test with durable admission (openclaw#166531) Source-commit: 1f576e4 fix: prevent heartbeat live replies from abbreviating markers (openclaw#166777) Source-commit: c4ed37e fix(ci): keep full release validation within measured budgets (openclaw#166774) Source-commit: 471f950 improve(ci): reuse Watch cache and expose shared scan build progress (openclaw#166498) Source-commit: 66d898f fix(e2e): normalize registry helper image modes (openclaw#163188) Source-commit: 1a09bec fix: MiniMax live validation misses Code Mode file reads (openclaw#163619) Source-commit: fc23bc8 fix(test): read canonical ACP upgrade metadata Source-commit: 46c8dd2 fix(qa): remove unavailable Telegram emoji fixture (openclaw#164956) Source-commit: e785c56 fix(release): reconcile full validation regressions (openclaw#166200) Source-commit: a3e349e fix(release): unblock stable validation evidence (openclaw#166315) Source-commit: 5ac0f82 fix(release): unblock 2026.9.9 full qualification (openclaw#166341) Source-commit: 8aa6d7c test(irc): await owned monitor signals (openclaw#163180) Source-commit: 429ea8c fix(release): unblock 2026.9.9 full validation (round 4) (openclaw#166485) Source-commit: ccb390b fix(release): repair Doctor teardown and FRV evidence recovery Source-commit: 5d7fa8e fix(release): bound FRV job reads and normalize ghost evidence Source-commit: 1854d41 test(release): align priority fixture with bounded job pages Source-commit: 4fd4fcc fix(test): keep MCP validation connected after automatic pairing approval (openclaw#166849) Source-commit: 0979efd fix(release): address 2026.9.9 validation failures and retain diagnostics (openclaw#166962) Source-commit: a024875 fix(release): repair fleet and CLI validation fixtures (openclaw#166977) Source-commit: b899f42 fix: keep 2026.9.9 upgrades on state schema 19 (openclaw#166959) Source-commit: bcfc888 fix(ui): keep passive chat viewers following incoming turns Source-commit: 6d9689d fix(doctor): commit transcript archive migration progress per batch and honor interruption (openclaw#165837) Source-commit: 3a085ea fix(doctor): restore release repair settlement Source-commit: fab3a66 fix(release): reconcile FRV backports Source-commit: 0c01cc6 fix(ui): refresh end geometry during interaction (openclaw#166239) Source-commit: 5b71763 fix(ui): preserve follow intent across content growth (openclaw#166258) Source-commit: ffcdd4d fix(ui): gate content follow on height changes (openclaw#166301) Source-commit: 4964263 fix(release): preserve gateway fixture close callback (openclaw#166348) Source-commit: 64ad20a test(ui): await collaborator smooth follow (openclaw#166285) Source-commit: 90abf6a Co-authored-by: Eric Curtin <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Abdel Gomez-Perez <[email protected]> Co-authored-by: Patrick Erichsen <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
What Problem This Solves
Fixes a
claude-clireply hanging until the run times out when a native background agent runs its own Bash command.User Impact
The completed background agent's answer finishes the turn promptly, without waiting for the run timeout and a model fallback that can repeat the work.
Why This Change Was Made
Claude Code reports the subagent's Bash start on the main stream with
owned_by_subagent: true. Its completion notification has no owner field and arrives before the background agent's own notification. Only the agent's notification produces a parentresultwithorigin.kind=task-notification. Previously, OpenClaw queued both notifications: that single result consumed the Bash slot, leaving the agent ID pending. The final answer was therefore markedopenclaw_interim_result, the iterator stayed open, and the run eventually timed out. An empty native background-task list does not acknowledge a queued answer.The existing Anthropic runtime now remembers subagent-owned task IDs at start and excludes their completion notifications from the parent's result queue. Parent notification ordering, inline replay receipts, host permissions, failure retirement, and warm-session reuse keep their existing behavior. No config, SDK, protocol, or schema changes are introduced.
Maintainer cleanup removes repeated comments, inlines single-use task constants, and removes an unused close-reason parameter. The regression extends the existing native stdio fixture, replacing this scenario's file polling with a permission-response barrier. It asserts the final result before awaiting iterator settlement, so the original defect fails directly instead of consuming a 10-second timeout.
Related: #158626. That issue describes broader missing Telegram delivery; no exact matching issue was established, so this PR does not claim to close it. This is a separate notification-accounting defect from #161260.
Evidence
Verified head:
54e4565c1b081ee704b73d499d6fdd534cc3e9fe.The defect remains in main at
7880834c19616b5efb871e1755cd4b30cf2f2481: subagent notifications are still unconditionally queued. The runtime's only change since this PR's merge-base is unrelated removal of unused close-reason forwarding.oxfmt --check, targetednode scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.jsonon all three changed files, andgit diff --checkpassed. No contributor runtime or tests executed locally.cbx_282cb9b8daa1, runrun_e7670f2b86b20242c4b91a4ce18d840e, bound to the full pushed head. The clean trusted-main bootstrap verified the head, the IMDSv2 no-instance-role boundary, and the package-manager pin; no hydration or Tailscale. The lease was stopped andcrabbox list --provider awsconfirmedreleased.Passing command:
Both typechecks passed; all 36 tests passed. Combined wall time: 72.79 s. Test command wall time: 40.04 s, with 5.172 s summed test-case time; the new subagent-Bash case took 48 ms. The existing transport suite tests real child-process framing and lifecycle; cold compiled-worker preparation took 21.101 s. No new timers, sleeps, polling, or production test seams were added.
CI test cost: exact-head extension job passed in 119 runner seconds; its selected test command took 50.09 s across the extension shard (including other selected files). The 36 runtime test cases totaled 4.721 s in that job.
Negative control on the same lease and head, changing only the production file:
git checkout c3b2b7d3fc1a053d2f6907e55e1629c16fc53706 -- extensions/anthropic/cli.runtime.ts pnpm test extensions/anthropic/cli-runtime.test.ts --maxWorkers=1 -t background-agent-subagent-bashIt failed in 69 ms of test-case time (30.34 s command wall time, including recompilation), exit 1, at
cli-runtime.test.ts:312:LOC,
git diff --numstat origin/main...HEAD: production +16/-20 (net -4); tests/test support +48/-39 (net +9):Contributor's original native and live evidence
The original contributor observed Claude Code 2.1.289 emit an interim parent result, then a subagent-owned Bash start, the Bash completion, the agent completion, and a single parent task-notification result. On their live Gateway build, the unpatched run exceeded 360 seconds and invoked fallback; the same build with the original fix completed in 91,087 ms without fallback. These are contributor-reported live observations. The maintainer proof above independently verifies the captured ordering through the native stdio boundary; it does not claim a new authenticated Claude run.
Original fix by @adele-with-a-b (Abdel Gomez-Perez); maintainer cleanup simplifies the same owner and makes the regression deterministic. Contributor commits and ancestry are preserved.