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
5 changes: 3 additions & 2 deletions config/quality/file-size-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,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": 1022,
"open-sse/services/compression/strategySelector.ts": 1025,
"open-sse/services/rateLimitManager.ts": 1035,
"_rebaseline_2026_06_29_4038_cas_guard": "PR (#4038) own growth: tokenRefresh.ts 2103->2181 (+78 = the compare-and-swap guard on the refresh persist — runWithCasGuard/getActiveCasGuard AsyncLocalStorage pair mirroring runWithOnPersist, casGuardShouldSkipPersist that rereads the row right before persisting and skips the write when a concurrent writer already rotated the refresh_token past the one presented, plus getCasGuardStats counters). Fixes the sibling-rotation-revert → token-family-revocation storm. Gated behind an active guard (opt-in; no guard => byte-identical). Wiring lives at the two persist chokepoints inside getAccessToken; the comparison reuses wasRefreshTokenRotated from refreshSerializer. Not extractable without splitting the refresh hot path.",
"open-sse/services/tokenRefresh.ts": 2181,
Expand Down Expand Up @@ -384,5 +384,6 @@
"_rebaseline_2026_07_06_6499_unique_default_name": "PR #6499 own growth: AddApiKeyModal.tsx 952->959 (+7 = a unique default connection name so a second API key for the same provider does not reuse 'main' and trigger the backend name-based upsert that silently overwrote the first connection). The pure name derivation was extracted to computeConnectionDefaultName.ts (unit-tested) to keep the growth minimal; the contributor's original full-form-reset rewrite was trimmed to a spread reset to avoid dropping the GLM team-quota fields #6351 added and to hold the frozen god-file growth down. Release captain rebaseline-at-release supersedes.",
"_rebaseline_2026_07_07_6523_chirag_cooldown_body": "PR #6523 (@chirag127, #6460) own growth: chatHelpers.ts 860->866 (+6 = retryAfterAt/credentialsCoolingCount fields on modelCooldownResponse) and auth.ts 2447->2448 (+1 = connectionsCount threaded through no-credentials fallback). Owner-approved rebaseline (file-size cap for contributor PR). Frozen (cannot grow further); release captain's rebaseline-at-release supersedes.",
"_rebaseline_2026_07_07_6526_chirag_modal_1080p": "PR #6526 (@chirag127, #6265): AddApiKeyModal.tsx ->961 (1080p sizing). Owner-approved. Frozen.",
"_rebaseline_2026_07_07_6515_chirag": "PR #6515 (@chirag127) own growth: src/sse/handlers/chat.ts ->1763. Owner-approved rebaseline. Frozen."
"_rebaseline_2026_07_07_6515_chirag": "PR #6515 (@chirag127) own growth: src/sse/handlers/chat.ts ->1763. Owner-approved rebaseline. Frozen.",
"_rebaseline_2026_07_07_6534_chirag": "PR #6534 (@chirag127) own growth: open-sse/services/compression/strategySelector.ts ->1025. Owner-approved rebaseline. Frozen."
}
35 changes: 26 additions & 9 deletions open-sse/services/compression/strategySelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,32 @@ function reportEngineStep(
});
}

/**
* #6463: When callers dispatch mode="stacked" WITHOUT pre-deriving the pipeline from the
* per-engine toggle map (e.g. /api/compression/preview, external routes that only forward
* the persisted config), the stacked loop must not silently fall back to the built-in
* [rtk, caveman] default while ignoring the operator's toggled engines. This resolver
* honors the explicit pipeline first, then the engines-derived pipeline, and only
* falls back to the historical default when neither source produced steps.
*/
function resolveStackSteps(
pipeline?: Array<CompressionPipelineStep | string>
pipeline?: Array<CompressionPipelineStep | string>,
config?: CompressionConfig
): CompressionPipelineStep[] {
return pipeline && pipeline.length > 0
? pipeline.map(normalizePipelineStep)
: [
{ engine: "rtk", intensity: "standard" },
{ engine: "caveman", intensity: "full" },
];
if (pipeline && pipeline.length > 0) return pipeline.map(normalizePipelineStep);

const engines = config?.engines;
if (engines && Object.values(engines).some((e) => e?.enabled === true)) {
const derived = deriveDefaultPlan(engines, true);
if (derived.mode === "stacked" && derived.stackedPipeline.length > 0) {
return derived.stackedPipeline as CompressionPipelineStep[];
}
}

return [
{ engine: "rtk", intensity: "standard" },
{ engine: "caveman", intensity: "full" },
];
}

