Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions config/quality/file-size-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@
"open-sse/handlers/search.ts": 1546,
"open-sse/handlers/sseParser.ts": 830,
"open-sse/handlers/videoGeneration.ts": 1275,
"open-sse/mcp-server/schemas/tools.ts": 1497,
"_rebaseline_2026_07_22_8010_codex_responses_engine": "PR #8010 (@JxnLexn) own growth: open-sse/mcp-server/schemas/tools.ts 1497->1505 (+8 = threading the new \"codex-responses\" literal into the compressionConfigureInput strategy/autoTriggerMode Zod enums and setCompressionEngineInput engine enum, mirroring the existing rtk/omniglyph enum entries; no new tool). open-sse/services/compression/strategySelector.ts 1043->1054 (+11 = one new `if (mode === \"codex-responses\")` dispatch branch in runCompression that delegates 100% to the new codexResponsesEngine.apply, mirroring the existing rtk single-mode dispatch, plus threading config.codexResponsesConfig.preserveToolNames into the shared adaptBodyForCompression call at the 3 existing call sites). src/lib/db/compression.ts (untracked, new-file cap 800) 794->845 (+51 = normalizeCodexResponsesConfig, mirroring the existing normalizeRtkConfig normalizer, plus registering \"codex-responses\" in the COMPRESSION_MODES/STACKED_PIPELINE_ENGINE_IDS/SINGLE_MODE_ENGINE sets and the getCompressionSettings load/save switch) — added to the baseline at its current size. All three are cohesive dispatch/normalizer wiring at existing chokepoints (mirroring the prior compression-mode rebaselines #6534/#6556), not extractable without hiding the mode-dispatch boundary. Covered by tests/unit/compression/codex-responses.test.ts (6) + omniglyph-registries.test.ts/types.test.ts (22, updated for the new mode).",
"src/lib/db/compression.ts": 845,
"open-sse/mcp-server/schemas/tools.ts": 1505,
"open-sse/mcp-server/server.ts": 1555,
"open-sse/mcp-server/tools/advancedTools.ts": 1120,
"_rebaseline_2026_06_27_5193_antigravity_basered": "Base-red (pre-existing release drift, fast-gate PR->release skips check:file-size): accountFallback.ts 1773->1777 and src/app/api/providers/[id]/test/route.ts 924->940 were already over their frozen caps on release/v3.8.39 independent of any antigravity change. Owner chose to rebaseline (keep the documented issue-reference comments #1846/#1449/#347 etc.) rather than accept the contributor comment-stripping in #5200/#5198. Reverted #5200 to restore the comments; bumped these two frozen caps to the actual base sizes. No logic change.",
Expand All @@ -194,7 +196,7 @@
"_rebaseline_2026_06_26_fidelity_gate_extraction": "Milestone-B fidelity-gate wiring residual: bodyToText+gateAdvance extracted to fidelityGateStep.ts (889->854, -35), but the StackOptions.fidelityGate field, the `const fidelityGate` reads at the two stacked-loop dispatch chokepoints, and the import of FidelityGateConfig are irreducible wiring that cannot leave strategySelector without an architectural refactor of the pre-existing stacked pipeline. Net: 889->854 (+6 vs the pre-Milestone-B frozen 848). Covered by tests/unit/compression/*.test.ts (940 pass).",
"_rebaseline_2026_06_28_5243_risk_gate_prepass": "PR #5243 (compression risk-gate pre-pass) own growth: open-sse/services/compression/strategySelector.ts 854->899 (+45). The three exported entry points (applyCompression/applyStackedCompression/applyStackedCompressionAsync) become thin wrappers over pure-extracted private bodies (runCompression/runStackedCompression/runStackedCompressionAsync) so the risk-gate mask->run->restore wrapper sits strictly OUTSIDE the per-step loop — a single universal integration point. The wrapper logic itself (resolveRiskGate/withRiskGate) lives in the new riskGate/strategyWrap.ts (<cap); the residual growth is the duplicated thin-wrapper signatures + the extracted bodies' dispatch boundary, guarded by a byte-identical parity test (riskGateIntegration). Default off (DEFAULT_COMPRESSION_CONFIG unchanged). Not extractable without hiding the dispatch boundary, mirroring prior compression rebaselines. Structural shrink tracked in #3501.",
"_rebaseline_2026_06_29_5286_memoization": "PR #5286 own growth: strategySelector.ts 899->960 (+61 = the opt-in result-memoization branches in applyCompression/applyCompressionAsync — principal+determinism gate, makeMemoKey lookup/store with model+supportsVision folded into the key, recompute-with-memo-off). Default off (memoizeCompressionResults), so zero behavior change. The memo helpers live in the leaf resultMemo.ts (<cap); the chokepoint wiring here is not extractable. Structural shrink of this hot-path file tracked in #3501.",
"open-sse/services/compression/strategySelector.ts": 1043,
"open-sse/services/compression/strategySelector.ts": 1054,
"_rebaseline_2026_07_10_gcf_v3_2_decode": "PR #6838 own growth: new vendored file open-sse/services/compression/engines/headroom/gcf/decode_generic.ts frozen at 880 (> 800 cap). It is the vendored GCF generic-profile decoder (spec v3.2 nested flattening plus the prototype-pollution / hasOwnProperty hardening added in this PR's Gemini review). Kept as one file faithful to upstream gcf-typescript so re-vendoring stays a clean copy rather than a re-split each cycle (sibling generic.ts/scalar.ts stay < cap; extraction would also fragment the file's frozen eslint no-explicit-any suppressions). Round-trip + prototype-pollution regression coverage in tests/unit/compression/headroom-smartcrusher.test.ts. Frozen: only shrinks from here.",
"open-sse/services/compression/engines/headroom/gcf/decode_generic.ts": 880,
"open-sse/services/rateLimitManager.ts": 1035,
Expand Down
28 changes: 24 additions & 4 deletions open-sse/mcp-server/schemas/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1095,11 +1095,31 @@ export const compressionStatusTool: McpToolDefinition<
export const compressionConfigureInput = z.object({
enabled: z.boolean().optional(),
strategy: z
.enum(["off", "lite", "standard", "aggressive", "ultra", "rtk", "stacked", "omniglyph"])
.enum([
"off",
"lite",
"standard",
"aggressive",
"ultra",
"rtk",
"codex-responses",
"stacked",
"omniglyph",
])
.optional()
.describe("Compression mode"),
autoTriggerMode: z
.enum(["off", "lite", "standard", "aggressive", "ultra", "rtk", "stacked", "omniglyph"])
.enum([
"off",
"lite",
"standard",
"aggressive",
"ultra",
"rtk",
"codex-responses",
"stacked",
"omniglyph",
])
.optional(),
maxTokens: z
.number()
Expand Down Expand Up @@ -1132,7 +1152,7 @@ export const compressionConfigureTool: McpToolDefinition<
> = {
name: "omniroute_compression_configure",
description:
"Configure compression settings at runtime. Supports enabling/disabling compression, changing strategy (off/lite/standard/aggressive/ultra/rtk/stacked), adjusting maxTokens threshold, targetRatio, auto-trigger mode, system prompt preservation, and MCP description compression.",
"Configure compression settings at runtime. Supports enabling/disabling compression, changing strategy (off/lite/standard/aggressive/ultra/rtk/codex-responses/stacked), adjusting maxTokens threshold, targetRatio, auto-trigger mode, system prompt preservation, and MCP description compression.",
inputSchema: compressionConfigureInput,
outputSchema: compressionConfigureOutput,
scopes: ["write:compression"],
Expand All @@ -1142,7 +1162,7 @@ export const compressionConfigureTool: McpToolDefinition<
};

export const setCompressionEngineInput = z.object({
engine: z.enum(["off", "caveman", "rtk", "stacked"]).optional(),
engine: z.enum(["off", "caveman", "rtk", "codex-responses", "stacked"]).optional(),
Comment thread
JxnLexn marked this conversation as resolved.
Resolved
cavemanIntensity: z.enum(["lite", "full", "ultra"]).optional(),
rtkIntensity: z.enum(["minimal", "standard", "aggressive"]).optional(),
outputMode: z.boolean().optional(),
Expand Down
21 changes: 17 additions & 4 deletions open-sse/mcp-server/tools/compressionTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,26 +428,39 @@ export async function handleSetCompressionEngine(
args: z.infer<typeof setCompressionEngineInput>
): Promise<{ success: boolean; settings: Record<string, unknown> }> {
const updates: Record<string, unknown> = { enabled: true };
const current = await getCompressionSettings();
if (args.engine) {
updates.defaultMode = args.engine === "caveman" ? "standard" : args.engine;
if (args.engine === "off") updates.enabled = false;
if (args.engine === "off") {
updates.enabled = false;
} else if (args.engine !== "stacked") {
const selectedEngine = args.engine === "caveman" ? "caveman" : args.engine;
updates.engines = Object.fromEntries(
Object.entries(current.engines).map(([id, toggle]) => [
id,
{
...toggle,
enabled: id === selectedEngine,
...(id === "caveman" && args.cavemanIntensity ? { level: args.cavemanIntensity } : {}),
...(id === "rtk" && args.rtkIntensity ? { level: args.rtkIntensity } : {}),
},
])
);
}
}
if (args.cavemanIntensity) {
const current = await getCompressionSettings();
updates.cavemanConfig = {
...(current.cavemanConfig ?? {}),
intensity: args.cavemanIntensity,
};
}
if (args.rtkIntensity) {
const current = await getCompressionSettings();
updates.rtkConfig = {
...(current.rtkConfig ?? {}),
intensity: args.rtkIntensity,
};
}
if (args.outputMode !== undefined) {
const current = await getCompressionSettings();
updates.cavemanOutputMode = {
...(current.cavemanOutputMode ?? {}),
enabled: args.outputMode,
Expand Down
88 changes: 84 additions & 4 deletions open-sse/services/compression/bodyAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ type MessageLike = {
[key: string]: unknown;
};

export const CODEX_RESPONSE_ITEM_META = Symbol("codexResponseItemMeta");

export type CodexResponseItemMeta = {
type: string;
eligible: boolean;
};

type CodexMessageLike = MessageLike & {
[CODEX_RESPONSE_ITEM_META]?: CodexResponseItemMeta;
};

type ResponsesItem = {
type?: unknown;
role?: unknown;
Expand All @@ -18,6 +29,8 @@ const RESPONSES_MESSAGE_TYPES = new Set([
"message",
"function_call_output",
"custom_tool_call_output",
"local_shell_call_output",
"apply_patch_call_output",
]);
const COMPRESSION_INPUT_INDEX = Symbol("compressionInputIndex");

Expand Down Expand Up @@ -100,11 +113,16 @@ function responsesToolOutputField(item: ResponsesItem): "output" | "content" {
return item.output !== null && item.output !== undefined ? "output" : "content";
}

function responsesItemToMessage(item: ResponsesItem): MessageLike | null {
function responsesItemToMessage(item: ResponsesItem): CodexMessageLike | null {
const type = typeof item.type === "string" ? item.type : "message";
if (!RESPONSES_MESSAGE_TYPES.has(type)) return null;

if (type === "function_call_output" || type === "custom_tool_call_output") {
if (
type === "function_call_output" ||
type === "custom_tool_call_output" ||
type === "local_shell_call_output" ||
type === "apply_patch_call_output"
) {
const rawOutput = item.output ?? item.content;
// OpenAI Responses shape (Codex): body.input holds Responses items. When
// output is a JSON object (not a string or content array), serialise it so
Expand All @@ -123,6 +141,7 @@ function responsesItemToMessage(item: ResponsesItem): MessageLike | null {
: isObjectOutput
? JSON.stringify(rawOutput)
: toChatContent(rawOutput),
[CODEX_RESPONSE_ITEM_META]: { type, eligible: false },
};
}

Expand All @@ -132,9 +151,65 @@ function responsesItemToMessage(item: ResponsesItem): MessageLike | null {
};
}

const DEFAULT_CODEX_PROTECTED_TOOL_NAMES = new Set([
"read",
"glob",
"grep",
"write",
"edit",
"websearch",
"webfetch",
"web_search",
"web_fetch",
]);
function markCodexResponseEligibility(
messages: CodexMessageLike[],
inputItems: unknown[],
preserveToolNames: string[] = []
): void {
const protectedNames = new Set([
...DEFAULT_CODEX_PROTECTED_TOOL_NAMES,
...preserveToolNames.map((name) => name.trim().toLowerCase()),
]);
const functionCalls = new Map<string, string>();
const skippedCallIds = new Set<string>();
for (const raw of inputItems) {
if (!isRecord(raw) || raw.type !== "function_call") continue;
if (typeof raw.call_id !== "string" || raw.call_id.length === 0) continue;
const name = typeof raw.name === "string" ? raw.name : "";
functionCalls.set(raw.call_id, name);
if (
protectedNames.has(name.trim().toLowerCase()) ||
name === "headless_retrieval" ||
name.endsWith("__headless_retrieval")
) {
skippedCallIds.add(raw.call_id);
}
}

for (const message of messages) {
const meta = message[CODEX_RESPONSE_ITEM_META];
if (!meta) continue;
if (meta.type === "local_shell_call_output" || meta.type === "apply_patch_call_output") {
meta.eligible = true;
continue;
}
if (meta.type !== "function_call_output") continue;
const rawIndex = message[COMPRESSION_INPUT_INDEX];
const rawItem = typeof rawIndex === "number" ? inputItems[rawIndex] : null;
const callId = isRecord(rawItem) && typeof rawItem.call_id === "string" ? rawItem.call_id : "";
meta.eligible = callId.length > 0 && functionCalls.has(callId) && !skippedCallIds.has(callId);
}
}

function messageToResponsesItem(message: MessageLike, originalItem: ResponsesItem): ResponsesItem {
const type = typeof originalItem.type === "string" ? originalItem.type : "message";
if (type === "function_call_output" || type === "custom_tool_call_output") {
if (
type === "function_call_output" ||
type === "custom_tool_call_output" ||
type === "local_shell_call_output" ||
type === "apply_patch_call_output"
) {
const outputField = responsesToolOutputField(originalItem);
const originalOutput = originalItem[outputField];
return {
Expand Down Expand Up @@ -166,7 +241,10 @@ export type CompressionBodyAdapter = {
restore(compressedBody: Record<string, unknown>): Record<string, unknown>;
};

export function adaptBodyForCompression(body: Record<string, unknown>): CompressionBodyAdapter {
export function adaptBodyForCompression(
body: Record<string, unknown>,
preserveToolNames: string[] = []
): CompressionBodyAdapter {
if (Array.isArray(body.messages)) {
return {
body,
Expand Down Expand Up @@ -205,6 +283,8 @@ export function adaptBodyForCompression(body: Record<string, unknown>): Compress
messages.push({ ...message, [COMPRESSION_INPUT_INDEX]: index });
});

markCodexResponseEligibility(messages, inputItems, preserveToolNames);

if (messages.length === 0) {
return {
body,
Expand Down
10 changes: 3 additions & 7 deletions open-sse/services/compression/deriveDefaultPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ const SINGLE_MODE_OF: Record<string, string> = {
aggressive: "aggressive",
ultra: "ultra",
rtk: "rtk",
"codex-responses": "codex-responses",
omniglyph: "omniglyph",
};

export type CompressionSource =
| "request-header"
| "routing-override"
| "active-profile"
| "auto-trigger"
| "default"
| "off";
"request-header" | "routing-override" | "active-profile" | "auto-trigger" | "default" | "off";

export interface DerivedPlan {
mode: string;
Expand All @@ -37,7 +33,7 @@ export interface DerivedPlan {
*/
export function deriveDefaultPlan(
engines: Record<string, EngineToggle>,
masterEnabled: boolean,
masterEnabled: boolean
): DerivedPlan {
if (!masterEnabled) return { mode: "off", stackedPipeline: [] };

Expand Down
17 changes: 15 additions & 2 deletions open-sse/services/compression/engineCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export interface EngineMeta {
id: string;
label: string;
stackPriority: number;
levels?: string[]; // intensity options; undefined = no level selector
isSingleMode: boolean; // can be the effective mode when it is the only engine on
levels?: string[]; // intensity options; undefined = no level selector
isSingleMode: boolean; // can be the effective mode when it is the only engine on
description: string;
guidance: EngineGuidance;
}
Expand Down Expand Up @@ -82,6 +82,19 @@ export const ENGINE_CATALOG: Record<string, EngineMeta> = {
cacheImpact: "moderate",
},
},
"codex-responses": {
Comment thread
JxnLexn marked this conversation as resolved.
Resolved
id: "codex-responses",
label: "Responses Tool Output",
stackPriority: 12,
isSingleMode: true,
description: "Conservative compression for supported Responses tool outputs.",
guidance: {
tradeoffs:
"Lossless-first JSON and bounded diagnostic compression for shell, patch, search, and build outputs. Protected tools and uncertain shapes pass through unchanged.",
lossy: true,
cacheImpact: "low",
},
},
headroom: {
id: "headroom",
label: "Headroom",
Expand Down
Loading
Loading