Repository navigation
fix: CJK tool results stay within context budgets - #114755
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 27, 2026, 6:26 PM ET / 22:26 UTC. ClawSweeper reviewWhat this changesThe PR makes tool-result trimming CJK-aware and UTF-16-safe across live prompt truncation and the context guard, adds unit and Gateway QA coverage, and simplifies an auto-reply test harness to preload mocked runtime seams. Merge readinessThis remains a useful fix for the linked CJK context-budget bug. The refreshed branch appears to route the affected truncation and guard paths through one weighted, UTF-16-safe helper, carries focused regression coverage and a real Gateway QA claim, and has no concrete patch defect from the supplied diff; its protected Priority: P2 Review scores
Verification
How this fits togetherEmbedded-agent tool results are generated by tools and then projected into the next provider request. This change measures and slices that text consistently before live truncation, aggregate recovery, and the mid-turn context guard send bounded content back to the model. flowchart LR
A[Tool result text] --> B[Shared weighted text budget]
B --> C[Live truncation]
B --> D[Aggregate recovery]
B --> E[Context guard]
C --> F[Provider-bound prompt]
D --> F
E --> F
F --> G[Next model turn]
Decision needed
Why: The supplied patch and proof are strong enough to avoid inventing an automated repair, but the protected label and current-base drift reserve the final merge decision for maintainers. Before merge
Agent review detailsSecurityNone. PR surfaceSource +167, Tests +182, Other +101. Total +450 across 10 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one shared weighted budget abstraction for every provider-bound tool-result path, rebase it onto current Do we have a high-confidence way to reproduce the issue? Yes. The linked report provides a concrete dense-CJK tool-result path, and the branch adds a Gateway QA scenario that drives the same provider-bound truncation behavior; this review did not execute the scenario itself. Is this the best way to solve the issue? Yes. Sharing one weighted, UTF-16-safe budget helper across live truncation and the context guard is narrower and less drift-prone than applying separate CJK multipliers to each path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0073862e232b. 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
History |
Use one weighted, UTF-16-safe budget across live truncation, aggregate recovery, persisted sessions, and the mid-turn context guard. Preserve ASCII behavior, bound mixed blocks, and add a real Gateway QA scenario.\n\nFixes #103847.
3f1d080 to
ad26208
Compare
|
Rank-up move reviewed: this branch was rebased onto
|
|
Merged via squash.
|
* fix(agents): make tool-result budgets CJK-aware Use one weighted, UTF-16-safe budget across live truncation, aggregate recovery, persisted sessions, and the mid-turn context guard. Preserve ASCII behavior, bound mixed blocks, and add a real Gateway QA scenario.\n\nFixes openclaw#103847. * fix(agents): satisfy tool-budget lint * test(qa): require exact CJK scenario reply * test(auto-reply): preload reply runtimes without a synthetic turn
Closes #103847
AI-assisted. Thanks to @yetval for the precise report and source reproduction.
What Problem This Solves
Fixes an issue where CJK-heavy tool output could consume up to roughly four times the intended context budget because live truncation, aggregate prompt budgeting, persisted recovery, and the mid-turn guard did not share language-aware accounting.
The same multi-block allocator could also exceed its total cap through independent minimums, starve later blocks, spend suffix budget on empty blocks, and underreport omissions in suffix-only truncation.
Why This Change Was Made
This introduces one canonical CJK-aware, UTF-16-safe budget-and-slice abstraction and routes every affected tool-result path through it. ASCII behavior and the context guard's existing safety floor remain intact, while the allocator now owns one bounded total budget across all text blocks.
The committed QA scenario exercises a real Gateway agent loop through qa-channel and the mock provider, then inspects the provider-bound tool result rather than relying only on helper tests. Its final marker check requires exact trimmed equality to avoid false-positive live proof.
During exact-head CI, an unrelated 3,545-line auto-reply suite timed out while sequentially importing modules and running a synthetic reply in
beforeAll. The test harness now uses normal mocked imports and preloads the three real lazy runtime seams in parallel, removing the synthetic turn and its registry/session side effects instead of merely extending the timeout.User Impact
CJK-heavy tool sessions now stay within the same context-pressure limits as ASCII-heavy sessions, reducing avoidable overflow, compaction, and lost-progress behavior. Mixed and multi-block tool results also remain within their declared aggregate cap without starving later output.
Evidence
CJK-TOOL-RESULT-OKin 20.4 seconds.git diff --checkgates passed.large-7CI shard passed on both refreshed heads.