function buildStepOptions(
Expand Down Expand Up @@ -819,7 +836,7 @@ function runStackedCompression(
pipeline?: Array<CompressionPipelineStep | string>,
options?: StackOptions
): CompressionResult {
const steps = resolveStackSteps(pipeline);
const steps = resolveStackSteps(pipeline, options?.config);
registerBuiltinCompressionEngines();

let currentBody = body;
Expand Down Expand Up @@ -922,7 +939,7 @@ async function runStackedCompressionAsync(
pipeline?: Array<CompressionPipelineStep | string>,
options?: StackOptions
): Promise<CompressionResult> {
const steps = resolveStackSteps(pipeline);
const steps = resolveStackSteps(pipeline, options?.config);
registerBuiltinCompressionEngines();

let currentBody = body;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { describe, it } from "node:test";
import assert from "node:assert/strict";

import { applyCompressionAsync } from "../../../open-sse/services/compression/index.ts";
import { DEFAULT_COMPRESSION_CONFIG } from "../../../open-sse/services/compression/types.ts";
import type { CompressionConfig } from "../../../open-sse/services/compression/types.ts";

/**
* Regression guard for #6463 (and the 30 downstream engine-substitution reports).
*
* When a caller dispatches mode="stacked" with a config that carries the operator's
* `engines` toggle map but no pre-derived `stackedPipeline` (e.g. /api/compression/preview,
* ad-hoc integrations that only forward the persisted config), the stacked loop must
* derive the pipeline from `engines` — not silently fall back to [rtk, caveman].
*/
describe("stacked pipeline honors engines map when stackedPipeline is missing (#6463)", () => {
function body(): Record<string, unknown> {
return {
messages: [
{
role: "tool",
content: Array.from({ length: 8 }, () => "same noisy tool output line").join("\n"),
},
{
role: "user",
content:
"Please provide a detailed explanation of the authentication configuration and how it works",
},
],
};
}

it("derives rtk + caveman from engines map when stackedPipeline is empty", async () => {
const config: CompressionConfig = {
...DEFAULT_COMPRESSION_CONFIG,
enabled: true,
stackedPipeline: [],
engines: {
...DEFAULT_COMPRESSION_CONFIG.engines,
rtk: { enabled: true },
caveman: { enabled: true, level: "full" },
},
};

const result = await applyCompressionAsync(body(), "stacked", { config });

const ran = result.stats?.engineBreakdown?.map((e) => e.engine) ?? [];
assert.deepEqual(ran, ["rtk", "caveman"], "engines map must drive the derived pipeline");
});

it("prefers explicit pipeline over engines-derived when both are present", async () => {
const config: CompressionConfig = {
...DEFAULT_COMPRESSION_CONFIG,
enabled: true,
stackedPipeline: [{ engine: "caveman", intensity: "full" }],
engines: {
...DEFAULT_COMPRESSION_CONFIG.engines,
rtk: { enabled: true },
caveman: { enabled: true, level: "full" },
},
};

const result = await applyCompressionAsync(body(), "stacked", { config });
const ran = result.stats?.engineBreakdown?.map((e) => e.engine) ?? [];
assert.deepEqual(ran, ["caveman"], "explicit stackedPipeline must win over engines map");
});

it("falls back to [rtk, caveman] default only when BOTH pipeline and engines are empty", async () => {
const config: CompressionConfig = {
...DEFAULT_COMPRESSION_CONFIG,
enabled: true,
stackedPipeline: [],
engines: {},
};

const result = await applyCompressionAsync(body(), "stacked", { config });
const ran = result.stats?.engineBreakdown?.map((e) => e.engine) ?? [];
assert.deepEqual(ran, ["rtk", "caveman"], "historical fallback preserved");
});
});
Loading