Repository navigation
Conversation
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. This PR is superseded by the stronger open fix at #101952, which targets the same linked mid-turn precheck bug with the provider-boundary projection change and sufficient real behavior proof; this branch remains a narrower constant-only mitigation with insufficient proof for the reported route. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Use #101952, or an equivalent exact-head projection-layer fix, as the canonical landing path and then resolve the narrower alternatives against the landed behavior. So I’m closing this here and keeping the remaining discussion on #101952. Review detailsBest possible solution: Use #101952, or an equivalent exact-head projection-layer fix, as the canonical landing path and then resolve the narrower alternatives against the landed behavior. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main still runs mid-turn precheck on contextMessages while the provider submission path separately applies aggregate tool-result projection, and the linked issue includes concrete logs and billed-usage deltas. I did not rerun the live provider cron scenario. Is this the best way to solve the issue? No. This PR is a plausible mitigation for part of the over-count, but the best fix is the projection-layer approach in #101952 because it estimates the same prompt shape that the provider path sends. Security review: Security review cleared: The diff changes internal TypeScript estimator logic and focused tests only; it does not touch secrets, dependencies, workflows, package scripts, or supply-chain-sensitive surfaces. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against fdc98242a1e5. |
TOOL_RESULT_CHARS_PER_TOKEN was 2 in both tool-result-char-estimator.ts and preemptive-compaction.ts. Tool results (JSON, code output) average ~4-5 chars/token in practice — not 2. The 2 chars/token estimate produced a ~2-2.6× token over-count vs billed usage, triggering mid-turn truncation on turns far below the real context window. Change TOOL_RESULT_CHARS_PER_TOKEN(_ESTIMATE) from 2 to 3 in both files. The estimator ratio drops from 4/2=2.0x to 4/3≈1.33x, and the token pressure estimate changes from chars/2 to chars/3. Fixes openclaw#101929
ff333f4 to
1a9eafe
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
What Problem This Solves
context-overflow-midturn-precheckestimates prompt tokens ~2.3–2.6× above provider-billed usage on tool-result-heavy turns. This fires truncation recovery on turns nowhere near the context window.Fixes #101929.
Root Cause / Fix
Root cause:
TOOL_RESULT_CHARS_PER_TOKENwas2in bothtool-result-char-estimator.tsandrun/preemptive-compaction.ts. Tool results (JSON, code output) average ~4-5 chars/token in practice — not 2. The 2 chars/token estimate:chars × 4/2 = 2×weighted chars, inflating context guard budgetchars / 2, doubling token pressure vs the actualchars / 4-5Both paths contributed to the ~2.3-2.6× over-count.
Fix: Raise both constants from
2to3:tool-result-char-estimator.ts:14:TOOL_RESULT_CHARS_PER_TOKEN_ESTIMATE = 3run/preemptive-compaction.ts:27:TOOL_RESULT_CHARS_PER_TOKEN = 3Evidence
Real behavior proof
Regression suite
Autoreview
oxfmt / oxlint
oxfmt --check— ✅git diff --check— ✅Change Type / Scope / Security Impact
src/agents/embedded-agent-runner/— tool-result token estimator + preemptive compaction