Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
11952ae
feat(compression): add ultraEngine + ultraSlmPrewarm to CompressionCo…
Jun 22, 2026
c9ae9a8
feat(compression): add CompressionStats.ultraTier resolved-tier signa…
Jun 22, 2026
b4ca033
feat(compression): add llmlingua ultra entry — slmAvailable + runLlml…
Jun 22, 2026
284802d
test(compression): runLlmlinguaUltra throws on backend no-op (B)
Jun 22, 2026
5f227c4
feat(compression): ultra two-tier resolver — async ultraCompress + sy…
Jun 22, 2026
f67ca7f
feat(compression): ultra SLM tier resolver branches + injectable test…
Jun 22, 2026
192645c
test(compression): ultra SLM tier preserves code/URL structure (B)
Jun 22, 2026
c8552c6
fix(compression): stacked ultra engine uses sync ultraCompressHeurist…
Jun 22, 2026
14c740b
feat(compression): route ultra SLM tier through async ultraCompress i…
Jun 22, 2026
7b8427b
feat(compression): re-export ultra-SLM surface from compression index…
Jun 22, 2026
74eebbc
feat(compression): ultra SLM pre-warm fires one best-effort warm call…
Jun 22, 2026
e386612
feat(compression): pure shouldPrewarmUltraSlm decision helper (B)
Jun 22, 2026
b1e13c9
feat(compression): best-effort ultra SLM pre-warm on enable + cold re…
Jun 22, 2026
a6e87bf
test(compression): await now-async ultraCompress in code-preservation…
Jun 22, 2026
12aad5a
feat(compression): surface ultra SLM tier + pre-warm in settings pane…
Jun 22, 2026
8d10e04
test(compression): gated VPS ultra-SLM live + forced-fallback evidenc…
Jun 22, 2026
75d9f2c
chore(compression): rebaseline file-size for ultra SLM tier strategyS…
Jun 22, 2026
60ad350
test(compression): add useLocale to next-intl mock after A panel loca…
Jun 23, 2026
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
8 changes: 5 additions & 3 deletions config/quality/file-size-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"_rebaseline_2026_06_20_4389_thinking_toolchoice": "Re-baseline base.ts 1387->1399 (#4389): tool_choice-forced thinking guard at the existing Claude wire-image injection chokepoint (effThinking gate avoids the Anthropic 400 when tool_choice forces a tool). Cohesive guard; structural shrink tracked in #3501.",
"cap": 800,
"frozen": {
"open-sse/translator/request/openai-to-kiro.ts": 807,
"_rebaseline_pr1043_minimax_tts": "Upstream port decolua/9router#1043 (toanalien) own growth: audioSpeech.ts 965->1061 (+96). Adds MiniMax T2A v2 TTS dispatch (handleMinimaxSpeech + hexToBytes helper) — provider entry was already in audioRegistry (format: minimax-tts) but no handler existed, falling through to the OpenAI-compatible default that fails (T2A has custom shape + hex-encoded audio + base_resp envelope). New branch sits next to the other inline provider branches (xiaomi-mimo, coqui, tortoise, aws-polly) — extracting would just create indirection. Covered by tests/unit/minimax-tts-1043.test.ts (3 tests, GREEN: success, base_resp error, invalid-hex).",
"open-sse/config/providerRegistry.ts": 4731,
"open-sse/executors/antigravity.ts": 1696,
"open-sse/executors/base.ts": 1414,
Expand All @@ -120,7 +120,6 @@
"open-sse/executors/grok-web.ts": 1871,
"open-sse/executors/muse-spark-web.ts": 1284,
"open-sse/executors/perplexity-web.ts": 1013,
"_rebaseline_pr1043_minimax_tts": "Upstream port decolua/9router#1043 (toanalien) own growth: audioSpeech.ts 965->1061 (+96). Adds MiniMax T2A v2 TTS dispatch (handleMinimaxSpeech + hexToBytes helper) — provider entry was already in audioRegistry (format: minimax-tts) but no handler existed, falling through to the OpenAI-compatible default that fails (T2A has custom shape + hex-encoded audio + base_resp envelope). New branch sits next to the other inline provider branches (xiaomi-mimo, coqui, tortoise, aws-polly) — extracting would just create indirection. Covered by tests/unit/minimax-tts-1043.test.ts (3 tests, GREEN: success, base_resp error, invalid-hex).",
"open-sse/handlers/audioSpeech.ts": 1061,
"open-sse/handlers/chatCore.ts": 5125,
"open-sse/handlers/imageGeneration.ts": 3777,
Expand All @@ -137,10 +136,12 @@
"open-sse/services/claudeCodeCompatible.ts": 1202,
"_rebaseline_pr4592_exclude_exhausted_auto": "Reconcile #4592 already-merged growth: combo.ts 2991->3036 (+45, terminal-status quota-cutoff exclusion in buildAutoCandidates + opt-in gate). Fast-gate PR->release does not run check:file-size.",
"open-sse/services/combo.ts": 3036,
"open-sse/services/compression/strategySelector.ts": 818,
"open-sse/services/rateLimitManager.ts": 1035,
"open-sse/services/tokenRefresh.ts": 1997,
"open-sse/services/usage.ts": 3450,
"open-sse/translator/request/openai-to-gemini.ts": 864,
"open-sse/translator/request/openai-to-kiro.ts": 807,
"open-sse/translator/response/openai-responses.ts": 922,
"open-sse/utils/cursorAgentProtobuf.ts": 1521,
"open-sse/utils/stream.ts": 2710,
Expand Down Expand Up @@ -302,5 +303,6 @@
"_rebaseline_2026_06_20_4355_gpt5x_pro_pricing": "PR #4355 own growth: pricing.ts 1581->1592 (+11 = pure-data pricing rows for openai gpt-5.5-pro + gpt-5.4-pro, closing the $0 gap that tripped the catalog pricing gate after the #4324 sweep added them to the registry; -pro mirrors its base family tier). provider-models-route.test.ts 1616->1618 (+2 = test-only alignment to the intentional opencode-go discovery behavior: owned_by stamp + T39 two-endpoint fail-path fetchCalls). Both are data/test-only; not extractable.",
"_rebaseline_2026_06_19_4293_codex_spark_scope": "PR #4293 (isolate Codex Spark quota scope) own growth, MEASURED on the actual merged tree (release/v3.8.30 + #4293). Production: auth.ts 2219->2279 (+60) threads requestedModel into Codex quota-policy/headroom/preflight/P2C scoring so normal Codex and GPT-5.3-Codex-Spark windows are evaluated independently; chatCore.ts 5116->5125 (+9) passes the failing model scope into Codex 429 failover (markCodexScopeRateLimited) instead of a connection-wide rateLimitedUntil write; accountFallback.ts 1727->1731 (+4) scopes Codex model-lock keys to codex vs spark. Heavy parsing/display logic lives in new leaf helpers under the cap (codexQuotaScopes.ts, codexUsageQuotas.ts, codexFailover.ts). Tests: account-fallback-service 1544->1569, executor-codex 1336->1339, sse-auth 1527->1553, usage-service-hardening 1612->1633 (added Spark-scope regression coverage). Cohesive wiring at existing selection/failover lockout boundaries; not extractable.",
"_rebaseline_2026_06_20_4447_openai_gpt41mini_o_mini_pricing": "PR #4447 own growth: pricing.ts 1592->1620 (+28 = pure-data pricing rows closing the null/$0 gap for registry-exposed OpenAI ids gpt-4.1-mini, gpt-4.1-nano, o3-mini, o4-mini that tripped the catalog pricing gate; getPricingForModel does an exact lookup, so a missing key resolves to null. Official OpenAI per-1M prices + the table's derived-field convention (reasoning=output*1.5, cache_creation=input, cached=official). Restore-green for a pre-existing release/v3.8.32 red surfaced by #4432's __RUN_ALL__ run. Cohesive data; not extractable.",
"_rebaseline_2026_06_20_web_cookie_validator_shadow_fix": "validation.ts 4518->4522 (+4 = move the generic web-cookie validateWebCookieProvider dispatch from the TOP of validateProviderApiKey to a FALLBACK after SPECIALTY_VALIDATORS, plus a comment, so #4023's generic AUTH_007 ping no longer shadows the rich per-provider validators (grok-web #3474 IP-reputation/Cloudflare, chatgpt-web cf-mitigated, claude/gemini/copilot/qwen/t3-web). Restores provider-validation-specialty.test.ts (112/112) while keeping web-cookie-auth007 (5/5). Behavior fix at an existing dispatch boundary; not extractable."
"_rebaseline_2026_06_20_web_cookie_validator_shadow_fix": "validation.ts 4518->4522 (+4 = move the generic web-cookie validateWebCookieProvider dispatch from the TOP of validateProviderApiKey to a FALLBACK after SPECIALTY_VALIDATORS, plus a comment, so #4023's generic AUTH_007 ping no longer shadows the rich per-provider validators (grok-web #3474 IP-reputation/Cloudflare, chatgpt-web cf-mitigated, claude/gemini/copilot/qwen/t3-web). Restores provider-validation-specialty.test.ts (112/112) while keeping web-cookie-auth007 (5/5). Behavior fix at an existing dispatch boundary; not extractable.",
"_rebaseline_2026_06_22_phase4b_slm_tier_ultra": "Compression Phase 4 (B) SLM tier own growth: open-sse/services/compression/strategySelector.ts 783->818 (+35 at the existing applyUltraAsync chokepoint). The no-modelPath ultra branch (previously a one-line passthrough to the sync applyCompression) now runs the two-tier resolver: it adapts the body, builds the ultraConfig (threading config.ultraEngine + preserveSystemPrompt), awaits the now-async ultraCompress (SLM Tier-B when ultraEngine===slm and the worker backend is available, else fail-open to the Tier-A heuristic), and threads result.stats.ultraTier into the returned CompressionStats so the resolved tier reaches the D0 telemetry persister. The sync applyCompression ultra branch is also re-pointed to the new pure ultraCompressHeuristic. The two-tier resolver + the pure heuristic live in open-sse/services/compression/ultra.ts and the thin SLM entry in engines/llmlingua/ultraEntry.ts (both <cap, fully unit-tested); strategySelector.ts is cohesive dispatch wiring at the existing ultra chokepoint, not extractable without hiding the dispatch boundary. Covered by tests/unit/compression/ultra-slm-tier.test.ts (applyCompressionAsync ultraTier:slm) + ultra.test.ts (39 regression) + the integration suites. Structural shrink of this file tracked in #3501."
}
4 changes: 2 additions & 2 deletions open-sse/services/compression/engines/cavemanAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { applyLiteCompression } from "../lite.ts";
import { cavemanCompress } from "../caveman.ts";
import { compressAggressive } from "../aggressive.ts";
import { ultraCompress } from "../ultra.ts";
import { ultraCompressHeuristic } from "../ultra.ts";
import { createCompressionStats } from "../stats.ts";
import { adaptBodyForCompression } from "../bodyAdapter.ts";
import {
Expand Down Expand Up @@ -414,7 +414,7 @@ export const ultraEngine: CompressionEngine = {
...(options?.stepConfig ?? {}),
preserveSystemPrompt: options?.config?.preserveSystemPrompt !== false,
};
const result = ultraCompress(messages, ultraConfig);
const result = ultraCompressHeuristic(messages, ultraConfig);
const compressedBody = { ...adapter.body, messages: result.messages };
return {
body: adapter.restore(compressedBody),
Expand Down
109 changes: 109 additions & 0 deletions open-sse/services/compression/engines/llmlingua/ultraEntry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* LLMLingua-2 entry point for the `ultra` mode (Phase 4, Sub-project B).
*
* A THIN wrapper over the existing worker backend (`./worker.ts`) — no new ONNX
* integration. It adds exactly what the `ultra` two-tier resolver needs:
* - `slmAvailable()` — cached, NON-BLOCKING probe (reuses the worker's memoized
* optional-deps gate). It NEVER loads a model; an actual load happens lazily
* inside the worker under its first-call timeout.
* - `runLlmlinguaUltra(text, opts)` — compress ONE prose string. Throws when the
* backend fail-opens to the original text (no-op), so the ultra resolver can
* fall through to the Tier-A heuristic and record "heuristic-fallback".
* - `prewarmLlmlinguaUltra()` — best-effort warm call (errors swallowed).
*
* The structure-preservation split (code/math/URLs never reach the model) is done
* by the CALLER (`ultra.ts`), exactly as the heuristic path already does — this
* entry only sees prose.
*/

import { workerBackend, depsAvailable } from "./worker.ts";
import { DEFAULT_LLMLINGUA_MODEL } from "./constants.ts";

/** Cached probe result. null = not probed yet. */
let _slmAvailable: boolean | null = null;

// ─── test-only injectable hooks ─────────────────────────────────────────────
interface UltraSlmTestHooks {
available?: boolean;
run?: (text: string, opts?: UltraSlmOptions) => Promise<string>;
}
let _testHooks: UltraSlmTestHooks | null = null;

/** Test-only: override availability + the per-prose run, to avoid loading a real model. */
export function __setUltraSlmTestHooks(hooks: UltraSlmTestHooks): void {
_testHooks = hooks;
}

/**
* Cheap, cached, non-blocking probe: are the optional SLM deps installed?
* Reuses the worker's memoized `depsAvailable()` (a filesystem manifest check),
* so it never spawns a worker or loads a model.
*/
export function slmAvailable(): boolean {
if (_testHooks && typeof _testHooks.available === "boolean") return _testHooks.available;
if (_slmAvailable !== null) return _slmAvailable;
_slmAvailable = depsAvailable();
return _slmAvailable;
}

/** Options the ultra SLM tier threads to the worker backend. */
export interface UltraSlmOptions {
model?: string;
compressionRate?: number;
modelPath?: string;
}

/**
* Compress ONE prose string via the SLM worker backend.
*
* The worker backend is strictly fail-open: on missing deps / spawn error /
* model-load or inference error / per-call timeout it returns the ORIGINAL text.
* We treat a returned no-op (output not shorter than input) as a FAILURE and
* throw, so the ultra resolver falls back to Tier-A and records the fallback.
*/
export async function runLlmlinguaUltra(text: string, opts?: UltraSlmOptions): Promise<string> {
if (_testHooks?.run) {
const out = await _testHooks.run(text, opts);
if (typeof out !== "string" || out.length >= text.length) {
throw new Error("llmlingua-ultra: backend produced no gain");
}
return out;
}
const out = await workerBackend(text, {
model: opts?.model,
compressionRate: opts?.compressionRate,
modelPath: opts?.modelPath,
});
if (typeof out !== "string" || out.length >= text.length) {
// Fail-open / no-op from the worker → let the caller fall back to heuristic.
throw new Error("llmlingua-ultra: backend produced no gain");
}
return out;
}

/**
* Best-effort pre-warm: ask the worker to load the model once on a short prose
* sample. NEVER throws — any failure is swallowed (the lazy first-call path still
* applies on the next real request). Returns true if a warm call was attempted.
*/
export async function prewarmLlmlinguaUltra(opts?: UltraSlmOptions): Promise<boolean> {
if (!slmAvailable()) return false;
try {
// A small but non-trivial sample so the worker triggers a real model load.
// Route through `runLlmlinguaUltra` so the same backend seam (and test hook)
// is exercised; a no-op/throw from the worker is fine here (best-effort).
await runLlmlinguaUltra(
"The quick brown fox jumps over the lazy dog while the sun sets behind the hills.",
{ model: opts?.model ?? DEFAULT_LLMLINGUA_MODEL, compressionRate: opts?.compressionRate }
);
} catch {
// swallow — pre-warm is best-effort (a no-op/throw from the worker is fine).
}
return true;
}

/** Test-only: reset the cached probe + injected hooks. */
export function __resetUltraEntryForTests(): void {
_slmAvailable = null;
_testHooks = null;
}
7 changes: 7 additions & 0 deletions open-sse/services/compression/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ export { STOPWORDS, FORCE_PRESERVE_RE, scoreToken, pruneByScore } from "./ultraH

export type { UltraCompressResult } from "./ultra.ts";
export { ultraCompress } from "./ultra.ts";
export { ultraCompressHeuristic } from "./ultra.ts";
export type { UltraTier } from "./ultra.ts";
export {
slmAvailable,
runLlmlinguaUltra,
prewarmLlmlinguaUltra,
} from "./engines/llmlingua/ultraEntry.ts";

export type { UltraConfig } from "./types.ts";
export { DEFAULT_ULTRA_CONFIG } from "./types.ts";
59 changes: 47 additions & 12 deletions open-sse/services/compression/strategySelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { CompressionEngineApplyOptions } from "./engines/types.ts";
import { applyLiteCompression } from "./lite.ts";
import { cavemanCompress } from "./caveman.ts";
import { compressAggressive } from "./aggressive.ts";
import { ultraCompress } from "./ultra.ts";
import { ultraCompress, ultraCompressHeuristic } from "./ultra.ts";
import { createCompressionStats } from "./stats.ts";
import { registerBuiltinCompressionEngines } from "./engines/index.ts";
import { getCompressionEngine, getEngineEntry } from "./engines/registry.ts";
Expand Down Expand Up @@ -325,19 +325,22 @@ export function applyCompression(
...(options?.config?.ultra ?? {}),
preserveSystemPrompt: options?.config?.preserveSystemPrompt !== false,
};
const result = ultraCompress(messages, ultraConfig);
const result = ultraCompressHeuristic(messages, ultraConfig);
const compressedBody = { ...compressionBody, messages: result.messages };
return {
body: adapter.restore(compressedBody),
compressed: result.stats.savingsPercent > 0,
stats: createCompressionStats(
compressionBody,
compressedBody,
mode,
["ultra"],
result.stats.rulesApplied,
result.stats.durationMs
),
stats: {
...createCompressionStats(
compressionBody,
compressedBody,
mode,
["ultra"],
result.stats.rulesApplied,
result.stats.durationMs
),
ultraTier: result.stats.ultraTier,
},
};
}
return { body, compressed: false, stats: null };
Expand Down Expand Up @@ -402,9 +405,41 @@ async function applyUltraAsync(
const ultraConfig = options?.config?.ultra;
const modelPath = typeof ultraConfig?.modelPath === "string" ? ultraConfig.modelPath.trim() : "";

// No model configured → heuristic ultra (unchanged default).
// No explicit modelPath → run the two-tier ultra resolver (heuristic, or SLM when
// config.ultraEngine === "slm" and the worker backend is available). This is the
// Phase-4 (B) path; it fail-opens to the heuristic and records the resolved tier.
if (!modelPath) {
return applyCompression(body, "ultra", options);
const adapter = adaptBodyForCompression(body);
const messages = (adapter.body.messages ?? []) as Array<{
role: string;
content?: string | unknown[];
[key: string]: unknown;
}>;
if (!Array.isArray(messages) || messages.length === 0) {
return { body, compressed: false, stats: null };
}
const ultraConfig = {
...(options?.config?.ultra ?? {}),
preserveSystemPrompt: options?.config?.preserveSystemPrompt !== false,
ultraEngine: options?.config?.ultraEngine,
};
const result = await ultraCompress(messages, ultraConfig);
const compressedBody = { ...adapter.body, messages: result.messages };
return {
body: adapter.restore(compressedBody),
compressed: result.stats.savingsPercent > 0,
stats: {
...createCompressionStats(
adapter.body,
compressedBody,
"ultra",
result.stats.techniquesUsed,
result.stats.rulesApplied,
result.stats.durationMs
),
ultraTier: result.stats.ultraTier,
},
};
}

registerBuiltinCompressionEngines();
Expand Down
22 changes: 22 additions & 0 deletions open-sse/services/compression/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ export interface CompressionConfig {
* change for installs that predate the panel). Set by `getCompressionSettings`.
*/
enginesExplicit?: boolean;
/**
* Phase 4 (B): which tier the `ultra` mode uses.
* "heuristic" = Tier-A token pruner (`pruneByScore`, default, byte-identical to pre-B).
* "slm" = Tier-B LLMLingua-2 ONNX worker when available, else fail-open to Tier-A.
*/
ultraEngine?: "heuristic" | "slm";
/**
* Phase 4 (B): best-effort pre-warm of the SLM model on the enable transition
* and on a cold restart when `ultraEngine: "slm"` is already set. Failures are
* swallowed; the lazy first-call path still applies. Default false.
*/
ultraSlmPrewarm?: boolean;
}

export interface CompressionStats {
Expand All @@ -177,6 +189,14 @@ export interface CompressionStats {
validationWarnings?: string[];
validationErrors?: string[];
fallbackApplied?: boolean;
/**
* Phase 4 (B): which `ultra` tier actually ran for this request.
* "slm" — Tier-B ran and produced the output.
* "heuristic-fallback" — Tier-B was selected but failed/timed out → Tier-A used.
* "heuristic" — Tier-A used directly (ultraEngine !== "slm" or SLM unavailable).
* Consumed by D0's persister as `CompressionRunTelemetry.ultraTier`.
*/
ultraTier?: "slm" | "heuristic-fallback" | "heuristic";
preservedBlockCount?: number;
rtkRawOutputPointers?: Array<{
id: string;
Expand Down Expand Up @@ -229,6 +249,8 @@ export const DEFAULT_COMPRESSION_CONFIG: CompressionConfig = {
],
engines: Object.fromEntries(ENGINE_IDS.map((id) => [id, { enabled: false }])),
activeComboId: null,
ultraEngine: "heuristic",
ultraSlmPrewarm: false,
};

export const DEFAULT_CAVEMAN_CONFIG: CavemanConfig = {
Expand Down
Loading
Loading