fix(agents): skip pre-prompt precheck when context engine owns compaction#95342
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 30, 2026, 3:46 AM ET / 07:46 UTC. Summary PR surface: Source +17, Tests +169, Docs +2. Total +188 across 5 files. Reproducibility: yes. at source/proof level: current main and v2026.6.10 run the generic precheck for owning context-engine prompt submissions, and the PR body includes before-failure details plus after-fix logs from a lossless-claw setup. I did not run the contributor's live setup in this read-only review. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land only after context-engine maintainers accept that owning engines manage prompt admission by default; otherwise preserve an assembled-prompt precheck and resolve the CJK false-positive estimator path separately. Do we have a high-confidence way to reproduce the issue? Yes, at source/proof level: current main and v2026.6.10 run the generic precheck for owning context-engine prompt submissions, and the PR body includes before-failure details plus after-fix logs from a lossless-claw setup. I did not run the contributor's live setup in this read-only review. Is this the best way to solve the issue? Yes, conditionally: this is a coherent owner-boundary fix if maintainers accept that owning engines manage prompt admission. If not, the safer alternative is to preserve an assembled-prompt precheck and fix CJK estimation separately. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 56c2d637d940. Label changesLabel justifications:
Evidence reviewedPR surface: Source +17, Tests +169, Docs +2. Total +188 across 5 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
|
ff7c508 to
0eeba50
Compare
a3a7935 to
9ced576
Compare
9ced576 to
6e36ce5
Compare
6e36ce5 to
ddc69d6
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@jalehman Could you review this when you get a chance? This fixes false-positive precheck overflow for CJK-heavy sessions when lossless-claw (ownsCompaction) is active. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@jalehman all checks have passed |
|
@jalehman Should we skip this precheck for the LCM context engine, or fix the local token estimation? |
…tion When a context engine advertises ownsCompaction=true (e.g. lossless-claw), skip the pre-prompt preemptive overflow precheck entirely. The engine already manages the context budget through assemble() and its own compaction lifecycle — the built-in precheck is redundant and causes false-positive overflow errors for CJK-heavy sessions due to its conservative token estimation formula. Safety is preserved: if the model's actual context limit is exceeded, the model API returns an error that the outer overflow-compaction retry loop handles normally.
6a3891d to
14d361b
Compare
|
Merged via squash.
|
…tion (openclaw#95342) * fix(agents): skip pre-prompt precheck when context engine owns compaction When a context engine advertises ownsCompaction=true (e.g. lossless-claw), skip the pre-prompt preemptive overflow precheck entirely. The engine already manages the context budget through assemble() and its own compaction lifecycle — the built-in precheck is redundant and causes false-positive overflow errors for CJK-heavy sessions due to its conservative token estimation formula. Safety is preserved: if the model's actual context limit is exceeded, the model API returns an error that the outer overflow-compaction retry loop handles normally. * fix(agents): assert non-null context engine in precheck skip log * test(context-engine): cover owning precheck contract * fix(agents): preserve precheck after context assembly failure --------- Co-authored-by: Josh Lehman <[email protected]>
…tion (openclaw#95342) * fix(agents): skip pre-prompt precheck when context engine owns compaction When a context engine advertises ownsCompaction=true (e.g. lossless-claw), skip the pre-prompt preemptive overflow precheck entirely. The engine already manages the context budget through assemble() and its own compaction lifecycle — the built-in precheck is redundant and causes false-positive overflow errors for CJK-heavy sessions due to its conservative token estimation formula. Safety is preserved: if the model's actual context limit is exceeded, the model API returns an error that the outer overflow-compaction retry loop handles normally. * fix(agents): assert non-null context engine in precheck skip log * test(context-engine): cover owning precheck contract * fix(agents): preserve precheck after context assembly failure --------- Co-authored-by: Josh Lehman <[email protected]>
…tion (openclaw#95342) * fix(agents): skip pre-prompt precheck when context engine owns compaction When a context engine advertises ownsCompaction=true (e.g. lossless-claw), skip the pre-prompt preemptive overflow precheck entirely. The engine already manages the context budget through assemble() and its own compaction lifecycle — the built-in precheck is redundant and causes false-positive overflow errors for CJK-heavy sessions due to its conservative token estimation formula. Safety is preserved: if the model's actual context limit is exceeded, the model API returns an error that the outer overflow-compaction retry loop handles normally. * fix(agents): assert non-null context engine in precheck skip log * test(context-engine): cover owning precheck contract * fix(agents): preserve precheck after context assembly failure --------- Co-authored-by: Josh Lehman <[email protected]>
…tion (openclaw#95342) * fix(agents): skip pre-prompt precheck when context engine owns compaction When a context engine advertises ownsCompaction=true (e.g. lossless-claw), skip the pre-prompt preemptive overflow precheck entirely. The engine already manages the context budget through assemble() and its own compaction lifecycle — the built-in precheck is redundant and causes false-positive overflow errors for CJK-heavy sessions due to its conservative token estimation formula. Safety is preserved: if the model's actual context limit is exceeded, the model API returns an error that the outer overflow-compaction retry loop handles normally. * fix(agents): assert non-null context engine in precheck skip log * test(context-engine): cover owning precheck contract * fix(agents): preserve precheck after context assembly failure --------- Co-authored-by: Josh Lehman <[email protected]>
…tion (openclaw#95342) * fix(agents): skip pre-prompt precheck when context engine owns compaction When a context engine advertises ownsCompaction=true (e.g. lossless-claw), skip the pre-prompt preemptive overflow precheck entirely. The engine already manages the context budget through assemble() and its own compaction lifecycle — the built-in precheck is redundant and causes false-positive overflow errors for CJK-heavy sessions due to its conservative token estimation formula. Safety is preserved: if the model's actual context limit is exceeded, the model API returns an error that the outer overflow-compaction retry loop handles normally. * fix(agents): assert non-null context engine in precheck skip log * test(context-engine): cover owning precheck contract * fix(agents): preserve precheck after context assembly failure --------- Co-authored-by: Josh Lehman <[email protected]>
What Problem This Solves
The pre-prompt preemptive overflow precheck uses a built-in token estimation formula that overestimates CJK (Chinese) tool-result content by ~2.5x (
TOOL_RESULT_CHARS_PER_TOKEN=2combined with CJK 4x char inflation). This causes false-positive "Auto-compaction could not recover this turn" errors for context engines like lossless-claw that already manage context budgets accurately.When a context engine declares
ownsCompaction: true, it already:assemble()with accurate token countingshouldDisableAgentAutoCompaction)afterTurn()before context grows too largeThe pre-prompt precheck is redundant for these engines and actively harmful when its estimation formula disagrees with the engine's accurate token counting.
Summary
shouldPreemptivelyCompactBeforePrompt()whenactiveContextEngine?.info.ownsCompaction === true[context-overflow-precheck] skipped: context engine "..." owns compactionfor observabilityrunEmbeddedAgentstill handles real model API overflow errorsEvidence
Real log output after fix (2026-06-20T22:57 local):
{ "time": "2026-06-20T22:57:44.111+08:00", "logLevelName": "INFO", "message": "[context-overflow-precheck] skipped: context engine \"lossless-claw\" owns compaction", "traceId": "f2b42c377940b005e61c07e9198b373f" } { "time": "2026-06-20T22:57:50.427+08:00", "logLevelName": "INFO", "message": "[context-overflow-precheck] skipped: context engine \"lossless-claw\" owns compaction", "traceId": "e374769e6e3660e577a4d6c607145a7c" }Config (
~/.openclaw/openclaw.json) confirming context engine:{ "plugins": { "slots": { "contextEngine": "lossless-claw" }, "entries": { "lossless-claw": { "enabled": true } } } }Before fix — session
8fa61d8f(same config, lossless-claw active):Unit test (
run.overflow-compaction.loop.test.ts):Architectural consistency:
shouldDisableAgentAutoCompaction()atagent-settings.ts:195already skips runtime auto-compaction forownsCompaction: true. This PR extends the same principle to the pre-prompt precheck.Security Impact
All No.
Compatibility
Backward compatible. Only affects sessions with an active context engine that declares
ownsCompaction: true. Sessions without a context engine or withownsCompaction: falseare unchanged.