Skip to content

fix(agents): bound escaped output for the third child-result call site - #124171

Merged
steipete merged 2 commits into
openclaw:mainfrom
masatohoshino:fix/subagent-child-result-escape-budget
Aug 24, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
masatohoshino:fix/subagent-child-result-escape-budget

Conversation

@masatohoshino

@masatohoshino masatohoshino commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where a subagent's completion result containing many </>
characters (e.g. code, XML, or HTML output — no adversarial input required)
could produce a "Child result" prompt block up to ~4x the intended 512-char
budget when surfaced to the parent agent via formatChildResultData
(src/agents/subagents/announce/subagent-announce-output.ts).

Why This Change Was Made

wrapPromptDataBlock (src/agents/sanitize-for-prompt.ts) delegates to its
internal wrapPromptDataBlockWithTag, which truncates text to maxChars
before escaping </> to &lt;/&gt;, then only enforces a second,
post-escape bound (maxEscapedChars) when the caller supplies it. Of the
three call sites that use wrapPromptDataBlock for "Child result"/"Subagent
result" data
(src/agents/agent-steering-queue.ts, src/agents/internal-events.ts,
src/agents/subagents/announce/subagent-announce-output.ts), the first two
already pass both params — added by
#119731
("fix(agents): bound task-completion result prompts", merged
2026-08-12), which established this exact pattern and its own test
coverage (src/agents/agent-steering-queue.test.ts,
src/agents/internal-events.test.ts) for
the same expansion. The third (formatChildResultData) was the only site
still missing them.

The Fix

This PR fixes the missing bound by adding maxEscapedChars and
truncationMarker to the wrapPromptDataBlock call inside
formatChildResultData, reusing the same MAX_CHILD_COMPLETION_RESULT_CHARS
/ CHILD_RESULT_TRUNCATION_NOTICE constants the function already declares
for its pre-escape truncation — matching the exact param shape #119731
applied to the other two call sites of the same helper (production-code
diff: +2/-0 in one file; test-file diff is separate, see Evidence).

Non-Scope

  • agent-steering-queue.ts / internal-events.ts — already fixed by fix(agents): bound task-completion result prompts #119731
  • wrapPromptDataBlockWithTag itself (src/agents/sanitize-for-prompt.ts) —
    its contract is correct and unchanged
  • The pre-escape truncation call to truncateUtf16Safe inside
    formatChildResultData — unrelated to the escape-budget defect, left as-is
    (only the two new wrapPromptDataBlock params are added)
  • CHANGELOG.md

User Impact

Subagent completion results embedded in a parent prompt now stay within
their declared context budget even when the child's output is dense in
angle brackets, matching the guarantee #119731 already gives the other two
call sites of the same helper. No behavior change for output whose escaped
form already stays under the 512-char budget; output with enough </>
characters to have exceeded that budget after escaping is now truncated with
a visible marker instead of being passed through oversized.

Evidence

Real behavior proof

Behavior addressed: formatChildResultData embedding a child result whose
text is dense in < characters (e.g. `${"<".repeat(6_000)}-tail`) into
the parent-visible "Child result" prompt block.

Real environment tested: Linux x86_64, node v24.18.0, patch at commit
163f511b120c318c569b26ea6859933ad3dfb1ea (current PR head).

Exact steps or command run after this patch:

# The harness (docs/work-items/subagent-child-result-escape-budget/proof/harness.mjs)
# drives this production module directly with two scenarios — an
# angle-bracket-dense child result and a plain-text control — which is what
# the capture's stderr shows it importing on each side:
#   src/agents/subagents/announce/subagent-announce-output.ts
clawproof work start subagent-child-result-escape-budget --baseline 8d5a54deaa158b39a7ec4168c88935963d6bc201
git -C ~/.clawproof/work-items/subagent-child-result-escape-budget/after reset --hard 4fec3eadd12bd9834953eddb3911d7aa8c59086b
clawproof build plan subagent-child-result-escape-budget --worktree before --apply
clawproof build plan subagent-child-result-escape-budget --worktree after --apply
clawproof prove subagent-child-result-escape-budget --scenario default --final --problem-file docs/work-items/subagent-child-result-escape-budget/proof/problem.md
ocw proof import subagent-child-result-escape-budget

