Skip to content

fix(agents): keep tool result summaries when middleware details exceed shape limits - #147805

Merged
obviyus merged 2 commits into
openclaw:mainfrom
LiuwqGit:feat/issue-147776-middleware-details-shape
Sep 14, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
LiuwqGit:feat/issue-147776-middleware-details-shape

Conversation

@LiuwqGit

@LiuwqGit LiuwqGit commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

AI-assisted: yes

Closes #147776

What Problem This Solves

Fixes wiki_lint returning “Tool output unavailable due to post-processing error.” for larger vaults even though the supported CLI lint succeeds.

User Impact

Agents keep the lint summary and report path when optional details exceed existing limits. Smaller results retain their normalized details. No configuration or migration is required.

Why This Change Was Made

The shared incoming-details sanitizer now applies the existing shape check as well as the byte cap, with one truncation-marker return. Middleware replacements still undergo strict validation. Each result stays local to its ordered middleware chain.

Evidence

A real Gateway chat.send invoked the registered wiki tool and bundled middleware against isolated vaults. A local provider fixture captured the next request.

  • Main f8cd665c2b44: 147 warnings become the post-processing error.
  • Updated 5b5e84742c21: the request retains Issues: 147 total (0 errors, 147 warnings); the persisted tool result has { truncated: true, originalSizeBytes: 26231 } and no error.
  • The ten-page control retains the same full normalized details; CLI lint succeeds for both sizes.
  • 32 focused tests pass on a fresh merge with main bcfe3383b87d. Restoring the old sanitizer makes only the 147-issue regression fail.
  • Type-aware lint, production/test types, protocol, formatting, line-count, assertion-safety, and unused-export checks pass.

Consumers

Registered middleware receives normalized details. Agent requests receive summary text; host transcripts retain the truncation marker. Validation limits, public types, and cache lifecycles are unchanged.

@clawsweeper

clawsweeper Bot commented Sep 14, 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 agents Agent runtime and tooling size: S labels Sep 14, 2026
@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: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 11:57 AM ET / 15:57 UTC (Revision 3).

ClawSweeper review

What this changes

Preserves tool-result summaries when optional details exceed existing complexity limits, replacing those details with a truncation marker and adding regression coverage.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main and v2026.9.4 retain the sanitizer gap. The focused fix has convincing before/after production-path evidence, and no actionable correctness findings remain.

Priority: P2
Reviewed head: 5b5e84742c211b433aea2e022853a055e315acf3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable repair with meaningful regression coverage and convincing production-path before/after evidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded Gateway chat.send evidence exercises the registered wiki tool and bundled middleware on isolated 10-page and 147-page vaults; the repaired sanitizer preserves the large-result summary in the next provider request and records truncated details without an error.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded Gateway chat.send evidence exercises the registered wiki tool and bundled middleware on isolated 10-page and 147-page vaults; the repaired sanitizer preserves the large-result summary in the next provider request and records truncated details without an error.
Evidence reviewed 9 items Verified introduced change: The pinned merge-base-to-head diff changes only the incoming-details sanitizer and its tests. It reuses the existing shape predicate without changing limits, middleware ordering, registrations, or output validation.
Current main still has the defect: The sanitizer returns parsed details whenever serialized size is within 100,000 bytes, even when recursive shape validation rejects them. A pass-through middleware subsequently causes valid summary text to be replaced with the generic error.
Latest release remains affected: The supplied latest release, v2026.9.4, contains the same byte-only input sanitizer; the requested repair is not present there.
Findings None None.
Security None None.

How this fits together

OpenClaw's tool-result middleware processes completed tool output before it reaches the model and transcript. Its input sanitizer must preserve useful text while making optional details safe for registered plugin transforms.

flowchart TD
  A[Completed tool result] --> B{Middleware registered?}
  B -->|No| F[Model and transcript]
  B -->|Yes| C[Normalize optional details]
  C --> D[Ordered plugin transforms]
  D --> E{Output valid?}
  E -->|Yes| F
  E -->|No| G[Safe processing error]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -4, Tests +41. Total +37 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 8 12 -4
Tests 1 43 2 +41
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 51 14 +37

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #147776
Summary: This PR is the implementation candidate for the linked middleware shape-limit defect.

Members:

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

Technical review

Best possible solution:

Keep normalization in the shared input sanitizer, preserve summary text and report references, and retain strict validation of plugin-produced replacements.

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

Yes. Current source establishes that details below the byte cap but above 1,000 recursive entries fail after pass-through middleware; supplied real-run evidence confirms the symptom. This review did not execute target code.

Is this the best way to solve the issue?

Yes. Completing the existing sanitizer's contract fixes the shared cause without adding a wiki-specific workaround, relaxing limits, or changing public APIs.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: Repairs lost agent tool summaries for larger wiki results, with limited demonstrated prevalence and a supported CLI workaround.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Recorded Gateway chat.send evidence exercises the registered wiki tool and bundled middleware on isolated 10-page and 147-page vaults; the repaired sanitizer preserves the large-result summary in the next provider request and records truncated details without an error.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded Gateway chat.send evidence exercises the registered wiki tool and bundled middleware on isolated 10-page and 147-page vaults; the repaired sanitizer preserves the large-result summary in the next provider request and records truncated details without an error.

Evidence

What I checked:

  • Verified introduced change: The pinned merge-base-to-head diff changes only the incoming-details sanitizer and its tests. It reuses the existing shape predicate without changing limits, middleware ordering, registrations, or output validation. (src/agents/harness/tool-result-middleware.ts:323, 5b5e84742c21)
  • Current main still has the defect: The sanitizer returns parsed details whenever serialized size is within 100,000 bytes, even when recursive shape validation rejects them. A pass-through middleware subsequently causes valid summary text to be replaced with the generic error. (src/agents/harness/tool-result-middleware.ts:326, c6b8270152bc)
  • Latest release remains affected: The supplied latest release, v2026.9.4, contains the same byte-only input sanitizer; the requested repair is not present there. (src/agents/harness/tool-result-middleware.ts:326, 3a9d69db306c)
  • Production entrypoint and implementation boundary: The embedded agent's tool_result handler calls this runner with runtime=openclaw. The changed tests exercise OpenClaw's own validator; the codex runtime string selects middleware context and does not execute or test an external Codex protocol. No dependency-specific Codex inspection gate is established. (src/agents/embedded-agent-runner/extensions.ts:48, 5b5e84742c21)
  • Wiki output retains a usable report reference: The registered wiki lint tool includes warning counts and the report path in text content independently of its detailed issue arrays, so collapsing optional details preserves access to the report. (extensions/memory-wiki/src/tool.ts:207, 5b5e84742c21)
  • Recorded real behavior proof: The captured PR body reports Gateway chat.send through the registered wiki tool and bundled middleware using isolated vaults and a local provider fixture: the old sanitizer loses the 147-warning summary; head 5b5e847 preserves it in the next request and persists a 26,231-byte truncation marker without an error. The ten-page control retains normalized details. The earlier terminal transcript at fix(agents): keep tool result summaries when middleware details exceed shape limits #147805 (comment) independently records real wiki execution through loaded plugin middleware. These are supplied observations, not executions performed during this review. (5b5e84742c21)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • solomonneas: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (2 earlier review cycles)
  • reviewed 2026-09-14T03:39:33.932Z sha fb9e2c0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-14T04:34:18.790Z sha fb9e2c0 :: needs maintainer review before merge. :: none

@LiuwqGit

Copy link
Copy Markdown
Contributor Author

Added the requested real-setup proof (no synthetic payloads, no injected handler). Evidence details are in the updated PR body; summary:

What was missing: the earlier proof called createAgentToolResultMiddlewareRunner directly with synthetic wiki_lint payloads and a hand-injected no-op handler.

What was added: a run of the real path, end to end:

  1. Registered middleware, not an injected one: the real bundled tokenjuice plugin is loaded through the real plugin loader (loadOpenClawPlugins) and the real plugin registry; its tool-result middleware is registered via the public api.registerAgentToolResultMiddleware plugin API (registered agent tool-result middlewares (runtime=openclaw): 1). For non-exec tools like wiki_lint it returns the result unchanged — exactly the issue's scenario.
  2. Real wiki_lint, not synthetic payloads: a real memory-wiki vault is initialized on disk and filled with real markdown entity pages older than the 90-day staleness window, so the real lint rules produce one stale-page warning per page. The real wiki_lint tool (createWikiLintTool, the same factory the memory-wiki plugin registers) lints that vault, with the memory-wiki state stores wired to the real SQLite-backed plugin blob/keyed stores like the plugin's register() does.
  3. Real runner construction: the tool result flows through createAgentToolResultMiddlewareRunner({ runtime: "openclaw", ... }) with no injected handlers — constructed exactly like buildAgentToolResultMiddlewareFactory (src/agents/embedded-agent-runner/extensions.ts) — so the middleware chain is the one registered in the plugin registry.

