Repository navigation
improve(agents): trim large tool results with less CPU - #148718
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
Codex review: blocked before merge. Reviewed September 14, 2026, 11:30 PM ET / September 15, 2026, 03:30 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR reduces repeated scanning while trimming oversized tool output, retaining existing Unicode-safe cuts and adding coverage for integer and fractional text weights. Merge readiness⛔ Blocked before merge - 2 items remain This remains a distinct, useful optimization candidate with no identified correctness defect. Current main does not implement it, and the scoped performance-validation requirement remains outstanding. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw trims oversized tool results before passing them into model context. The text-budget cutter selects a prefix or diagnostic tail using a shared multilingual character estimator. flowchart LR
A[Tool output] --> B[Tool result truncation]
B --> C[Prefix or tail search]
C --> D[Weighted text estimator]
D --> E[Budget decision]
E --> C
E --> F[Unicode-safe retained text]
F --> G[Model context]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +19, Tests +19. Total +38 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one canonical cutter with unchanged output semantics, retaining incremental accounting where current-estimator measurements demonstrate a worthwhile benefit. Do we have a high-confidence way to reproduce the issue? Yes for the repeated work: current-main source measures overlapping candidates on each search iteration. Its runtime cost and the proposed speedup were not measured in this read-only review. Is this the best way to solve the issue? The ownership and arithmetic are appropriate: the existing cutter reuses additive estimates and preserves fractional rounding. Whether the added bookkeeping is worthwhile remains unclear until current-base performance results are available. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a4a3e5670573. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
* commit 'd8e50a38fd1c4df6dd69bcbc155697c464e1be45': (23 commits) fix(cron): release queued reservations when activation fails (#141008) fix(gateway): reduce CPU work in session lists and searches (#148713) feat(gateway): add admin CPU profile diagnostics (#148004) fix(gateway): cap device-required probe cache to prevent unbounded growth (#147708) fix(ci): align Gateway E2E expectations (#148653) refactor(ai): remove unused overflow wrapper (#148719) feat: stage selected chat text as editable comments (#148649) fix(ci): admit reachable release refs with large histories (#148161) fix(agents): allow authorized email CLI actions (#148521) improve(agents): trim large tool results with less CPU (#148718) refactor(docker): share image version parsing (#148243) fix(ci): retain passing hosted checks after skipped duplicates (#148722) fix(update): report configuration failures during repair (#144819) refactor(imessage): share handle classification (#148229) fix(ui): keep the selected agent across Settings pages (#148667) test(telegram): reuse deferred fixture helper (#148501) fix(media): resize images before understanding (#122431) fix: preserve unfinished work during completed PR cleanup (#148704) refactor(migrate-hermes): reuse canonical config record coercion (#148645) perf(channels): reduce history worker metadata footprint (#148711) ...
What Problem This Solves
Trimming oversized tool results repeatedly scans overlapping text while searching for the retained prefix or tail, adding synchronous CPU work before the model can continue.
User Impact
The same tool-result text, ordering, truncation notices, and Unicode boundaries are preserved. Large-input cutter measurements now show less CPU work; this is not a gateway end-to-end latency claim.
Why This Change Was Made
For the two integer weight floors used by runtime callers, the canonical cutter updates the measured weight using only the interval that changed between candidates. Other floors keep whole-candidate measurement to preserve per-ASCII-run rounding. The search and its final UTF-16-safe cuts stay unchanged.
Production: +20/-1 lines (net +19) for the incremental measurement state and non-additive rounding branch; tests: +29/-10 lines (net +19). Regression coverage exercises prefix/tail boundaries, fractional-floor rounding, and head-plus-tail truncation with mixed Unicode.
Evidence
Exact head
67bfe84f563340f14b37e0b6905ed448ae38f3fdversus baseb45506d663b5c8a84a9b9ae327e098ef348ff193, using the same current estimator and UTF-16 helper in both variants. Independent source review found no actionable P0–P2 defect.0x67bfe. Covers ASCII, CJK, supplementary characters, emoji, unpaired surrogates, fractional floors, and negative/nonfinite bounds.414782450952a196bbb64b1605a458c2531c47b6: protocol content items and success, lines 61–62 and ordered FunctionToolOutput conversion, lines 152–162. Public source bytes match the inspected sibling checkout; text order and success propagation are unchanged.Measured on Blacksmith Testbox, Linux x64, Node 24.19.0, AMD EPYC, four available CPUs, on 2026-09-15. The native measurement receipt attested this head and source tree
b0458605eb94e9e236b9b2525151eebfa6a75d77(measurement carrier6cc17ff7e5946b321f368269eee5c19181d10eb7). Leasetbx_01m2hhjp1cjvzrhc55e3925j6zcompleted successfully and was stopped.64 timing scenarios use two warm batches and four alternating baseline/candidate samples. Table values are wall-clock microseconds per call, spanning both directions and integer floors:
The worst 32-unit regression was 0.0501 µs/call. Fitting-input ratios ranged 0.979–1.089 (median 1.001), so these samples do not establish an improvement for already-fitting input. No extra small-input branch was added.
A separate 400-cut mixed-text workload ran in four fresh processes, baseline/candidate/candidate/baseline:
Peak RSS includes parsing, estimator lookup initialization, and warmup. The ranges overlap; no retained-allocation or memory-reduction claim is made. This is bounded cutter proof, not a production profile or end-to-end benchmark.
ClawSweeper follow-through: the exact-head review found no code defect. Its requested current-estimator CPU/RSS, short-input tradeoff, and parity evidence—and the same Rank-up move—are addressed above. The measured large-input benefit supports keeping the canonical incremental path; fractional rounding stays unchanged. No source change or rating-only re-review is needed. Exact-head CI run 34924254509 completed successfully; required checks are green. Independent review also verified the captured measurements and test receipts.