Skip to content

fix(agents): retain actionable text in bounded tool results - #131827

Merged
steipete merged 4 commits into
mainfrom
codex/fix-tool-result-diagnostic-retention
Aug 28, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/fix-tool-result-diagnostic-retention

Conversation

@steipete

@steipete steipete commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Related #131824. Retains actionable diagnostic tails and short later text blocks when oversized tool results are projected into the next model request. The existing capacity is unchanged; raw captured output is not rewritten.

The original guard had two projection policies. Image-bearing results used the shared bounded block allocator, while text-only results were flattened and explicitly opted out of diagnostic-tail selection. The latter could remove the information the model needed next even when it fit the existing limit.

Why This Change Was Made

Text arrays and image-bearing results now use the same canonical block allocator, including the fallback that omits non-text content too large to fit. Existing weighted cost is carried consistently through allocation, while the established semantic small-block threshold remains separate from that cost. The flattened parallel path, proportional retry loop and sole tail-preservation opt-out are removed.

This repairs longstanding divergent behavior. Stable v2026.7.1-2 already had shared diagnostic-tail preservation alongside a prefix-only guard. #117149 carried that behavior forward, not a proven introduction. The newer multi-block allocator came from #114755; it is not claimed to be that same allocator in the stable tag.

User Impact

The next model request can retain a fitting error or retry instruction without increasing context limits. Existing privacy/detail stripping, raw-result immutability, image ordering and bounded prefixes, UTF-16 handling and ordinary pass-through behavior remain covered. There are no new settings, dependencies, SDK/protocol changes or persistence semantics.

Evidence

Before repair, CI run 33188808868 / job 98909068896 executed exact merge 3062103eee28688e94d7619e1de5ee861799e4aa of diagnostic f65427029c72e99e6d65a26faba5287d473b1b01 into fa68ddb2ec9e54c257ece2556c51c9c794f01851. It reported nine intended missing-text failures and 1,264 passing tests, across 68 files. All nine image controls, including the added 2,000-character description, passed. The complete 796,736-byte log has SHA256 a773bdd58a829a037220512e25374050961f332407d072dd47d4f8e94528e668; independent review verified all failures and 31 exact executed source/venue identities.

After repair, CI run 33195783997 / job 98933464357 executed merge 7a43b1c8795ab01342e32bd84ac6f80c652a33da of c71556cc1b301c10b33ef9226ccbbd274c07f467 into 267b0799b63c178e5be80122bb33d711f79e57e9. All 1,273 tests across 68 files passed, including the same nine regressions and all nine image controls. The same job also passed 16 overflow-compaction tests in two files. Its complete 505,781-byte log has SHA256 288daecd8d7d572bbc62e155ed27f1771282107ff6cca324829b7a0f37d94f6f. Thirty of the 31 named executed source/venue files match the repair commit exactly; the remaining prerequisite-table change only registers an unrelated Gateway test.

The cases cover ASCII, CJK, UTF-16, separate diagnostic/non-keyword text blocks, bounded/oversized non-text content, and two real Agent-loop cases. The latter execute a fixture tool through the production Agent, guard and canonical conversion, capture the second model request and inspect raw in-memory state. They use an injected model transport, not a live provider, Gateway, native tool implementation or persistent transcript. Passing complete cases now reaches the final-reply/idle/error and post-hint metadata assertions that were not reached on RED.

The earlier test-type error was corrected by carrying the same explicit 8,192 constant into fixture, guard and assertion; the repair commit's type and lint jobs passed. Its required assertion-safety ratchet did fail: one new array assertion lacked its invariant explanation. The follow-up adds only a brief comment documenting that the shared allocator preserves or maps the supplied array. It changes no executable code, type, test or baseline. The check is not weakened or bypassed.