Before (pre-fix):

===== BEFORE (baseline 8d5a54deaa15, unfixed source) =====
--- harness.stderr ---
[harness: importing [REDACTED:path]/before/src/agents/subagents/announce/subagent-announce-output.ts]
[harness: running angle-dense-child-result]
[harness: running plain-text-child-result-control]
--- harness.stdout ---
{
  "moduleUnderTest": "src/agents/subagents/announce/subagent-announce-output.ts",
  "results": [
    {
      "case": "angle-dense-child-result",
      "blockLength": 1973,
      "endsWithTruncationMarker": true,
      "containsResultText": false,
      "error": null
    },
    {
      "case": "plain-text-child-result-control",
      "blockLength": 33,
      "endsWithTruncationMarker": false,
      "containsResultText": true,
      "error": null
    }
  ]
}

Evidence after fix:

===== AFTER (candidate 4fec3eadd12b, fix applied) =====
--- harness.stderr ---
[harness: importing [REDACTED:path]/after/src/agents/subagents/announce/subagent-announce-output.ts]
[harness: running angle-dense-child-result]
[harness: running plain-text-child-result-control]
--- harness.stdout ---
{
  "moduleUnderTest": "src/agents/subagents/announce/subagent-announce-output.ts",
  "results": [
    {
      "case": "angle-dense-child-result",
      "blockLength": 509,
      "endsWithTruncationMarker": true,
      "containsResultText": false,
      "error": null
    },
    {
      "case": "plain-text-child-result-control",
      "blockLength": 33,
      "endsWithTruncationMarker": false,
      "containsResultText": true,
      "error": null
    }
  ]
}

Observed result after fix: blockLength is the length of the full escaped
<prompt-data>...</prompt-data> block (escaped content plus truncation
marker, if any) for the per-child 512-char budget — separate from the
unrelated 4096-char aggregate budget across all children, discussed below.
The angle-dense case's blockLength drops from 1973 to 509 and ends with
the truncation marker before and after — pre-fix, only the earlier
maxChars: 512 pre-escape truncation was active, and escaping then
re-expanded that already-truncated text past 512; post-fix, the added
maxEscapedChars: 512 re-truncates the escaped output itself to the same
512-char budget. The plain-text control case is unchanged (33 chars, no
marker, both sides), confirming the fix is scoped to the escape-expansion
defect and does not alter normal output.

What was not tested: this harness drives buildChildCompletionFindings
directly (the only caller of formatChildResultData), not a live gateway
session end-to-end. The separate 4096-char aggregate budget across
multiple children (MAX_CHILD_COMPLETION_FINDINGS_CHARS) is covered
instead by
src/agents/subagents/announce/subagent-announce-output.test.ts's
buildChildCompletionFindings describe block, whose invariant is that an
actionable (failed) child's finding is always retained even when successes
must be dropped to fit the budget. Two of its pre-existing tests exercising
that invariant (retains a later actionable failure when earlier children exceed the remaining budget, prioritizes an oversized failed completion over a competing oversized success) needed their oversized-child counts
increased — not their assertions weakened — because bounding the per-item
escape budget changed how many oversized children now fit inside the
aggregate cap (empirically measured: it now takes 6-7 oversized children to
reach the cap, not 1-2). Both were re-verified to fail against pre-fix
source for the same reason before the fix was restored.

Focused tests

node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-support.config.ts src/agents/subagents/announce/subagent-announce-output.test.ts

