Repository navigation
fix(agents): preserve Claude parent replies after discarded subagent output - #184352
Conversation
Claude Code forwards every subagent's traffic on stdout with parent_tool_use_id set. The streaming parser keeps nothing from those records but the parent id, for progress; the subagent's answer reaches the parent through the Agent tool result. Yet each record was charged its full size against the 8 MiB per-turn budget, so a research turn that fanned out to many subagents spent the budget on output it never kept and lost its finished reply after the work was done. Each forwarded subagent record now costs a fixed 64-character allowance against the same budget and still counts toward the frame limit, so subagent floods stay bounded. Parent-lane output keeps its full accounting.
Co-authored-by: Jaxon Parrott <[email protected]> # Conflicts: # src/agents/cli-output-stream-limits.ts # src/agents/cli-output-stream.ts
|
🦞👀 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Built-entry-point verification for Linux / Node 24.22.1 / real Claude Code 2.1.310, native CLI pointed at a deterministic local Messages fixture. Both refs use the shipped Anthropic plugin Candidate large native streams are approximately 10.7 MB, including approximately 10.3 MB of child assistant/user records discarded by the parser, followed by the native success result. Main aborts around 8.7 MB with the 8,388,608-character output error. Separate registered-runtime stdout fault controls replayed two retained child-attributed text deltas of 4,300,000 characters each and a 9,000,000-character single child line before the real CLI result. Candidate rejects both with exit 1 and the existing budget/line errors. Only these negative controls splice records; primary A/B turns have unchanged native output and argv. The new retained-child regression fails on the contributor's original permissive charging; the integrated repair passes all 80 focused stream/framing/partial/subagent tests. Build, touched lint and formatting pass; integrated independent review is scoped-clean through P2. No native-tool or authority policy is changed by the patch. |
|
Codex review: needs maintainer review before merge. What this changesThis PR discounts discarded Claude subagent messages while preserving full accounting for retained output. Example: A native Claude subagent produces approximately 10.3 MB of discarded child messages before the parent returns PARENT_ANSWER_INTACT.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open for landing: it repairs a current-main reply-loss bug, preserves the existing output safeguards, and has relevant built-runtime verification; no actionable defects were found. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe CLI runner feeds Claude JSONL stdout through bounded framing and record accounting, then projects retained replies, tool events, and attributed progress to Gateway consumers. flowchart TD
A[Claude CLI stdout] --> B[Bounded JSONL framing]
B --> C[Record budget accounting]
C --> D[Canonical streaming parser]
D --> E[Parent reply delivery]
D --> F[Attributed child progress]
Technical reviewBest possible solution: Land the focused accounting repair so discarded child payloads cannot prevent parent delivery while retained output remains bounded. Do we have a high-confidence way to reproduce the issue? Current-main source charges discarded child records before excluding their content, and the published built-Gateway A/B receipt demonstrates the matching failure; this read-only review executed no target code. Is this the best way to solve the issue? The patch repairs the existing accounting owner using the parser's semantic classification, preserves retained-text charging, and introduces no competing parser, setting, or state owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c3904c683d2d. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +23, Tests +87, Docs +3. Total +113 across 4 files. Added test files: 1. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 Reviewed October 26, 2026, 3:48 AM ET / 07:48 UTC. |
|
Landed in d1470c8. This carries @jaxonparrott's fix from #168661 (fork archived), with co-author credit. Thanks! |
…output (openclaw#184352) fix(agents): keep Claude CLI parent replies after large subagent output With native Agent orchestration enabled for the Claude CLI backend, large forwarded subagent records were charged against the parent's output budget even when they were discarded, so the budget ran out and the parent's answer was lost. Only child records that are actually kept now count against the budget. Evidence: real Claude CLI 2.1.310 through built Gateways, using the shipped `plugins.entries.anthropic.config.managedNativeTools.default: ["Agent"]` opt-in and a local Messages fixture whose subagent emits about 13 MB of records. On main the parent ran out of output budget and its answer was lost (twice); with this change the parent answer was delivered (twice). Small-record turns work on both refs, and retained-text and huge-line cases are still rejected. Details: openclaw#184352 (comment). Repairs openclaw#168661 by @jaxonparrott, whose fork is archived. Co-authored-by: Jaxon Parrott <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…output (#184352) fix(agents): keep Claude CLI parent replies after large subagent output With native Agent orchestration enabled for the Claude CLI backend, large forwarded subagent records were charged against the parent's output budget even when they were discarded, so the budget ran out and the parent's answer was lost. Only child records that are actually kept now count against the budget. Evidence: real Claude CLI 2.1.310 through built Gateways, using the shipped `plugins.entries.anthropic.config.managedNativeTools.default: ["Agent"]` opt-in and a local Messages fixture whose subagent emits about 13 MB of records. On main the parent ran out of output budget and its answer was lost (twice); with this change the parent answer was delivered (twice). Small-record turns work on both refs, and retained-text and huge-line cases are still rejected. Details: #184352 (comment). Repairs #168661 by @jaxonparrott, whose fork is archived. Co-authored-by: Jaxon Parrott <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]> Adaptation: Adapt central retained-output charging into B parser and existing media/partial normalizers. Keep all line, frame, retained-delta and mixed-item caps; additionally reject oversized raw attribution before discounting. Preserve B partial metadata behavior without importing 72c9a55. Source-commit: d1470c8 Co-authored-by: RomneyDa <[email protected]>
…eadcode after backports (#187570) * refactor: keep Teams allowlist sentinel private (#185484) The Microsoft Teams fail-closed allowlist sentinel now remains module-private while preserving its exact restrictive projection and lifecycle coverage. (cherry picked from commit 59b1ddd) * test: teach the live-wrapper fake Bun to answer --revision Partial cherry-pick of the test/scripts/test-live.test.ts hunk only. #173807 (backported as e72f868) made the CI Bun --revision probe mandatory; the fake Bun fixture must answer it from the checkout pin. (cherry picked from commit 08dd80a) * test(ci): expect watchdog exit 124 from wedged run-tsgo #184639 (backported as d9a91b5) intentionally changed the run-tsgo watchdog exit from 1 to 124 so CI collectors stop admitting work. Main realigned this case in run-tsgo-worktree.test.ts (9b14a38); on the release branch the same watchdog case lives in run-tsgo.test.ts and was not realigned by the backport. * test(vitest): keep gateway database-worker routes in canonical order The beta.5 adaptation of #178415 (23a2bcd) prepended three integration proofs to gatewayDatabaseWorkerTestFiles. Canonical project ownership compares that list against sorted discovery, so the out-of-order entries failed vitest-cli-ownership. Move them to their sorted positions; routing membership is unchanged. * refactor: keep Slack reconnect policy private (#181690) Keeps Slack reconnect policy details module-private while preserving the exact invalid-auth cutoff, reset, and blocked-status behavior. (cherry picked from commit cd65901) * fix: keep retired Telegram throttler release private Telegram hunk of 09f9ec8 (#183086) only. The release-only test called the private helper directly; its surviving-alias case is already asserted through releaseRemovedTelegramAccountThrottler, so drop the duplicate direct call. (cherry picked from commit 09f9ec8, partial) * refactor: keep Claude partial-message measurement private src/agents/cli-output-stream-limits.ts hunk of 28e2774 (#184686) only; the backport of #184352 left this export without a consumer. (cherry picked from commit 28e2774, partial) * refactor: keep managed plugin cache selector private src/plugins/management-catalog.ts hunk of 2c0c30b (#185269) only; the backport of #184921 left this export without a consumer. (cherry picked from commit 2c0c30b, partial) * refactor(agents): keep requester settle batch callbacks type private The backport of #181260 (2f7589a) moved RequesterSettleWakeParams into the state module, leaving RequesterSettleWakeBatchCallbacks exported only for a test fixture. Main keeps it module-private; type the fixture through RequesterSettleWakeParams instead. * refactor(infra): drop unconsumed streaming UTF-8 decoder The minimal backport of #180861 (8d3183d) added decodeUtf8Chunks as a prerequisite, but its main consumers (streaming state-migration importers) were intentionally not backported, so production Knip flags it. Remove the export and its unit case; decodeUtf8Input is unchanged. * refactor(scripts): keep pinned Bun CI detection private The minimal #172625 backport (e6c3639) deferred the dev-tool, test-runtime and run-format callers that consume isCiEnvironment on main, so the export has no consumer on the release branch. * test(update): drop orphaned recovery version-mismatch fixture The #185692 backport in 39f9bde removed the last consumer of recoveryVersionMismatch from update-cli.plugin-convergence.test.ts. Main removed the same fixture in eae9bc4 (#181717). * test(gateway): type config removal mocks through inline module imports The release adaptation of #152052 (41aa7a6, de41770) typed its partial mocks through type-only namespace imports. Knip treats the secrets runtime namespace as the only consumer of its exports, so the full-tree scan reported prepareSecretsRuntimeSnapshotRestore and SecretResolverWarning as unused. Use main's inline typeof import() form. * refactor(shared): drop unconsumed async-store helper The backport of #179213 (6d9852d, plus f3fb0e9 registering it as a wrapper component) took the runWithAsyncStore helper and its test without the plugin-instance-invocation consumer, leaving src/shared/async-store.ts unused in production. Remove the helper, its test and its wrapper-components entry rather than complete a perf change during beta stabilization. * chore(knip): model backported perf scripts and Telegram worker fixture Mirror main's Knip entries for files added by beta.5 backports: - scripts/perf/{node-event-session-source-measure.mjs, stream-dispatch-scope-measure.ts,system-prompt-report-retention.ts} as path-invoked script roots (#183931, #183552, #183010); - the Telegram ingress context Worker fixture loaded by URL (#178909) in production ignoreFiles. Also register scripts/test-security-mail-parser.mjs, the standalone nodemailer sender-parsing regression added by #187301 (release-only). * refactor(doctor): keep dashboard migration guard at the repair boundary Release adaptation of 50b532d (#183153). The backport of #182345 (51f63cb) exported isUnstampedDashboardRoot only for its unit test. Main made it private and drove the eligibility cases through repairLegacyDashboardChatTypes using a canonical-repair fixture this branch does not carry. Keep every accepted and rejected row case, now asserted through the repair boundary with the branch's session accessor. * test(agents): hold requester preparation for the settle capacity case after #181260 backport Backport 2f7589a (#181260) filters delivered child findings from settle wakes (needsRequesterSettleFindings), so this delivered-row case no longer reads the child transcript where it injected worker capacity and failed with 'expected findTranscriptEvent to be called'. Main realigned the same case in 411b2e6 (#178104): inject capacity at captureRequesterSessionEntryCurrent and assert the delivered result is not repeated in the resumed wake. Apply that realignment; the 'Already delivered child results' wording that main also asserts belongs to #178104's message change, which this branch does not carry. (adapted from commit 411b2e6) --------- Co-authored-by: Shakker <[email protected]>
…budget Narrow this change to the behaviour main does not already have. Upstream openclaw#184352 already charges a forwarded child message record a flat 64-char allowance in `measureClaudeSubagentRecord`, and upstream keeps charging such a record a frame on purpose, so a 20,001-record child flood still stops the parent's parse. Exempting those frames (and discounting their characters a second time) contradicted that policy. - drop the raw-line `isClaudeSubagentJsonlLine` scan and the budget's `chargeable` gate; every Claude line now goes through main's `chargeClaudeStreamJsonLine` unchanged, forwarded records included. - keep the `parseClaudeCliStreamingDelta` child-attribution guard: child stream-event text stays out of the parent reply, but is still charged in full, which is what main's cli-output-subagent-budget.test.ts:68 pins. What remains in this branch is recovery of a finished turn past a spent budget, the retention bounds that recovery requires, and the child-text leak fix.
…'s policy The branch's own suite asserted the exemption this PR no longer makes. - cli-output-stream-budget.test.ts: 'does not charge forwarded subagent traffic against the parent line budget' -> 'charges ...', and the flood is now pinned as recovered-with-truncation rather than uncharged; 'does not charge ... against the parent character budget' -> 'charges ... a fixed allowance, not their wire length', which is upstream openclaw#184352's behaviour and the only char relief this branch relies on; 'neither charges nor retains forwarded subagent partial-message deltas' -> 'charges but does not retain ...', matching main's cli-output-subagent-budget.test.ts:68. - scripts/proof-cli-stream-turn-budget.ts: scenario 6 'subagent-exempt' -> 'subagent-frame-bound'. It now proves the frame odometer stops the flood, that it does so past the character budget (so the per-record allowance is in force), that the turn is still recovered, and that attributed progress keeps flowing on both sides of exhaustion. - drop cli-output-jsonl-scan.test.ts with its module; retitle the surviving nested-attribution case, which no longer guards a raw-line exemption but still guards against a substring shortcut. No test that exists on origin/main was edited or deleted.
Repairs #168661 (fork archived).
Parent-lane records, partial-message deltas (#153545) and media omission keep their existing accounting. This is the same class as #150132 and #159929: bytes OpenClaw never keeps trip the guard.
What Problem This Solves
Large forwarded Claude Code subagent records can exhaust OpenClaw's 8 MiB CLI output budget even though their message payloads are discarded, preventing delivery of the parent answer.
User Impact
Forwarded child assistant messages and tool-result messages that the parser discards receive a bounded fixed charge for their progress identifier. Child attribution alone does not earn a discount: retained child-attributed stream-event text still consumes its full payload budget. Parent output, individual raw-line limits, frame limits, partial-message accounting, and media normalization retain their existing limits.
Why This Change Was Made
The streaming accounting owner now reuses the parser's semantic subagent-progress classification and restricts the discount to discarded message kinds. The repair closes the contributor revision's counterexample: two child-attributed text deltas of 4,300,000 characters each must exceed the retained-output budget, not cost only 128 characters. The helper stays private to the accounting owner.
Original fix by @jaxonparrott; the contributor commit remains in history. Current main was integrated because the native runtime and its shipped managed-native-tool configuration materially changed since the contributor revision.
Evidence
Published native-runtime verification receipt: #184352 (comment).
Linux Docker, Node 24.22.1, real Claude Code CLI 2.1.310, built Gateway and ordinary remote
agent --jsonturns. The native CLI uses a deterministic local Anthropic Messages fixture and the documentedOPENCLAW_LIVE_CLI_BACKEND_PRESERVE_ENVroute with synthetic credentials only.The proof uses the shipped opt-in from #183765 (
3eeb12bea80b482a8068d1cf27870a5e12be5bda):plugins.entries.anthropic.config.managedNativeTools.default: ["Agent"]. It does not inject native tools or change execution arguments. The child uses the same policy-filteredmcp__openclaw__readtool as its parent. A transparent recorder preserves the actual native JSONL; the Messages fixture drives the real native Agent tool and hundreds of real reads of synthetic files.92233fdddef26465e8701531620b69ff48c3124d, twice1d37983b99beb91bb78e29bc09c7cd8c08569c98, twicePARENT_ANSWER_INTACTdeliveredCandidate large native captures contain about 10.7 MB of actual JSONL, including about 10.3 MB of discarded child assistant/user records, followed by the real native success result and intact parent answer. Main captures stop around 8.7 MB with the 8,388,608-character budget error. These are real native-runtime Gateway turns, not a fake CLI executable or parser-only proof.
The tested tree was committed at
1c5d129b113271c810f46fad7e2271630c0b6cd8; the final head only adds verified contributor credit to that commit's metadata, with no source change.At the same registered native-runtime stream boundary, two separate fault controls replayed crafted records immediately before the real CLI's terminal result: two child-attributed text deltas of 4,300,000 characters each, and one 9,000,000-character child tool-result line. Candidate Gateway turns rejected both with exit 1 and the existing output/line budget error. Only these negative controls alter stdout; the eight primary native-runtime turns above used unmodified native records and unchanged argv. These controls do not claim Claude currently emits those crafted shapes.
Supporting regression: the new retained-child-delta test fails on the contributor's original accounting because no budget error is raised. The repaired integrated candidate passes all 80 focused stream, framing, partial-message, and subagent-budget tests. Both built artifacts completed; touched-file formatting and lint passed. Independent review of the integrated patch found no actionable P0–P2 findings.
The full diff against the integrated merge base is production +40/-17, tests +87/-0, docs +5/-2. Necessary production growth is confined to discarded-record accounting in the existing owner; no new resource limit, configuration option, or authority policy is introduced.
Merge Danger
Two-way door: reverting restores prior output charging; no state migration is involved. Blast radius is Claude stream-JSON output accounting. The main risk is undercharging retained data, protected by the retained-child, parent-budget, line-size, frame-count and partial-message controls.