Final head 3efc8cacaac55b90552f446dcb683013d4bbf03a now passes CI run 33198773591 / behavior job 98942972048, executed at exact merge e4ee71fa1b7c0cd7df66b53f2328a3544038c6e4 into 9219c92065ede2aa4cf65e38c3e87df135fdda52. The same nine regressions and all nine image controls pass: 1,273 tests in 68 files, plus the 16 overflow tests in two files. The complete 505,689-byte log has SHA256 8c18f15f46bb665ecc32713beeb5ee4afa1ce3fd42ce37c050393c9b848f1644. The assertion-safety ratchet also passes. The exact-head rollup is 190 successes, 55 skips, one neutral result and two routine dispatch/labeler cancellations, with no pending or failing checks; required openclaw/ci-gate is successful. Independent review bound the complete logs to 31 named executed source/venue files: 30 match the reviewed head, and the remaining prerequisite registration is the same unrelated Gateway-test entry previously examined.

No local product import, build, test or install ran under the campaign resource limit. The existing secretless hosted lane is used without new jobs, environment overrides or production test seams. Fresh structured review of the complete four-file candidate found no actionable P0–P2 issues; independent review verified the exact source, complete review inputs and final before/after evidence. Normal repository-native prepare/merge gates still apply.

The latest ClawSweeper review reviewed this exact head at 18:26 UTC. Its requested exact-head checks and rank-up are now complete. Its current-main/release comparison gap was independently covered: direct comparison of the 31 named owners and venue files from the PR base to main c8ddecdbfaae065fc0bce844d996b2a962776324 found only the unrelated Gateway prerequisite entry; the stable-tag distinction is recorded above. Its generic persistent-cache-schema annotation does not describe this diff: there is no schema/version/table/migration/store-write change. The changed production paths allocate bounded in-memory model projections; context-engine ingestion/assembly hooks and persistence eligibility are untouched, and raw in-memory Agent state remains unchanged in the passing tests. No migration is introduced or needed. This PR retains ownership of the repair; no duplicate fix was dispatched.

Production LOC: +85/-90 (net−5, including the invariant comment). Tests: +212/-4 across two existing modules, no new line-count suppression. Release-note context: preserve fitting actionable text when final tool-result context projection truncates large output.

Refs #131824. Expected-RED diagnostic baseline only; runtime behavior is unchanged.
@clawsweeper

clawsweeper Bot commented Aug 28, 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 maintainer Maintainer-authored PR labels Aug 28, 2026
@steipete
steipete marked this pull request as ready for review August 28, 2026 14:37
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 28, 2026
@clawsweeper

clawsweeper Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 28, 2026, 3:10 PM ET / 19:10 UTC.

ClawSweeper review

What this changes

The PR routes oversized embedded-agent tool-result arrays through the shared bounded allocator so fitting diagnostic tails and later text blocks reach the next model request within the existing cap.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for human landing: the maintainer-authored, maintainer-labeled PR fixes a current source-proven projection gap, and no blocking patch defect was found.

Priority: P2
Reviewed head: 3efc8cacaac55b90552f446dcb683013d4bbf03a
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, net-negative owner-boundary repair with credible regression coverage and no actionable review finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the captured evidence nevertheless includes focused before/after CI and an Agent-loop projection scenario through the production guard and conversion boundary.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the captured evidence nevertheless includes focused before/after CI and an Agent-loop projection scenario through the production guard and conversion boundary.
Evidence reviewed 8 items Current-main gap: Current main's text-only fallback explicitly disabled diagnostic-tail preservation, so the reported loss remains actionable before this PR merges.
Canonical repair: The PR reserves non-text content, delegates text allocation to the shared bounded allocator, and preserves visible omission information without flattening surviving text blocks.
Shared allocator contract: Weighted costs are carried through block allocation while the small semantic-block classification stays independent of the guard's raw-text safety floor.
Findings None None.
Security None None.

How this fits together

Embedded agents turn tool output into context for the next model request. The guard bounds that transient provider-facing projection while leaving the raw in-memory tool result available to the session.

flowchart LR
A[Tool output] --> B[Embedded agent guard]
B --> C[Bounded block allocator]
C --> D[Provider context]
D --> E[Next model response]
B --> F[Raw session result]
Loading

Decision needed

Question Recommendation
Should a human maintainer land this maintainer-authored repair after the repository-native merge gates confirm the current head? Land after native gates: Accept the focused owner-boundary repair after normal exact-head merge validation.

Why: The PR is protected by its maintainer label and author association, so this workflow must not auto-close or auto-land it.