46 passed (46) in
src/agents/subagents/announce/subagent-announce-output.test.ts, including
one new regression test (bounds a single child result's escaped output with a visible marker) that fails against pre-fix source for the intended
reason.

Precheck

ocw review precheck subagent-child-result-escape-budget — PASS (codex
review: 0 findings).

…site

formatChildResultData was the last of three identical Child result/Subagent result wrapPromptDataBlock call sites without maxEscapedChars/truncationMarker. wrapPromptDataBlockWithTag truncates to maxChars before escaping <>, so an angle-bracket-dense child result (code/XML/HTML output) could still expand the escaped block up to ~4x the intended 512-char budget. Bring this site in line with the other two, already fixed by carrier PR openclaw#119731 (agent-steering-queue.ts, internal-events.ts).
@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Aug 15, 2026
@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 24, 2026, 2:02 AM ET / 06:02 UTC.

ClawSweeper review

What this changes

This PR moves child-result truncation into the shared prompt sanitizer’s escaped-output budget and adds regression coverage for angle-bracket-heavy and control-character-prefixed subagent output.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 3 items remain

The patch is correct and follows the canonical escaped-budget pattern, but its terminal proof names an earlier head while the current head also changes sanitization/truncation order; refresh after-fix proof on the current head before merge.

Priority: P2
Reviewed head: 04b6d93c5573d533997cffd427d5fdb18fb09cb7

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The implementation and focused regressions are sound, but the available real-behavior transcript does not verify the current head.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The supplied terminal before/after proof is credible for the original escaped-bound change, but it names 163f511 rather than current head 04b6d93, whose sanitization-order change also needs after-fix evidence; redact private details in the refreshed capture. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The supplied terminal before/after proof is credible for the original escaped-bound change, but it names 163f511 rather than current head 04b6d93, whose sanitization-order change also needs after-fix evidence; redact private details in the refreshed capture. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current-main defect: Current main manually truncates raw child text, then calls the sanitizer with only maxChars; the sanitizer escapes angle brackets afterward, so escaped content can exceed the intended per-child budget.
Canonical sanitizer contract: The shared sanitizer sanitizes before truncation/escaping and applies maxEscapedChars with the supplied marker, making it the correct owner for the escaped budget.
Sibling implementation: Current main already gives the internal-event child-result projection the same maxEscapedChars and truncationMarker shape used by this PR.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-support.config.ts src/agents/subagents/announce/subagent-announce-output.test.ts --reporter=verbose -t "bounds a single child result's escaped output with a visible marker"

Result: PASS (completed)

node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-support.config.ts src/agents/subagents/announce/subagent-announce-output.test.ts --reporter=v
erbose -t "bounds a single child result's escaped output with a visible marker"
runner@runnervm76f27:/tmp/clawsweeper-live-proof-124171-LcnAWQ/target$ node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-support.config.ts src/
agents/subagents/announce/subagent-announce-output.test.ts --reporter=verbose -t "bounds a single child result's escaped output with a visible marker"

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-124171-LcnAWQ/target

node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-support.config.ts src/agents/subagents/announce/subagent-announce-output.test.ts --reporter=v
erbose -t "bounds a single child result's escaped output with a visible marker"
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › dedupeLatestChildCompletionRows › prefers the newer generation when child r
uns share a creation timestamp
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › buildCompactAnnounceStatsLine › rolls one-decimal thousand token stats over
 to the million unit
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › does not treat a sessions_yield wait turn as subagent
completion output
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › does not expose a 'OpenAI top-level snake_case functio
n …' yield turn as completion output
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › does not expose a 'top-level camelCase tool call' yiel
d turn as completion output
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › does not expose a 'nested content function call' yield
 turn as completion output
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › does not synthesize output from provider-specific tool
Use transcript blocks
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › does not synthesize output from provider-specific func
tionCall transcript blocks
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › does not synthesize output from provider-specific func
tion_call transcript blocks
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › summarizes provider-specific toolUse transcript blocks
 after a timeout
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › summarizes provider-specific functionCall transcript b
locks after a timeout
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › summarizes provider-specific function_call transcript
blocks after a timeout
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › summarizes top-level toolCalls after a timeout
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › summarizes top-level tool_calls after a timeout
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › keeps an intentional silent reply ahead of timeout too
l progress
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › returns final assistant output that arrives after a se
ssions_yield wait turn
 ↓  agents-support  src/agents/subagents/announce/subagent-announce-output.test.ts › readSubagentOutput › does not reuse assistant progress that issued a traili
ng tool call
 ↓  agents-support  src/agents/subagents/announce
… output truncated …

Assertions:

  • PASS expect_output: bounds a single child result's escaped output with a visible marker

How this fits together

Subagent completion text is formatted into a prompt-data block for the parent agent. The shared sanitizer removes unsafe controls, escapes angle brackets, and bounds the resulting model-visible text before the parent prompt is assembled.

flowchart LR
  A[Subagent completion] --> B[Child-result formatter]
  B --> C[Prompt sanitizer]
  C --> D[Escaped-output budget]
  D --> E[Parent-agent prompt]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The supplied terminal before/after proof is credible for the original escaped-bound change, but it names 163f511 rather than current head 04b6d93, whose sanitization-order change also needs after-fix evidence; redact private details in the refreshed capture. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The PR body’s before/after terminal transcript identifies 163f511 as the current head, but the actual head is 04b6d93 and additionally removes raw pre-truncation; current-head proof should cover both angle-dense text and a control-character prefix.
  • Complete next step (P2) - No mechanical repair is needed; the remaining merge blocker is refreshed real-behavior evidence for the current head.
Agent review details

Security

None.

PR surface

Source -7, Tests +32. Total +25 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 10 -7
Tests 1 52 20 +32
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 55 30 +25

Review metrics

Metric Value Why it matters
Production vs test delta production -7, tests +32 The bug fix removes duplicate raw truncation in favor of the shared sanitizer; added tests cover the escaped-budget regression and retain aggregate-budget behavior.

Root-cause cluster

Relationship: canonical
Canonical: #124171
Summary: This PR addresses the remaining child-result formatter omitted from the escaped-output hardening pattern.

Members:

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the sanitizer-owned escaped cap and publish a redacted current-head terminal capture demonstrating both the escaped-output bound and preservation of useful text after unsafe controls are removed.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the sanitizer-owned escaped cap and publish a redacted current-head terminal capture demonstrating both the escaped-output bound and preservation of useful text after unsafe controls are removed.

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

Yes—source establishes a focused path: feed angle-bracket-dense completion text through buildChildCompletionFindings on current main, where raw truncation precedes escaping and can exceed the 512-character escaped budget.

Is this the best way to solve the issue?

Yes—the shared sanitizer is the narrowest owner because it sanitizes before calculating the escaped budget, matching the current sibling child-result projection.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against c43166a9208c.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The supplied terminal before/after proof is credible for the original escaped-bound change, but it names 163f511 rather than current head 04b6d93, whose sanitization-order change also needs after-fix evidence; redact private details in the refreshed capture. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • remove proof: sufficient: Current real behavior proof status is insufficient, not sufficient.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P2: This is a bounded prompt-context regression in subagent completion output with limited blast radius.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The supplied terminal before/after proof is credible for the original escaped-bound change, but it names 163f511 rather than current head 04b6d93, whose sanitization-order change also needs after-fix evidence; redact private details in the refreshed capture. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the current-head sanitizer-bound implementation and the recent current-main child-completion maintenance commit. (role: recent area contributor; confidence: high; commits: 04b6d93c5573, 611b3f17533b; files: src/agents/subagents/announce/subagent-announce-output.ts, src/agents/sanitize-for-prompt.ts)
  • clawsweeper[bot]: Its merged related PR established the escaped-budget pattern already used by the internal-event and steering projections. (role: introduced sibling implementation; confidence: medium; commits: 0f5984f4e11b; files: src/agents/internal-events.ts, src/agents/agent-steering-queue.ts)

Rank-up moves

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

  • Re-run the direct production-module harness on 04b6d93 and publish redacted before/after output for angle-dense text and a control-character-prefixed useful result.

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 (4 earlier review cycles)
  • reviewed 2026-08-15T12:42:41.611Z sha 163f511 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-15T12:59:20.469Z sha 163f511 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-21T23:47:36.857Z sha 163f511 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-22T00:30:39.391Z sha 163f511 :: needs maintainer review before merge. :: none

@masatohoshino
masatohoshino marked this pull request as ready for review August 15, 2026 12:52
Preserve contributor ancestry and current subagent completion behavior while delegating escaped child-result budgets to the canonical prompt sanitizer. Remove the obsolete raw pre-truncation so sanitized control characters cannot discard useful completion text.

Co-authored-by: masatohoshino <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed 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. labels Aug 24, 2026
@steipete

Copy link
Copy Markdown
Contributor

Maintainer verification for exact head 04b6d93c5573d533997cffd427d5fdb18fb09cb7:

The root cause was producer-side truncation before prompt sanitization and HTML escaping. The current owner now delegates directly to the shared sanitizer, removing the obsolete raw truncation and enforcing the existing 512-character escaped budget with a visible marker. Production delta: +3/-10 (net -7); both sibling projections already use the same contract.

Direct imports of the actual current-main and exact-head buildChildCompletionFindings production modules, with real completion rows:

{
  "before": {
    "head": "b0d6fff9f951bf709e37bae396628446f01cb2cd",
    "angleDense": { "escapedChars": 1973, "within512": false, "visibleMarker": true },
    "removableControlPrefix": { "preservesUsefulResult": false, "falselyTruncated": true },
    "ordinaryResultPreserved": true,
    "aggregate": { "chars": 2382, "within4096": true, "preservesActionableFailure": true }
  },
  "after": {
    "head": "04b6d93c5573d533997cffd427d5fdb18fb09cb7",
    "angleDense": { "escapedChars": 509, "within512": true, "visibleMarker": true },
    "removableControlPrefix": { "preservesUsefulResult": true, "falselyTruncated": false },
    "ordinaryResultPreserved": true,
    "aggregate": { "chars": 4087, "within4096": true, "preservesActionableFailure": true }
  }
}

The new 700-control-character regression also failed against pre-fix production code for the intended reason (the real completion text disappeared), then passed after the canonical owner repair.

node scripts/run-vitest.mjs \
  src/agents/subagents/announce/subagent-announce-output.test.ts \
  src/agents/sanitize-for-prompt.test.ts \
  src/agents/internal-events.test.ts \
  src/agents/agent-steering-queue.test.ts

4 files passed; 92 tests passed

Coverage includes angle-heavy escaping, UTF-16/entity integrity, control-first sanitization, the 4,096-character aggregate, actionable-failure priority, ordinary output, both sibling projections, and the current pending-error timeout behavior from #125357. Focused formatting, fresh isolated structured review, independent review, and native READY FOR /prepare-pr artifacts are clean. Exact-head hosted CI: run 32695278079; Workflow Sanity: run 32695278158.

This directly addresses the latest ClawSweeper rank-up move with current-head evidence for both escaped output and removable control prefixes.

@steipete
steipete merged commit 60613b7 into openclaw:main Aug 24, 2026
257 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 25, 2026
…site (openclaw#124171)

formatChildResultData was the last of three identical Child result/Subagent result wrapPromptDataBlock call sites without maxEscapedChars/truncationMarker. wrapPromptDataBlockWithTag truncates to maxChars before escaping <>, so an angle-bracket-dense child result (code/XML/HTML output) could still expand the escaped block up to ~4x the intended 512-char budget. Bring this site in line with the other two, already fixed by carrier PR openclaw#119731 (agent-steering-queue.ts, internal-events.ts).

Co-authored-by: Peter Steinberger <[email protected]>
obviyus added a commit that referenced this pull request Sep 15, 2026
…49223)

Most added lines cover regressions and move formatting beside exact-run reads; archived histories now stream through the existing storage worker.

## What Problem This Solves

Completed child answers could lose required fields before their parent read them. Closes #138555. Reported by @aleps001.

## Why This Change Was Made

The parent receives the complete visible final answer from the selected child run, including its registered deletion archive. Descendant results remain input to the child's synthesis. A persisted final message-tool reply remains authoritative after a later same-run `NO_REPLY`.

The shared 4,096-character terminal snapshot stays bounded for lifecycle and durable evidence. This state has one writer. Stored shapes, retention, and cleanup ownership are unchanged. Complete answers use more parent context. The owner's September 15 decision replaces projection limits from #119731 and #124171 while preserving escaping, metadata limits, stable order, and whole-item queue delivery.

## User Impact

Waiting and returning parents receive complete answers while the exact-run transcript remains retained. If archive pruning has removed it, that completion uses its capped published result with a `truncated-by-retention` marker. Healthy siblings and the parent continue. Public and private nested children forward their own conclusions. Large archived histories no longer require one decoded string on the Gateway thread.

## Evidence

An 8,638-character answer lost its required tail on the baseline. Served Chat now delivers all 11,758 escaped characters to the resumed parent and retains them after child deletion. A public nested case delivers the middle child's distinct conclusion. Earlier aggregate, nested-yield, and ordinary completion captures also pass.

The registered `maybeWakeRequesterAfterAllChildrenSettled` regression uses capped visible terminal evidence and a complete >4,096-character exact-run transcript with a trailing same-run `NO_REPLY` row. It fails on the original implementation and passes here. The producer contract is covered by [run-entry-terminal.ts](https://github.com/openclaw/openclaw/blob/a97d75a928ed8f5a9f70ee7977da8e767d03acea/src/agents/embedded-agent-runner/run-entry-terminal.ts#L153) and [run-entry.test.ts:928–931](https://github.com/openclaw/openclaw/blob/a97d75a928ed8f5a9f70ee7977da8e767d03acea/src/agents/embedded-agent-runner/run-entry.test.ts#L928). Native children cannot call `message` under the existing hard deny, so that live cell is excluded.

A returning parent can receive a kept child’s answer and then continue after that child starts a valid follow-up. The registered tool-result continuation fails on `a97d75a9` and passes here. Initial source rejection, parent cancellation, and pre-prompt compaction remain covered.

The registered `attempt-prompt-submit.retention.test.ts` regression publishes and prunes a child archive, then consumes deferred results through the real parent session (`node scripts/run-vitest.mjs run src/agents/embedded-agent-runner/run/attempt-prompt-submit.retention.test.ts`). It fails before the correction and passes with the marked retained result, the healthy sibling’s complete answer, cleared delivery leases, and a successful next parent turn.

[Scenario and captures](https://gist.github.com/obviyus/cce960c04dafd949c21141686af3696e).

| Before | After |
| --- | --- |
| ![Missing field](https://gist.githubusercontent.com/obviyus/cce960c04dafd949c21141686af3696e/raw/e8b97302964ad1bd874c7b4f578c30a72593610a/before.png) | ![Complete field](https://gist.githubusercontent.com/obviyus/cce960c04dafd949c21141686af3696e/raw/e8b97302964ad1bd874c7b4f578c30a72593610a/after.png) |

## Compatibility

No public API, schema, retention, or retrieval feature changes. Archive hash, header, session, and owner checks remain. The existing worker scans a 536.9 MB decoded archive whose previous whole-string decoder failed.

## Consumers

Requester settlement, deferred turns, nested announcements, event projections, and retained parent history use the complete result, or the marked retained snapshot when its exact answer is unavailable.

## Invalidation

Run, producer, generation, batch, requester, and lease authority are rechecked after reads and before delivery. Failed prompt assembly releases its lease. Deferred source validation ends after the first foreground stream is acquired; parent abort checks remain active.

## Tests

The retained complete-result proof covers 374 tests across 15 files, including the format suite. The retained owner and sibling proof covers 379 passing tests across 17 files on a fresh merge with main, including the format and retention regressions. Four additional consumer suites update their explicit session-accessor mocks for the exact-run reader; their 286 tests pass on a fresh merge with main, with behavior assertions unchanged. Registered settlement, deferred-input, and continuation regressions fail on their original source. Type-aware preflight, structural checks, and test registration pass.

Production growth is 422 lines: result +241; output −130; queue +27; registry API +8; prompt build/phase/submit +6/+1/+16; wake/message −44/+54; announce +13; events −16; archive read/session/types/dispatch/worker/history +183/+6/+14/+20/+9/+11; history export +3. Growth accepted under the owner's standing acceptance (2026-09-15).

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
…enclaw#149223)

Most added lines cover regressions and move formatting beside exact-run reads; archived histories now stream through the existing storage worker.

## What Problem This Solves

Completed child answers could lose required fields before their parent read them. Closes openclaw#138555. Reported by @aleps001.

## Why This Change Was Made

The parent receives the complete visible final answer from the selected child run, including its registered deletion archive. Descendant results remain input to the child's synthesis. A persisted final message-tool reply remains authoritative after a later same-run `NO_REPLY`.

The shared 4,096-character terminal snapshot stays bounded for lifecycle and durable evidence. This state has one writer. Stored shapes, retention, and cleanup ownership are unchanged. Complete answers use more parent context. The owner's September 15 decision replaces projection limits from openclaw#119731 and openclaw#124171 while preserving escaping, metadata limits, stable order, and whole-item queue delivery.

## User Impact

Waiting and returning parents receive complete answers while the exact-run transcript remains retained. If archive pruning has removed it, that completion uses its capped published result with a `truncated-by-retention` marker. Healthy siblings and the parent continue. Public and private nested children forward their own conclusions. Large archived histories no longer require one decoded string on the Gateway thread.

## Evidence

An 8,638-character answer lost its required tail on the baseline. Served Chat now delivers all 11,758 escaped characters to the resumed parent and retains them after child deletion. A public nested case delivers the middle child's distinct conclusion. Earlier aggregate, nested-yield, and ordinary completion captures also pass.

The registered `maybeWakeRequesterAfterAllChildrenSettled` regression uses capped visible terminal evidence and a complete >4,096-character exact-run transcript with a trailing same-run `NO_REPLY` row. It fails on the original implementation and passes here. The producer contract is covered by [run-entry-terminal.ts](https://github.com/openclaw/openclaw/blob/a97d75a928ed8f5a9f70ee7977da8e767d03acea/src/agents/embedded-agent-runner/run-entry-terminal.ts#L153) and [run-entry.test.ts:928–931](https://github.com/openclaw/openclaw/blob/a97d75a928ed8f5a9f70ee7977da8e767d03acea/src/agents/embedded-agent-runner/run-entry.test.ts#L928). Native children cannot call `message` under the existing hard deny, so that live cell is excluded.

A returning parent can receive a kept child’s answer and then continue after that child starts a valid follow-up. The registered tool-result continuation fails on `a97d75a9` and passes here. Initial source rejection, parent cancellation, and pre-prompt compaction remain covered.

The registered `attempt-prompt-submit.retention.test.ts` regression publishes and prunes a child archive, then consumes deferred results through the real parent session (`node scripts/run-vitest.mjs run src/agents/embedded-agent-runner/run/attempt-prompt-submit.retention.test.ts`). It fails before the correction and passes with the marked retained result, the healthy sibling’s complete answer, cleared delivery leases, and a successful next parent turn.

[Scenario and captures](https://gist.github.com/obviyus/cce960c04dafd949c21141686af3696e).

| Before | After |
| --- | --- |
| ![Missing field](https://gist.githubusercontent.com/obviyus/cce960c04dafd949c21141686af3696e/raw/e8b97302964ad1bd874c7b4f578c30a72593610a/before.png) | ![Complete field](https://gist.githubusercontent.com/obviyus/cce960c04dafd949c21141686af3696e/raw/e8b97302964ad1bd874c7b4f578c30a72593610a/after.png) |

## Compatibility

No public API, schema, retention, or retrieval feature changes. Archive hash, header, session, and owner checks remain. The existing worker scans a 536.9 MB decoded archive whose previous whole-string decoder failed.

## Consumers

Requester settlement, deferred turns, nested announcements, event projections, and retained parent history use the complete result, or the marked retained snapshot when its exact answer is unavailable.

## Invalidation

Run, producer, generation, batch, requester, and lease authority are rechecked after reads and before delivery. Failed prompt assembly releases its lease. Deferred source validation ends after the first foreground stream is acquired; parent abort checks remain active.

## Tests

The retained complete-result proof covers 374 tests across 15 files, including the format suite. The retained owner and sibling proof covers 379 passing tests across 17 files on a fresh merge with main, including the format and retention regressions. Four additional consumer suites update their explicit session-accessor mocks for the exact-run reader; their 286 tests pass on a fresh merge with main, with behavior assertions unchanged. Registered settlement, deferred-input, and continuation regressions fail on their original source. Type-aware preflight, structural checks, and test registration pass.

Production growth is 422 lines: result +241; output −130; queue +27; registry API +8; prompt build/phase/submit +6/+1/+16; wake/message −44/+54; announce +13; events −16; archive read/session/types/dispatch/worker/history +183/+6/+14/+20/+9/+11; history export +3. Growth accepted under the owner's standing acceptance (2026-09-15).

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants