Skip to content

fix(claude-cli): finish parent replies after nested background agents - #182267

Merged
roboclaw-bot merged 2 commits into
mainfrom
openclaw/claude-background-reliability-20261024
Oct 24, 2026
Merged

roboclaw-bot merged 2 commits into
mainfrom
openclaw/claude-background-reliability-20261024

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #182175

What Problem This Solves

Fixes: Claude CLI parent replies can remain in progress indefinitely after a background Agent launches another background task.

User Impact

User impact: the parent reply finishes when its own background work settles, without waiting for a nested task's reply on the wrong stream. Top-level background work still keeps its parent reply open. No configuration or migration is required.

Why This Change Was Made

Claude identifies nested Agents and workflows with parent_task_id, but reserves owned_by_subagent for nested Bash tasks. Treat all tasks with a parent as owned by that subagent instead of inheriting ownership of the outer input. Keep the existing completion, replay, and watchdog policies unchanged.

Evidence

  • Native stdio regressions for nested Agents and workflows fail on the base revision because the final result is incorrectly marked interim; both pass with the fix. They also verify warm-session reuse with the same process.
  • Anthropic CLI runtime suites: 69 tests passed. Host CLI execution/watchdog suites: 32 tests passed. Targeted typecheck, lint, formatting, and diff checks passed.
  • Claude 2.1.296 producer source confirms parent_task_id means the launching local Agent, while owned_by_subagent is emitted only for nested Bash.
  • Canonical fresh autoreview completed with no P0–P2 findings; simplification review retained one ownership rule and removed parent-input inheritance.
  • A built, isolated Gateway at implementation commit 6802faaa completed chat.send → native Claude stdio → agent.wait with status: ok and terminal reply parent final; chat.history retained both interim and final text. The focused E2E test passed, and its owned Gateway and state were removed. Publication added a metadata-only commit; the published tree is identical to the tested tree.
  • Live Claude subscription inference has not been exercised. The Gateway proof used a synthetic external Claude protocol executable and synthetic credentials, not a live Anthropic account. An earlier in-process fixture failed native-supervisor startup before reaching the protocol; the final proof uses a separately built Gateway process.

Thanks to Peter Steinberger (@steipete).

Work sessions

Worked on by

roboclaw-bot and others added 2 commits October 24, 2026 05:03
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]>
Worked on by:
- @steipete

Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 03795749-42de-4fcd-ada4-4794e31a50d2
@clawsweeper

clawsweeper Bot commented Oct 24, 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 docs Improvements or additions to documentation gateway Gateway runtime extensions: anthropic size: S labels Oct 24, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review October 24, 2026 05:22
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Exclude subagent-launched tasks from parent-input completion accounting and add nested Agent and workflow regressions.

Example: Background Agent parent launches child with parent_task_id="parent", then the parent finishes with "parent final".

  • Before: The child remains pending on the parent input, so the final answer is marked interim and the turn stalls.
  • After: The child belongs to its launching subagent, allowing the parent's final answer to complete the turn.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The repair is focused and source-supported with meaningful transport regressions and passing gates; independent runtime confidence remains bounded by synthetic producer coverage.
Proof confidence 🦐 gold shrimp (3/6) This collaborator/bot PR is outside the ordinary contributor proof gate; its body reports a built-Gateway chat.send → Claude stdio → agent.wait success with retained history using a synthetic executable, while inspectable committed coverage exercises the real adapter with synthetic protocol events rather than native Claude inference.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A completed Claude CLI answer remains in progress because a nested background task is incorrectly charged to the parent turn.
Reason: The collaborator-authored direction addresses an evidenced current bug with a smaller ownership rule and no new configuration, public API, or persisted-state contract.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: current main still misattributes nested background tasks, and this focused repair addresses the resulting reply-completion failure without changing watchdog policy.

Priority: P1
Reviewed head: 6fee39c5794cabb926e86461d73098875d3dc93b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No inspectable after-fix native-Claude trace demonstrates nested task production, terminal parent settlement, and a successful warm follow-up.
Agent review details

How this fits together

The Anthropic CLI adapter consumes native task events, records session-wide ownership, and emits interim or terminal results to the host runner.

flowchart LR
  A[Gateway input] --> B[Claude CLI transport]
  B --> C[Native task events]
  C --> D[Task ownership]
  D --> E[Parent completion accounting]
  E --> F[Terminal reply]
Loading

Technical review

Best possible solution:

Keep nested-task classification in the existing ownership helper while preserving top-level holds, notification settlement, and warm-session reuse.

Do we have a high-confidence way to reproduce the issue?

The supplied event order deterministically leaves the nested task pending on current main; source and regression inspection establish the path, but this read-only review executed no target code.

Is this the best way to solve the issue?

The patch repairs classification at the existing producer of ownership facts, preserves legitimate continuation accounting, and avoids timers or watchdog changes that could hide the cause.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 70ad789846f2.

Provenance checked

  • Nested task ownership changes intended behavior with a stated reason (a9479eb: fix(claude-cli): stop unrelated native tasks holding the current final answer #170322 preserved task ownership across inputs and resumed work to prevent unrelated tasks holding current replies.)
  • CLI completion documentation keeps the original intent (a9479eb: The existing documentation separates legitimate current-input continuations from stopped or earlier-input work; the addition clarifies the same boundary for nested tasks.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source -2, Tests +75, Docs +1. Total +74 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 4 6 -2
Tests 1 75 0 +75
Docs 1 2 1 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 81 7 +74

Labels

Label changes:

  • add P1: The linked official-release incident loses normal reply completion and stalls an active agent workflow until watchdog termination.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: The linked official-release incident loses normal reply completion and stalls an active agent workflow until watchdog termination.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach redacted native-Claude output showing a nested Agent, terminal parent completion, and successful reuse of the same session.

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.

Reviewed October 24, 2026, 1:39 AM ET / 05:39 UTC.

@roboclaw-bot
roboclaw-bot merged commit f36f0cc into main Oct 24, 2026
200 of 201 checks passed
@roboclaw-bot
roboclaw-bot deleted the openclaw/claude-background-reliability-20261024 branch October 24, 2026 05:49
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
…openclaw#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]>
OpenClaw-Publication: 03795749-42de-4fcd-ada4-4794e31a50d2

---------

Co-authored-by: steipete <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 26, 2026
…#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)
RomneyDa added a commit that referenced this pull request Oct 28, 2026
…#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]>
OpenClaw-Publication: 03795749-42de-4fcd-ada4-4794e31a50d2

---------

Co-authored-by: steipete <[email protected]>

Adaptation: Apply nested classification directly in the B runtime monolith and its real stdio fixture. This intermediate source behavior is corrected by the required next source for parent-ended-first forwarding; no extracted runtime architecture imported.

Source-commit: f36f0cc
Co-authored-by: RomneyDa <[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 P1 High-priority user-facing bug, regression, or broken workflow. 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

1 participant