Before merge

  • Complete next step (P2) - No repair-lane work is indicated; the remaining action is protected maintainer landing review.
Agent review details

Security

None.

PR surface

Source -5, Tests +208. Total +203 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 85 90 -5
Tests 2 212 4 +208
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 297 94 +203

Review metrics

Metric Value Why it matters
Production versus test delta production +85/-90 (net -5); tests +212/-4 The repair removes a parallel projection path while adding focused owner-boundary regression coverage.

Stored data model

Persistent data-model change detected: persistent cache schema: src/agents/embedded-agent-runner/tool-result-context-guard.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #131824
Summary: This PR is the focused candidate repair for the reported final tool-result context-projection loss.

Members:

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

Technical review

Best possible solution:

Land the canonical shared-allocator repair through the normal maintainer merge gates so bounded model context retains fitting actionable tool output without changing limits or stored session data.

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

Yes for a high-confidence source-level reproduction: current main still disables important-tail preservation in the final text-only guard, and the supplied expected-red baseline targets that route. This read-only review did not execute the test suite.

Is this the best way to solve the issue?

Yes. Reusing the existing bounded block allocator removes the divergent flattened path instead of adding a special-case tail workaround.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded agent-context correctness repair with no demonstrated crash, data-loss, or security impact.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the captured evidence nevertheless includes focused before/after CI and an Agent-loop projection scenario through the production guard and conversion boundary.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the prior merged CJK bounded-tool-result repair and context-limit refactor, as well as this focused repair. (role: recent area contributor and current repair author; confidence: high; commits: 69e8d406f070, 475ea69f2c35, c71556cc1b30; files: src/agents/embedded-agent-runner/tool-result-context-guard.ts, src/agents/embedded-agent-runner/tool-result-truncation.ts)
  • Shakker: Blame attributes the current-main tail-preservation opt-out to the source snapshot in f21acc9. (role: current behavior provenance; confidence: medium; commits: f21acc911cfb; files: src/agents/embedded-agent-runner/tool-result-context-guard.ts)

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 (3 earlier review cycles)
  • reviewed 2026-08-28T14:45:31.192Z sha e68765b :: found issues before merge. :: [P2] Pair the expected-red baseline with the owner repair
  • reviewed 2026-08-28T16:18:31.715Z sha f654270 :: found issues before merge. :: [P2] Pair the expected-red baseline with the owner repair
  • reviewed 2026-08-28T18:26:56.006Z sha 3efc8ca :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 28, 2026
@steipete steipete changed the title chore(agents): diagnose tool-result diagnostic retention fix(agents): retain actionable text in bounded tool results Aug 28, 2026
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 28, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Final proof for 3efc8cacaac55b90552f446dcb683013d4bbf03a: the same nine regressions that failed before repair now pass, together with all nine image controls, 1,273 tests in 68 files and 16 overflow tests in two files. Behavior CI and the assertion-safety ratchet pass; the exact-head required gate is green, with no failing or pending checks.

The repair removes the parallel flattened projection path and uses the existing bounded block allocator throughout, preserving the hard cap and fitting diagnostic/short text blocks (production net−5). Independent review verified the complete before/after logs and 31 named executed source/venue identities. The Agent-loop tests use real production execution and an injected model transport/fixture tool; they do not claim a live provider, Gateway or persistent-transcript run.

The latest ClawSweeper's CI/rank-up and current-main/release-comparison gaps are addressed in the updated body. Its generic storage classification is inapplicable to the actual diff: no schema, migration or store-write path changes, and raw in-memory results remain unchanged. Normal native prepare/merge gates remain; related #131824 stays open until the repair is verified on main.

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 28, 2026
@steipete
steipete merged commit 5d88e18 into main Aug 28, 2026
257 of 259 checks passed
@steipete
steipete deleted the codex/fix-tool-result-diagnostic-retention branch August 28, 2026 19:16
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 29, 2026
…#131827)

* test(agents): reproduce diagnostic loss in context guard

Refs openclaw#131824. Expected-RED diagnostic baseline only; runtime behavior is unchanged.

* test(agents): extend tool-result diagnostic baseline

* fix(agents): unify bounded tool-result projection

* docs(agents): explain bounded content array invariant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant