Repository navigation
improve: send compact JSON tool results to the model - #196756
Conversation
|
🦞👀 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. |
|
|
Codex review: needs changes before merge. What this changesThis PR emits compact model-facing JSON, aligns output budgets, and preserves readable tool-result displays. Example: A tool returns {"ok":true,"messageId":"msg-1"}.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: compact serialization is a useful, maintainer-directed improvement, but the consumer-test cutover is incomplete. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherTool-result constructors turn payloads into model-facing text and structured details; budget owners bound that text, while Control UI and TUI render captured results. flowchart LR
A[Tool payload] --> B[Result constructors]
B --> C[Compact JSON text]
C --> D[Output budget checks]
D --> E[Model request]
C --> F[Captured tool result]
F --> G[Control UI display]
F --> H[TUI literal display]
Technical reviewBest possible solution: Keep compact serialization in the existing owners and complete the affected consumer-test expectations without restoring server-side indentation. Do we have a high-confidence way to reproduce the issue? Current-main source directly shows repeated pretty serialization, and current-head GitHub annotations demonstrate the consumer expectations affected by replacing it. Is this the best way to solve the issue? The existing result constructors are the right owners, and aligning budget measurements with emitted bytes is the smallest complete approach; display formatting appropriately remains at the presentation boundary. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 109b0cc2e9b5. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +3, Tests +16, Docs +1. Total +20 across 44 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 November 10, 2026, 12:26 PM ET / 17:26 UTC. |
Complete the consumer expectation cutover from #196756. Keep full result equality, original typed details and all registration/config assertions. Actual affected test fails before correction; both helper and plugin files pass all six tests after correction. Co-authored-by: obviyus <[email protected]>
## What Problem This Solves An agent cannot collect an already-finished background process when unrelated Code Mode continuations fill all 64 suspended-run slots. The fresh observer fails before reaching `process`, even with outer `awaitResults: true`. ## User Impact and Solution Required-completion cells keep their owner until settlement and cannot publish suspended continuations, so they no longer reserve a suspension slot at inline dispatch or checkpoint settlement. Agents can collect the original process result without relaunching work. Capacity errors and troubleshooting guidance explain this recovery path. Default suspension admission, existing-run reservation transfer, process retention, authority checks, and cancellation are unchanged. This complements #196435's rejected-cell settlement fix; it addresses fresh-observer admission rather than process-output loss. It intentionally permits actively owned required-completion cells at the suspension cap, not a new total-live-cell resource limit. ## Evidence - One real native background process and 64 genuine parked VM continuations: default observation fails without dispatch; required observation retrieves the original terminal output. Assertions retain one launch, one poll, the 64-slot cap, active-resume reservation, cancellation, and capacity recovery. - Regression fails on base `5e8ed5f5b437e3a8438a036eb42c4d98009d0d86`, passes with the fix. - Seven focused suites: **169 tests passed**, including agent-loop recovery, Node/QuickJS failure origins, required wait/cancellation, shell terminal draining, bridge behavior, and prompt-prefix stability. - Core and changed-test TypeScript, targeted type-aware lint, formatting, MDX, and diff checks passed. - Exact **59-line** allocation records the native-process setup and assertions added to the existing capacity test; shared scalar unchanged. Local test-line ratchet passes with 17 lines slack, and the previous head's complete baseline-ratchet CI passed. Saturation test takes about 2 seconds locally. - No new queue, quota, recovery manager, or persistent state. Production delta: 9 added / 3 removed lines. ## CI repairs Earlier heads exposed two inherited worker containment expectation failures in `checks-node-changed-11`. Source inspection and base reproduction established stale expectations after #194473's root-aware recovery and #196756's compact JSON serialization. Current main `18adeb3f1768b3c1371b3c294f06397d5cb352ea` still had those expectations; no competing fix was found. The follow-up updates only `src/worker/worker-runtime-permissions.suite.ts`: independent per-policy literal expectations and exact compact JSON output. Rejection status, tool name, escaped path, operator-only hint separation/logging, unchanged outside-file contents, and file-mode assertions remain intact. No permission behavior, ignores, retries, or gates were weakened. - `node scripts/run-vitest.mjs src/worker/worker.runtime.test.ts --maxWorkers=1`: **69 passed**, 40.79 seconds suite / 47.24 seconds wrapper. The existing suite's real background-process cleanup tests dominate duration; the two repaired cases take 29/24 ms. - Changed-test TypeScript graph (`gateway-other`), type-aware lint, formatting, diff check, and test-line ratchet passed. - New-head CI is being evaluated separately; previous-head results are not claimed as current-head CI proof. ## Review and limitations Independent native-subagent reviews of the implementation, exact allocation, and worker repair found no actionable defects. Local reviewer CLIs and bound autoreview tool were unavailable; no review tools were installed. These were narrative independent reviews, not helper-enforced isolation or structured helper validation. Hosted review of `1269cc403ec7243b847eb4cbec0ff0b5a8d08f6e` also reported no findings. The new saturation case executes Node. QuickJS support is backed by shared owner-path inspection and existing parity/failure tests, not a separate saturation run. No shipped Gateway/live-model saturation capture or guarantee of model recovery choices is claimed; proof exercises the actual Code Mode/native-process integration boundary. ## Main integration (November 11, 2026) Merged main into the published PR branch without rewriting history (head `33a9fa55f09e6cbb41300cc0aa67ee9ef2edf94b`). Verified tree equivalence with the reviewed rebase plus the disjoint main update. The equivalent rebased code passed the native-process capacity regression and 69 worker tests, targeted type-aware lint, and formatting. The final merge passed diff checks and the test-line ratchet with 10 lines slack; no shared budget increase. Updated-head CI verified on November 11, 2026: 71 checks passed, 59 skipped, no failures or pending checks on `33a9fa55f09e6cbb41300cc0aa67ee9ef2edf94b`. The PR remains open; no merge was performed. ## Main conflict resolution (November 12, 2026) Merged main `4947e40db109` normally into the PR without force-pushing. New head: `225c5b5bcf06f45ef6018580425bc94349c1b9c2`. The only conflict was in the worker containment test: main now has the same corrected messages and compact JSON expectation. Kept the already-reviewed independent per-policy literal expectations; no new production behavior. The database-worker test inventory auto-merged both additions. Scoped proof on the integrated tree: native-process saturation regression passed; all 69 worker runtime tests passed; worker test typecheck, type-aware lint, formatting, and diff check passed. Existing implementation review remains applicable to this mechanical integration. The initial worker invocation hit unresolved conflict markers after a failed editing command; the corrected complete worker suite passed. Current-head CI is pending and is required before merge; previous-head green checks are not claimed as current proof. <!-- openclaw-publication:496957c8-5491-47fa-9565-7ecf6d229daa -->
Align the native hook relay middleware expectation with the compact payload serializer introduced by #196756. Retain exact result content and details assertions. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]>
* fix: bound transcript reads before native context seeding Co-authored-by: RomneyDa <[email protected]> * fix: reduce transcript allocation when preparing native context seeds OpenClaw-Publication: 294c8539-9e0b-4d17-aef7-76eb33f15e8b * fix: preserve lightweight native seed reader imports Move shared selection and token accounting into existing pure leaf owners without loading compaction transports or the agent runtime. Preserve the transcript-reader isolation introduced by #162609 and package only the required leaf closure. Co-authored-by: RomneyDa <[email protected]> * Publish openclaw/bound-context-read-pr OpenClaw-Publication: 09aca01f-b368-487f-97eb-dbb64b0b376f * Publish openclaw/bound-context-read-pr OpenClaw-Publication: 9793f742-04ad-4d1a-b977-7ebd074e7f63 * fix(sessions): satisfy bounded seed CI ratchets Build last-member JSON lookup with typed Kysely. Keep deterministic hydration assertions without repeated timing samples and allocate exactly the remaining 250 regression-test lines. Co-authored-by: RomneyDa <[email protected]> * Publish openclaw/bound-context-read-pr OpenClaw-Publication: beebe320-4be9-4844-bf45-651370b69c83 * Publish openclaw/bound-context-read-pr OpenClaw-Publication: d07a04d5-f480-4414-994f-c5feed6be860 * test(codex): expect compact native tool result JSON Align the native hook relay middleware expectation with the compact payload serializer introduced by #196756. Retain exact result content and details assertions. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> * Publish openclaw/bound-context-read-pr OpenClaw-Publication: 63a451db-f5c9-453b-96f0-72ed26ba3893 --------- Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]>
…aw#197068) Align the Telegram loopback assertion with the compact answered-result text intentionally introduced by openclaw#196756. Preserve the exact answered status, successful text result, Bot API prompt and authority/cleanup assertions. No production, retry or timeout changes. Co-authored-by: steipete <[email protected]> Co-authored-by: obviyus <[email protected]>
…openclaw#197082) Align the worker permission fixture with source-specific containment recovery guidance introduced by openclaw#194473 and compact JSON results introduced by openclaw#196756. Preserve exact denial, outside-file contents/mode and operator-only hint assertions. No production permission policy changes. Proof: independent isolated review clean; source-extracted diagnostic red/green checks for configured and guarded modes; exact-head CI 42974054691 passed changed tests, boundary checks, lint/types, ratchets and ci-gate. Local named runtime test could not collect without task dependencies; no local integration success claimed. Co-authored-by: steipete <[email protected]> Co-authored-by: obviyus <[email protected]>
…97222) Complete the consumer expectation cutover from openclaw#196756. Keep full result equality, original typed details and all registration/config assertions. Actual affected test fails before correction; both helper and plugin files pass all six tests after correction. Co-authored-by: obviyus <[email protected]>
## What Problem This Solves An agent cannot collect an already-finished background process when unrelated Code Mode continuations fill all 64 suspended-run slots. The fresh observer fails before reaching `process`, even with outer `awaitResults: true`. ## User Impact and Solution Required-completion cells keep their owner until settlement and cannot publish suspended continuations, so they no longer reserve a suspension slot at inline dispatch or checkpoint settlement. Agents can collect the original process result without relaunching work. Capacity errors and troubleshooting guidance explain this recovery path. Default suspension admission, existing-run reservation transfer, process retention, authority checks, and cancellation are unchanged. This complements openclaw#196435's rejected-cell settlement fix; it addresses fresh-observer admission rather than process-output loss. It intentionally permits actively owned required-completion cells at the suspension cap, not a new total-live-cell resource limit. ## Evidence - One real native background process and 64 genuine parked VM continuations: default observation fails without dispatch; required observation retrieves the original terminal output. Assertions retain one launch, one poll, the 64-slot cap, active-resume reservation, cancellation, and capacity recovery. - Regression fails on base `d53716c9b1671e5509516227f720722e25d9e1d4`, passes with the fix. - Seven focused suites: **169 tests passed**, including agent-loop recovery, Node/QuickJS failure origins, required wait/cancellation, shell terminal draining, bridge behavior, and prompt-prefix stability. - Core and changed-test TypeScript, targeted type-aware lint, formatting, MDX, and diff checks passed. - Exact **59-line** allocation records the native-process setup and assertions added to the existing capacity test; shared scalar unchanged. Local test-line ratchet passes with 17 lines slack, and the previous head's complete baseline-ratchet CI passed. Saturation test takes about 2 seconds locally. - No new queue, quota, recovery manager, or persistent state. Production delta: 9 added / 3 removed lines. ## CI repairs Earlier heads exposed two inherited worker containment expectation failures in `checks-node-changed-11`. Source inspection and base reproduction established stale expectations after openclaw#194473's root-aware recovery and openclaw#196756's compact JSON serialization. Current main `ecfec37bdb3551b3555550d398d19655c9327a9f` still had those expectations; no competing fix was found. The follow-up updates only `src/worker/worker-runtime-permissions.suite.ts`: independent per-policy literal expectations and exact compact JSON output. Rejection status, tool name, escaped path, operator-only hint separation/logging, unchanged outside-file contents, and file-mode assertions remain intact. No permission behavior, ignores, retries, or gates were weakened. - `node scripts/run-vitest.mjs src/worker/worker.runtime.test.ts --maxWorkers=1`: **69 passed**, 40.79 seconds suite / 47.24 seconds wrapper. The existing suite's real background-process cleanup tests dominate duration; the two repaired cases take 29/24 ms. - Changed-test TypeScript graph (`gateway-other`), type-aware lint, formatting, diff check, and test-line ratchet passed. - New-head CI is being evaluated separately; previous-head results are not claimed as current-head CI proof. ## Review and limitations Independent native-subagent reviews of the implementation, exact allocation, and worker repair found no actionable defects. Local reviewer CLIs and bound autoreview tool were unavailable; no review tools were installed. These were narrative independent reviews, not helper-enforced isolation or structured helper validation. Hosted review of `1269cc403ec7243b847eb4cbec0ff0b5a8d08f6e` also reported no findings. The new saturation case executes Node. QuickJS support is backed by shared owner-path inspection and existing parity/failure tests, not a separate saturation run. No shipped Gateway/live-model saturation capture or guarantee of model recovery choices is claimed; proof exercises the actual Code Mode/native-process integration boundary. ## Main integration (November 11, 2026) Merged main into the published PR branch without rewriting history (head `33a9fa55f09e6cbb41300cc0aa67ee9ef2edf94b`). Verified tree equivalence with the reviewed rebase plus the disjoint main update. The equivalent rebased code passed the native-process capacity regression and 69 worker tests, targeted type-aware lint, and formatting. The final merge passed diff checks and the test-line ratchet with 10 lines slack; no shared budget increase. Updated-head CI verified on November 11, 2026: 71 checks passed, 59 skipped, no failures or pending checks on `33a9fa55f09e6cbb41300cc0aa67ee9ef2edf94b`. The PR remains open; no merge was performed. ## Main conflict resolution (November 12, 2026) Merged main `ec930d1030e9` normally into the PR without force-pushing. New head: `225c5b5bcf06f45ef6018580425bc94349c1b9c2`. The only conflict was in the worker containment test: main now has the same corrected messages and compact JSON expectation. Kept the already-reviewed independent per-policy literal expectations; no new production behavior. The database-worker test inventory auto-merged both additions. Scoped proof on the integrated tree: native-process saturation regression passed; all 69 worker runtime tests passed; worker test typecheck, type-aware lint, formatting, and diff check passed. Existing implementation review remains applicable to this mechanical integration. The initial worker invocation hit unresolved conflict markers after a failed editing command; the corrected complete worker suite passed. Current-head CI is pending and is required before merge; previous-head green checks are not claimed as current proof. <!-- openclaw-publication:496957c8-5491-47fa-9565-7ecf6d229daa -->
* fix: bound transcript reads before native context seeding Co-authored-by: RomneyDa <[email protected]> * fix: reduce transcript allocation when preparing native context seeds OpenClaw-Publication: 294c8539-9e0b-4d17-aef7-76eb33f15e8b * fix: preserve lightweight native seed reader imports Move shared selection and token accounting into existing pure leaf owners without loading compaction transports or the agent runtime. Preserve the transcript-reader isolation introduced by openclaw#162609 and package only the required leaf closure. Co-authored-by: RomneyDa <[email protected]> * Publish openclaw/bound-context-read-pr OpenClaw-Publication: 09aca01f-b368-487f-97eb-dbb64b0b376f * Publish openclaw/bound-context-read-pr OpenClaw-Publication: 9793f742-04ad-4d1a-b977-7ebd074e7f63 * fix(sessions): satisfy bounded seed CI ratchets Build last-member JSON lookup with typed Kysely. Keep deterministic hydration assertions without repeated timing samples and allocate exactly the remaining 250 regression-test lines. Co-authored-by: RomneyDa <[email protected]> * Publish openclaw/bound-context-read-pr OpenClaw-Publication: beebe320-4be9-4844-bf45-651370b69c83 * Publish openclaw/bound-context-read-pr OpenClaw-Publication: d07a04d5-f480-4414-994f-c5feed6be860 * test(codex): expect compact native tool result JSON Align the native hook relay middleware expectation with the compact payload serializer introduced by openclaw#196756. Retain exact result content and details assertions. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> * Publish openclaw/bound-context-read-pr OpenClaw-Publication: 63a451db-f5c9-453b-96f0-72ed26ba3893 --------- Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]>
…ith compact JSON - Restore buildBootstrapContextFiles' [MISSING] Expected at: <absolute path> marker so the exported agent-harness-runtime SDK consumer contract is unchanged. Prompt preparation (prepareContextFilesForPrompt) still renders workspace-relative markers via the new missing flag, keeping the cross-workspace prefix-cache parity from openclaw#191485. - Align run-attempt.native-hook-relay.test.ts with compact JSON tool results from openclaw#196756 (main 3d6699c changed payloadTextResult serialization after this branch point; the stale pretty-JSON expectation fails the merged-tree shard).
…during compaction (#196550) * fix: reduce Gateway heap spikes during long-session compaction OpenClaw-Publication: 3c8ed9c2-cdf2-4a3e-9cfc-cb237d488ace * fix: reuse compaction facts without repeated transcript parsing OpenClaw-Publication: b899f5e4-7fb9-46f0-9b19-635e33a8b99c * Publish openclaw/keen-prawn OpenClaw-Publication: 33dc62a0-c779-4768-97d2-4b3fa2323cdf * Publish openclaw/keen-prawn OpenClaw-Publication: f8c0512a-6354-4487-b291-d85f50f68262 * fix: reconcile compaction regression-test allocation OpenClaw-Publication: 90ea6a98-3750-4df1-8f07-6333b0ba229c * fix(compaction): free the compaction worker during summary model calls * fix: match compaction concurrency test-line credit to its net growth * perf(compaction): check only captured rows before rerendering summary input * test: align worker containment and Claude fallback tests with main contracts main #194473 reworded the file-tool containment hint per source and #196756 compacted tool-result JSON; main #196459 gave unknown Claude ids mandatory adaptive thinking, so the non-reasoning fallback fixture uses a pre-Claude-5 id. * refactor(compaction): keep preflight metadata in its reader Co-authored-by: RomneyDa <[email protected]> * fix(compaction): detach bounded floor facts from transcript payloads Prevent small excerpts and identifier captures from retaining whole source strings while a compaction plan is cached. Add a GC retention regression for the owning producer. Co-authored-by: RomneyDa <[email protected]> * fix(workers): defer slow idle GC logging imports Keep the slow-GC diagnostic behind its own lazy operation boundary so small workers do not eagerly evaluate the logging graph. Preserve collection thresholds and warning fields. The existing production build gate reproduces 240 identity-worker modules on the base and passes at 203 after the repair (budget 220 unchanged). Full and sourcePerformance builds, 11 focused worker tests, infra typecheck, lint, and format checks pass. Independent native review found no actionable P0/P1/P2 findings; local autoreview was unavailable because Codex was not installed. Co-authored-by: RomneyDa <[email protected]> * fix: complete compaction wrapper inventory Co-authored-by: RomneyDa <[email protected]> --------- Co-authored-by: RomneyDa <[email protected]>
…during compaction (openclaw#196550) * fix: reduce Gateway heap spikes during long-session compaction OpenClaw-Publication: 3c8ed9c2-cdf2-4a3e-9cfc-cb237d488ace * fix: reuse compaction facts without repeated transcript parsing OpenClaw-Publication: b899f5e4-7fb9-46f0-9b19-635e33a8b99c * Publish openclaw/keen-prawn OpenClaw-Publication: 33dc62a0-c779-4768-97d2-4b3fa2323cdf * Publish openclaw/keen-prawn OpenClaw-Publication: f8c0512a-6354-4487-b291-d85f50f68262 * fix: reconcile compaction regression-test allocation OpenClaw-Publication: 90ea6a98-3750-4df1-8f07-6333b0ba229c * fix(compaction): free the compaction worker during summary model calls * fix: match compaction concurrency test-line credit to its net growth * perf(compaction): check only captured rows before rerendering summary input * test: align worker containment and Claude fallback tests with main contracts main openclaw#194473 reworded the file-tool containment hint per source and openclaw#196756 compacted tool-result JSON; main openclaw#196459 gave unknown Claude ids mandatory adaptive thinking, so the non-reasoning fallback fixture uses a pre-Claude-5 id. * refactor(compaction): keep preflight metadata in its reader Co-authored-by: RomneyDa <[email protected]> * fix(compaction): detach bounded floor facts from transcript payloads Prevent small excerpts and identifier captures from retaining whole source strings while a compaction plan is cached. Add a GC retention regression for the owning producer. Co-authored-by: RomneyDa <[email protected]> * fix(workers): defer slow idle GC logging imports Keep the slow-GC diagnostic behind its own lazy operation boundary so small workers do not eagerly evaluate the logging graph. Preserve collection thresholds and warning fields. The existing production build gate reproduces 240 identity-worker modules on the base and passes at 203 after the repair (budget 220 unchanged). Full and sourcePerformance builds, 11 focused worker tests, infra typecheck, lint, and format checks pass. Independent native review found no actionable P0/P1/P2 findings; local autoreview was unavailable because Codex was not installed. Co-authored-by: RomneyDa <[email protected]> * fix: complete compaction wrapper inventory Co-authored-by: RomneyDa <[email protected]> --------- Co-authored-by: RomneyDa <[email protected]>
…ith compact JSON - Restore buildBootstrapContextFiles' [MISSING] Expected at: <absolute path> marker so the exported agent-harness-runtime SDK consumer contract is unchanged. Prompt preparation (prepareContextFilesForPrompt) still renders workspace-relative markers via the new missing flag, keeping the cross-workspace prefix-cache parity from openclaw#191485. - Align run-attempt.native-hook-relay.test.ts with compact JSON tool results from openclaw#196756 (main 3d6699c changed payloadTextResult serialization after this branch point; the stale pretty-JSON expectation fails the merged-tree shard).
…ith compact JSON - Restore buildBootstrapContextFiles' [MISSING] Expected at: <absolute path> marker so the exported agent-harness-runtime SDK consumer contract is unchanged. Prompt preparation (prepareContextFilesForPrompt) still renders workspace-relative markers via the new missing flag, keeping the cross-workspace prefix-cache parity from openclaw#191485. - Align run-attempt.native-hook-relay.test.ts with compact JSON tool results from openclaw#196756 (main 3d6699c changed payloadTextResult serialization after this branch point; the stale pretty-JSON expectation fails the merged-tree shard).
) (cherry picked from commit b65961b) Release adaptation: bounded override guard and corresponding regression. Later openclaw#196756 compact JSON output is not a model-resolution prerequisite. Diff check passed; focused tests require missing shared configuration dependency @solidjs/vite-plugin. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 5006a76530e816ec56011dabd5e8aad8ffa91790) (cherry picked from commit 8715be0d6eefe4e4542c2fc0c009301d347f7497)
What Problem This Solves
Tool results built with core
jsonResult/payloadTextResultreach the model as 2-space pretty-printed JSON, which spends model context on indentation for every tool call. Code Mode makes this worse: thedispatch_actionenvelope escapes the indented text a second time. About 116 non-test files calljsonResult. That includes core tools, about 28 bundled plugins, and every feature-plugin tool throughsrc/plugin-sdk/feature-plugin.ts(for example, Knowledge).User Impact
User impact: agents spend roughly 20–25% fewer tokens on the JSON tool results this changes (about 2.5% of interactive and 8% of all transcript tokens in real sessions; see Evidence), with the same data.
details, plugin APIs and config are unchanged. Control UI already renders JSON tool results with its own exact-lexeme JSON viewer, so its display is unchanged; Raw/Copy/Download keep the exact compact text. TUI renders JSON tool output literally instead of as Markdown.Why This Change Was Made
jsonResultandpayloadTextResultinsrc/agents/tools/tool-results.tsnow emitJSON.stringify(payload). This is the single owner of the format. No flag or per-plugin opt-in was added, because no contract needed one: the SDK docs only named the helpers, and they now say the text is compact.Siblings that copied that formatting, or measured budgets against it, now match the text that is actually sent:
compactoption, which only Code Mode passed, is removed. Batch search fitting and thetool_describeinstructions-hint size check measure compact text.sessions_listfitting, the sessions patchresolvedbudget (its redundant pretty check is removed), thepluginstool result, the gatewayconfig.getcap,update.runsummary diagnostics trimming, and lobstermaxStdoutBytes.web_searchbranch,session_statusroute and state-change fenced JSON,ask_userand secrets note payloads, bundle LSP and MCP results, and the feishu, github and llm-task plugin result helpers.Deliberately left unchanged:
registerCommandtext, CLI--jsonoutput, and files written to disk (manifests, evidence, configs).event-projector-tool-items,session-catalog-transcript-item,agentsapi-native-items). They mirror another harness's items for display; they are not OpenClaw tool results sent to the model.context-engine-projectionstableJson. It feeds Codex's rendered-context budget, which has its own owner and tests and needs separate review against the Codex harness.llm-taskinputJson, which is prompt input for a sub-model, not a tool result.extensions/knowledge, where result fields are being trimmed in a separate change.Evidence
Model-visible bytes, measured by running representative payloads through the real helpers (
jsonResult,feishuExternalToolResult,serializeToolSearchControlResult):sessions_list(12 rows,jsonResult)feishuExternalToolResult, external-content wrapped)jsonResult)dispatch_actionenvelope around that resultThe payloads are synthetic, but their shapes match production results. Direct-call tools save the indentation only; nested and Code Mode results also lose the escaped indentation. Separately, re-rendering 6,800 real Knowledge results from a trial cut model-visible size from 57.8M to 44.7M chars (−23%).
Token savings against real sessions
Measured by replaying 996 real local transcripts from the last 10 days (about 330M tokens: interactive dashboard sessions, cron automations and subagents) through current
mainformatting and through this PR. Tokens were counted witho200k_baseas a proxy tokenizer. The baseline already includesmain's compactdispatch_actionenvelope. Shell output, file reads and Code Mode results are unchanged by this PR and count as unchanged.Results this PR changes lose about 22% of their tokens. The largest absolute savings come from
sessions_list(−21%),sessions_history(−15%),tool_describe(−19%) and theknowledge_*tools (−15% to −28%).github_readis large but saves only about 5%, because its results are mostly file contents in a single string. These are transcript-token figures: compaction and prompt caching change billed tokens, but the relative savings should roughly carry over. A result that hits a size cap uses the same tokens and fits more content.Tests run locally with
node scripts/run-vitest.mjs:src/plugin-sdk/tool-results.test.tscovers the compact contract. It fails on the base and passes with this change.ask_user, gateway tool, plugins, secrets, sessions,session_status,web_search, LSP/MCP bundle, feishu, github, llm-task, TUI tool execution and Control UI tool output.sessions_listquery, plugins tool, tool-search runtime, scheduled widget, sessions self-archive, browser, feishu docx table, MCP HTTP question authority, worker gateway tool runtime, and the code-mode-json budget.extensions/voice-call/index.test.ts(EXIT=1, 370s wall). That failure is inherited frommain: the same file fails the same way onb21829a4c85fin a clean worktree ("Voice call service is not running…", service runtime never starts, mock config unset). It does not touch JSON formatting.pnpm check:changedon the final head (1304s): every lane passes except two that are not caused by this PR. The Plugin SDK surface budget fails the same way onmain. The dead-export scan reports only files this PR does not touch.No visual change: Control UI display code is untouched.
CI repair on the final head: the first CI run's failures were all caused by this PR (stale pretty-JSON expectations in
tool-search,mcp-httpandllm-tasktests, a Control UI display reformat that broke the existing exact-lexeme JSON viewer, now reverted, and +4 test lines over the test-lines ratchet, now offset). Focused reruns of every failing file pass locally.