[codex] Honor disabled compression for reactive compaction (#9200)

Validated in local merge-train (devbox-vm-06-dev002) @ combined-tip (FAST gates green: static + changed tests + vitest — only pre-existing audit.test.ts flake). Evidence: /home/diegosouzapw/dev/proxys/OmniRoute/.claude/worktrees/merge-train-20260805-213228-suite.log
This commit is contained in:
Joachim Brindeau
2026-08-06 02:44:44 +02:00
committed by GitHub
parent db12943146
commit d5aa7e318f
3 changed files with 28 additions and 2 deletions

View File

@@ -0,0 +1 @@
- **fix(compression):** honor the global compression-off setting for proactive and last-resort context compaction, preventing disabled compression from rewriting tool-call histories ([#9200](https://github.com/diegosouzapw/OmniRoute/pull/9200)) — thanks @joachimBrindeau

View File

@@ -1092,6 +1092,10 @@ export async function handleChatCore({
// settings read below, then threaded to executor.execute() further down. Lives at
// function scope because the read happens inside the per-message compression block.
let contextEditingEnabled = false;
// The dashboard's global compression switch must also control the built-in
// reactive and last-resort compaction passes. Otherwise an operator selecting
// "off" still has large histories rewritten by trim_tools/purify_history.
let reactiveContextCompactionEnabled = false;
// Hoisted to function scope (not just the compression-block scope below) so the
// combo-resolved override survives to the final enforceOutputTokenBudget() call
// further down — see #8378 (context limit resolved by the combo was silently
@@ -1108,6 +1112,7 @@ export async function handleChatCore({
compressionSettings?.exclusions
);
let promptCompressionEnabled = compressionSettingsResult.enabled && !compressionExcluded;
reactiveContextCompactionEnabled = compressionSettingsResult.enabled && !compressionExcluded;
contextEditingEnabled = compressionSettingsResult.contextEditingEnabled;
if (compressionExcluded) {
void writeCompressionSkip(
@@ -1757,7 +1762,7 @@ export async function handleChatCore({
// engines (Caveman/RTK). Codex Desktop / Responses clients need this path even
// when those engines are off, otherwise multi-turn image sessions hard-reject
// at the budget check below (#8560).
if (estimatedTokens > threshold) {
if (reactiveContextCompactionEnabled && estimatedTokens > threshold) {
log?.info?.(
"CONTEXT",
`Proactive compression triggered: ${estimatedTokens} tokens > ${threshold} threshold (${contextLimit} limit)`
@@ -1848,7 +1853,7 @@ export async function handleChatCore({
// Last-resort compaction against the concrete input budget (not the 70% threshold).
// Covers cases where the proactive pass was skipped or still left the request oversized (#8560).
if (finalEstimatedInputTokens >= finalContextLimit && body) {
if (reactiveContextCompactionEnabled && finalEstimatedInputTokens >= finalContextLimit && body) {
const lastResortTarget = Math.max(1, finalContextLimit - toolsReserve - 1);
const lastResortAdapter = adaptBodyForCompression(body as Record<string, unknown>);
const lastResortResult = compressContext(lastResortAdapter.body, {

View File

@@ -0,0 +1,20 @@
import assert from "node:assert/strict";
import test from "node:test";
import { readFileSync } from "node:fs";
const source = readFileSync(
new URL("../../open-sse/handlers/chatCore.ts", import.meta.url),
"utf8"
);
test("global compression off gates reactive and last-resort context compaction", () => {
assert.match(
source,
/reactiveContextCompactionEnabled\s*=\s*compressionSettingsResult\.enabled\s*&&\s*!compressionExcluded;/
);
assert.match(source, /reactiveContextCompactionEnabled\s*&&\s*estimatedTokens\s*>\s*threshold/);
assert.match(
source,
/reactiveContextCompactionEnabled\s*&&\s*finalEstimatedInputTokens\s*>=\s*finalContextLimit/
);
});