Repository navigation
fix(claude-cli): stop unrelated native tasks holding the current final answer - #170322
Conversation
…background task was stopped or belongs to an earlier turn The native adapter kept a successful result interim while any task ID stayed in the turn's pending set. Several task shapes never leave that set, so the answer waited for the 600 s no-output watchdog, which then discarded it: - A task stopped with TaskStop: its task_notification status "stopped" was queued as a reply slot, the task stayed pending, and no notification query follows a stopped task. - A late child or resumed Agent from a previous input: task IDs were tracked per turn, so a prior input's work could hold or settle the current input. - A task that finished in the foreground got a reply slot and could consume the answer of a still-running background Agent. Changes: - task_notification status "stopped" is a receipt for that task ID only: it releases the task's pending entry and slots and never consumes another task's queued answer. - Task ownership is per session: the admitted input that first saw a task (or the parent's owner via parent_task_id). Only the current input's own tasks hold its result. - Foreground-completed tasks never get a reply slot. - Notification results are matched by origin.runId when the CLI sends it (2.1.296+), first-in-first-out otherwise. A prior input's answer consumes only its own slot and never completes the current turn. Refs openclaw#167580, openclaw#166585
…Bash Regression for openclaw#167580 / openclaw#166585: a foreground Bash is moved to the background, TaskStop kills it, the turn keeps working, and the final end_turn answer arrives with its one result and no later notification query. Before the stopped-receipt handling the stopped Bash stayed pending, the result was held as interim, and the 600 s no-output watchdog discarded the answer. The fixture follows real Claude Code stream traces, with host permission through PreToolUse: - fast: a short foreground timeout is first announced already backgrounded; - slow (>= 3 s, the shape that hid the bug in earlier probes): task_started is_backgrounded:false, task list, task_updated is_backgrounded:true; - 2.1.289 order (no run_id; empty task list before killed/stopped) and 2.1.296 order (run_id; empty task list after the stopped receipt). The test asserts one non-interim result after the end_turn assistant record, an idle session and warm reuse. Both cases time out without the stopped branch's pending-set release.
The added adapter cases take cli-runtime.test.ts past the max-lines budget. The fixture lifecycle hooks and helpers (createContext, createLiveSession, collect, resultDetail, fixtureReadyBeforeSettlement, waitForProcessExit) move unchanged into cli-runtime-harness.test-support.ts, and installClaudeProtocolHarness() registers the same per-file hooks. No test case changed.
|
🦞👀 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 changesThis PR prevents stopped tasks and earlier-input continuations from holding or settling the current Claude CLI answer. Example: Claude Code stops an automatically backgrounded Bash task and emits STOPPED_FINAL_candidate-fast.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a concrete task-ownership defect still present on current main; the scoped change is ready for normal landing with no actionable findings. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Anthropic plugin translates Claude Code stream-JSON events into the shared CLI runner’s result stream, tracking which native tasks must finish before an admitted input can settle. flowchart LR
A[Gateway admitted input] --> B[Anthropic CLI runtime]
B --> C[Claude Code process]
C --> D[Native task and result events]
D --> E[Session task ownership]
E --> B
B --> F[Shared CLI reply settlement]
Technical reviewBest possible solution: Land the scoped task-ownership repair while retaining separate tracking for missing native results and watchdog handling of genuinely pending work. Do we have a high-confidence way to reproduce the issue? Current-main source queues stopped notifications without releasing their pending task and lacks session-lived input ownership; the discussion supplies matching observed failures and candidate runtime results, but this read-only review executed no target code. Is this the best way to solve the issue? The patch repairs the existing Anthropic runtime owner with session-scoped identity and precise settlement, removes the superseded subagent set, and preserves genuine continuation holds without adding configuration, persistence, or a parallel execution path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d91197ecafe6. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +53, Tests +420, Docs +2. Total +475 across 7 files. Added test files: 2. View PR surface stats
Review metrics
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 (5 earlier review cycles)
Reviewed October 22, 2026, 4:18 PM ET / 20:18 UTC (Revision 6). |
…r instead of polling
# Conflicts: # extensions/anthropic/cli-runtime.test-support.ts # extensions/anthropic/cli-runtime.test.ts # extensions/anthropic/cli.runtime.ts
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in a9479eb. Thanks @cassthebandit. Claude CLI final answers are no longer held by stopped or earlier tasks. |
…l answer (openclaw#170322) fix(claude-cli): don't hold the final answer for stopped or earlier-input tasks With the Claude CLI runtime, a real final answer could be held and then lost when a stopped background task, or a task started by an earlier input, was treated as work the current turn still owned. Stopped tasks now settle, and tasks from earlier inputs no longer hold the current final answer; genuinely running background work still holds it until its answer arrives. This does not resolve the broader missing-reply reports, which have other causes. Evidence: real Claude Code 2.1.308 through built Gateway RPC in Docker with a local Messages fixture. On main the final answer was held in both cases; with this change stopped work settles and earlier-input work does not hold the current final, a live background Agent is still held until its answer, and the next input reuses the same native process and session. A live gpt-5.4-mini run passes. Production +53 (down from +148). Thanks @cassthebandit. Co-authored-by: Ayaan Zaidi <[email protected]>
…l answer (#170322) fix(claude-cli): don't hold the final answer for stopped or earlier-input tasks With the Claude CLI runtime, a real final answer could be held and then lost when a stopped background task, or a task started by an earlier input, was treated as work the current turn still owned. Stopped tasks now settle, and tasks from earlier inputs no longer hold the current final answer; genuinely running background work still holds it until its answer arrives. This does not resolve the broader missing-reply reports, which have other causes. Evidence: real Claude Code 2.1.308 through built Gateway RPC in Docker with a local Messages fixture. On main the final answer was held in both cases; with this change stopped work settles and earlier-input work does not hold the current final, a live background Agent is still held until its answer, and the next input reuses the same native process and session. A live gpt-5.4-mini run passes. Production +53 (down from +148). Thanks @cassthebandit. Co-authored-by: Ayaan Zaidi <[email protected]> Release adaptation: stable's Claude CLI runtime predates main's same-turn input injection, held results, and yield interrupts, so only the task-ownership logic is ported: session-level task owners and run IDs, stopped-task settlement, and prior-input notification results no longer settling the current turn. readReplayedTaskId keeps stable's single input UUID. Main's protocol-fixture split and harness-based task-ownership test are main-only; the new scenarios are added to stable's existing fixture and cli-runtime.test.ts (the injection-only ownership case is not ported). (cherry picked from commit a9479eb)
…#182267) * fix(claude-cli): finish parent replies after nested background agents Keep tasks launched by a native subagent out of parent-input completion accounting. Their notifications are consumed by the launching agent, not the main query. Cover nested Agents and workflows through the stdio runtime, preserving top-level holds and same-process warm reuse. Co-authored-by: steipete <[email protected]> * fix(claude-cli): finish parent replies after nested background agents Worked on by: - @steipete Co-authored-by: steipete <[email protected]> --------- Co-authored-by: steipete <[email protected]> Release adaptation: main's harness-based task-ownership test file does not exist on stable; the nested Agent/workflow cases are ported as a `nested-child-*` scenario in stable's protocol fixture and cli-runtime.test.ts. Companion follow-up to #170322. (cherry picked from commit f36f0cc)
…turns (#183765) * fix(claude-cli): let operators keep selected native Claude Code tools on managed turns * fix(claude-cli): retire warm sessions while native descendants still run Claude Code reparents a nested Agent when its foreground parent finishes, and a subagent's background child can resume its Agent later. Neither holds the turn, so a warm process kept them alive into the next admitted turn, where native permission callbacks and the process MCP bearer resolve to that turn's authority. Close the process instead when any Agent, Workflow, or subagent-owned task is still running at turn end. * docs(claude-cli): describe warm-process retirement for running native descendants --------- Co-authored-by: VACInc <[email protected]> Release adaptation: stable has no delegated-execution tool policy (#168085), so managed native tools are dropped only for restricted senders, caller caps, and workspace-only runs (docs, manifest help, and the SDK doc comment no longer mention delegated execution); resolveCliRuntimeToolPolicy stays synchronous. The descendant-retirement hunk lands on the #170322 task-ownership port. Tests are ported into stable's structure: the delegation policy test becomes prepare-tool-policy.managed-native.test.ts, the bootstrap file-access case moves to prepare.bootstrap-file-access.test.ts, and the cli-runtime fixture harness is shared via cli-runtime.harness.test-support.ts so task-ownership cases live in cli-runtime.task-ownership.test.ts (keeps both files under the line cap). Adds a subagent-owned and a reparented nested-descendant scenario. Adds the plugins.entries.anthropic.config.managedNativeTools option (off by default). (cherry picked from commit 3eeb12b)
… a background agent (#182516) Keep nested background-agent continuations owned by the current input until their forwarded answer arrives. Reuse the descendant tracker for launcher identity, releasing a child hold while its running parent consumes the result. Preserve foreground-descendant retirement and previous-input isolation. Validation: both Agent/Workflow forwarded-answer regressions fail on current main; the four focused native task/runtime/yield/process suites pass 93 tests with one Linux-only skip. Exact-head CI 40292223795 is green. Retained contributor real Claude CLI/local Messages API traces cover both completion orders and warm reuse; no live provider session was repeated. Related: #182175, #170322. Co-authored-by: Dmitriy <[email protected]>
… a background agent (openclaw#182516) Keep nested background-agent continuations owned by the current input until their forwarded answer arrives. Reuse the descendant tracker for launcher identity, releasing a child hold while its running parent consumes the result. Preserve foreground-descendant retirement and previous-input isolation. Validation: both Agent/Workflow forwarded-answer regressions fail on current main; the four focused native task/runtime/yield/process suites pass 93 tests with one Linux-only skip. Exact-head CI 40292223795 is green. Retained contributor real Claude CLI/local Messages API traces cover both completion orders and warm reuse; no live provider session was repeated. Related: openclaw#182175, openclaw#170322. Co-authored-by: Dmitriy <[email protected]>
… a background agent (#182516) Keep nested background-agent continuations owned by the current input until their forwarded answer arrives. Reuse the descendant tracker for launcher identity, releasing a child hold while its running parent consumes the result. Preserve foreground-descendant retirement and previous-input isolation. Validation: both Agent/Workflow forwarded-answer regressions fail on current main; the four focused native task/runtime/yield/process suites pass 93 tests with one Linux-only skip. Exact-head CI 40292223795 is green. Retained contributor real Claude CLI/local Messages API traces cover both completion orders and warm reuse; no live provider session was repeated. Related: #182175, #170322. Co-authored-by: Dmitriy <[email protected]> Adaptation: Keep the B monolith and its queue semantics; persist input ownership and descendant relations before active-turn filtering, release children only for running launchers, retain parent-ended forwarded receipts, ignore duplicate notifications and pre-input/old-input holds. Preserve explicit subagent exclusion, injected-input and cancellation behavior. Source-commit: 3d7f8fb Co-authored-by: RomneyDa <[email protected]>
Preserve accepted native conversation cursors, current async capability ownership, input UUIDs, and bounded native task lifecycle. Adapt configured MCP and Workshop mediation to the release owners without a schema change. Release adaptation of 29ec680 (#117397). Original source author: Peter Steinberger <[email protected]> Release adaptation of e2b7206 (#159931). Original source author: James Myers <[email protected]> Release adaptation of adb9a7c (#181311). Original source author: Peter Steinberger <[email protected]> Release adaptation of 93a248d (#178420). Original source author: sunlit-deng <[email protected]> Release adaptation of 399a360 (#179914). Original source author: Peter Steinberger <[email protected]> Release adaptation of 0df027b (#179203). Original source author: Peter Steinberger <[email protected]> Release adaptation of 4a2a4e0 (#183059). Original source author: Peter Steinberger <[email protected]> Release adaptation of a9479eb (#170322). Original source author: cassthebandit <[email protected]> Release adaptation of 3eeb12b (#183765). Original source author: Vito Cappello <[email protected]> Release adaptation of 77d9f42 (#172026). Original source author: Marvinthebored <[email protected]> Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Fixes the Claude CLI task-ownership bug where a stopped background task or a task belonging to an earlier input holds the current final answer. Native has already emitted a successful terminal result, but OpenClaw incorrectly counts unrelated work against the current input and leaves that answer provisional.
Not fixed here: the broader missing-reply reports #167580 and #166585 are not closure targets. Missing replies caused by native failing to emit a terminal
result, or by the host watchdog/timeout handling of genuinely pending work, have different causes from incorrect task ownership and are not repaired here. #167580 does not establish stopped-task involvement or distinguish an absent stdout result from a held result. #166585 includes a stopped-task case this patch addresses, but its broader watchdog/reply-loss report is not claimed fully resolved. Watchdog waiting and timeout preservation are separate work in #166511.Changes
Stopped task notifications release only that task's hold; they do not reserve an answer slot. Task ownership follows the admitted input for the lifetime of the native session, including resumed Agents and subagent work. Notification results use native run IDs when available and otherwise retain ordered receipt matching. Earlier-input results cannot overwrite a held current-input answer. Foreground completions do not consume a background Agent's answer.
The per-turn subagent identity set is removed. Identity parsing lives in a small internal module, not a plugin-SDK API. The protocol fixture and held-answer regression are split out rather than suppressing line limits. Redundant synthetic stopped cases are removed in favor of captured native event orders and real-runtime proof. Production delta against main: +53 lines, reduced from the original +148-line proposal; focused tests retain distinct stop, sibling, subagent, stale-input, run-ID and injected-input boundaries. No config or persisted-state changes.
Evidence
Inspectable redacted built-Gateway/native-Claude output covers stopped-task settlement, earlier-input isolation, the genuine-background control and warm reuse.
Built artifacts in an isolated Node 24.22.1 Docker container, with local provider fixtures configured through shipped commands and sessions created through Gateway RPC. The actual Claude Code binary generated native task events; no shortened watchdog or scratch backend descriptor was used. Native Bash/TaskStop/Agent are enabled with the shipped exec-host configuration.
agent.waitstill timed out. One completed observation reached the normal 180-second no-output watchdog. A genuine background Agent control remained held until its notification answer and then completed.CURRENT_FINAL; stopped-task final completed without the post-native hold, and the follow-up reused the same native process and session. Genuine background Agent work still held and completed normally after release.openai/gpt-5.4-minireturnedLIVE_OKthrough the built Gateway/Agents API; credentials were resolved from a private file and removed afterwards. Native fixture runs used Claude Code 2.1.308.Limits: local provider responses are deterministic fixtures, not an Anthropic service run. No channel-delivery or Claude CLI version matrix claim.
Two-way door: reverting restores the prior in-memory task bookkeeping; no data migration or public API changes. Blast radius is Claude CLI sessions using native tasks, background work or same-turn injected input.