After (fix commit fb9e2c0d): the 147-stale-page vault yields 147 issues / 51,699 detail bytes (under the 100,000-byte cap) / 1,774 recursive detail entries (over the 1,000-entry shape cap — the same entry count measured on the reporter's vault). The agent receives the summary Issues: 147 total (0 errors, 147 warnings) with details: { truncated: true, originalSizeBytes: 26672 }; the 10-page control is delivered unchanged with full details.

{"pass":"control-10-pages","rawIssueCount":10,"detailsBytes":3654,"detailEntries":130,"outputTextFirstLine":"Issues: 10 total (0 errors, 10 warnings)","middlewareError":false,"truncated":false}
{"pass":"oversized-147-pages","rawIssueCount":147,"detailsBytes":51699,"detailEntries":1774,"outputTextFirstLine":"Issues: 147 total (0 errors, 147 warnings)","middlewareError":false,"truncated":true,"originalSizeBytes":26672}
ASSERTIONS PASSED (fix active): real wiki_lint through registered plugin middleware keeps the summary

Before (identical script, origin/main version of src/agents/harness/tool-result-middleware.ts): the same registered-middleware path logs [agents/harness] [openclaw] discarded invalid tool result middleware output for wiki_lint and returns Tool output unavailable due to post-processing error. with details: { status: "error", middlewareError: true } for the 147-page pass — the exact symptom from the issue.

Not covered: a full live gateway session with a model-driven agent turn (no model credentials in this environment); the run executes from a source checkout with dev-source SDK aliasing (the same aliasing the repository's vitest config applies). CI is green on the current head.

@clawsweeper clawsweeper Bot added 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. and removed 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. labels Sep 14, 2026
@obviyus

obviyus commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

landpr-approve-admin-merge
pr: 147805
head: 5b5e847
scope: owner-review

@obviyus

obviyus commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

landpr-approve-unrelated-red
pr: 147805
head: 5b5e847
run: 34860446155 attempt: 2
failed: checks-node-compact-large-23 job=104037238965 conclusion=failure
check: openclaw/ci-gate

@obviyus
obviyus merged commit 3c08384 into openclaw:main Sep 14, 2026
245 of 251 checks passed
@obviyus

obviyus commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Thanks @LiuwqGit!

Proof: A Gateway turn ran wiki_lint against 147 stale pages and retained the lint summary with explicit truncation in the stored tool details. The ten-page control retained its full normalized details.

  • Bug: Large lint details caused a valid summary to become a post-processing error.
  • Fix: The shared result sanitizer applies the existing byte and shape limits before middleware runs while preserving summary text.
Before After
Tool output unavailable due to post-processing error. Issues: 147 total (0 errors, 147 warnings)

vincentkoc added a commit that referenced this pull request Sep 14, 2026
* commit '3c08384584f57787a26da9998488233fc15ccf7e': (122 commits)
  fix(agents): keep tool result summaries when middleware details exceed shape limits (#147805)
  test: make full-suite fixtures portable across runtimes (#148247)
  refactor(qa): share unknown confidence results (#148200)
  chore(android): remove unused test dependencies and duplicate Wear settings (#148231)
  test: reuse compiled preflight in startup fixtures (#148330)
  test(wizard): route recovery integration through database forks (#148337)
  refactor(plugins): simplify provider auth patch recursion (#147933)
  fix(cli): drain failed web capability output (#148234)
  refactor(android): remove unused production helpers (#148233)
  fix(plugins): scope feed integrity to hosted ClawHub (#148220)
  test(qa): compare Telegram entities semantically (#148219)
  test(qa): recognize native Slack exec progress rows (#148217)
  test(cron): distinguish repeated delivery incidents (#148151)
  test(qa): preserve restart command ownership (#148218)
  test(qa): isolate bundled skill CLI gateway state (#148150)
  test(qa): align process lifecycle contracts (#148149)
  improve(media): reduce metadata fetched during orphan cleanup (#148244)
  fix(matrix): retain sync state runtime for deferred persistence (#148152)
  test: deduplicate gateway watch exit fixtures (#148237)
  refactor(cli): derive daemon status contract from gatherer (#148108)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 15, 2026
…d shape limits (openclaw#147805)

> AI-assisted: yes

Closes openclaw#147776

## What Problem This Solves

Fixes `wiki_lint` returning “Tool output unavailable due to post-processing error.” for larger vaults even though the supported CLI lint succeeds.

## User Impact

Agents keep the lint summary and report path when optional details exceed existing limits. Smaller results retain their normalized details. No configuration or migration is required.

## Why This Change Was Made

The shared incoming-details sanitizer now applies the existing shape check as well as the byte cap, with one truncation-marker return. Middleware replacements still undergo strict validation. Each result stays local to its ordered middleware chain.

## Evidence

A real Gateway `chat.send` invoked the registered wiki tool and bundled middleware against isolated vaults. A local provider fixture captured the next request.

- Main `20cf6971b89c`: 147 warnings become the post-processing error.
- Updated `5b5e84742c21`: the request retains `Issues: 147 total (0 errors, 147 warnings)`; the persisted tool result has `{ truncated: true, originalSizeBytes: 26231 }` and no error.
- The ten-page control retains the same full normalized details; CLI lint succeeds for both sizes.
- 32 focused tests pass on a fresh merge with main `1b62a56f76bf`. Restoring the old sanitizer makes only the 147-issue regression fail.
- Type-aware lint, production/test types, protocol, formatting, line-count, assertion-safety, and unused-export checks pass.

## Consumers

Registered middleware receives normalized details. Agent requests receive summary text; host transcripts retain the truncation marker. Validation limits, public types, and cache lifecycles are unchanged.

Co-authored-by: Ayaan Zaidi <[email protected]>
@LiuwqGit
LiuwqGit deleted the feat/issue-147776-middleware-details-shape branch September 22, 2026 14:47
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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.

[Bug]: wiki_lint discards valid summary when details exceed middleware shape limit

2 participants