mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-21 06:32:16 +03:00
Compare commits
1 Commits
fix/7592-s
...
fix/10877-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b668d91364 |
5
.github/workflows/electron-release.yml
vendored
5
.github/workflows/electron-release.yml
vendored
@@ -279,14 +279,9 @@ jobs:
|
||||
|
||||
- name: Smoke packaged Electron app (Linux)
|
||||
if: matrix.platform == 'linux'
|
||||
# #7592: also cold-restart against the same DATA_DIR and assert a
|
||||
# native SQLite driver (not the sql.js WASM fallback) is selected on
|
||||
# the second launch — blocking here since Linux has no Windows-style
|
||||
# sandbox caveats that would make it flaky.
|
||||
env:
|
||||
ELECTRON_SMOKE_TIMEOUT_MS: 60000
|
||||
ELECTRON_SMOKE_STREAM_LOGS: "1"
|
||||
ELECTRON_SMOKE_COLD_RESTART: "1"
|
||||
run: xvfb-run -a npm run electron:smoke:packaged
|
||||
|
||||
- name: Collect installers
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
- **fix(sse):** `getResetAwareProvider()` and the auto-combo quota lookup in `combo.ts` now canonicalize the provider id via `resolveProviderId()` before calling `getQuotaFetcher()`, so a fetcher registered under a provider's canonical id (e.g. `ollama-cloud`, `codex`) is found for combo targets stored under an alias spelling (e.g. `ollamacloud`, `cx`) instead of silently degrading reset-aware/reset-window/auto quota-aware routing to plain priority ordering (#10877)
|
||||
@@ -1 +0,0 @@
|
||||
- **Electron packaged smoke test:** add a cold-restart mode (`ELECTRON_SMOKE_COLD_RESTART=1`, wired blocking on the Linux release leg) that relaunches the packaged app against its own persisted `DATA_DIR` and asserts a native SQLite driver was selected instead of the sql.js WASM fallback, closing the regression-test gap flagged in the stale-ABI `better-sqlite3` investigation ([#7592](https://github.com/diegosouzapw/OmniRoute/issues/7592)).
|
||||
@@ -64,6 +64,7 @@ import { getHiddenModelsByProvider } from "@/models";
|
||||
import { resolveModelLockoutSettings } from "../../src/lib/resilience/modelLockoutSettings";
|
||||
import { fetchCodexQuota } from "./codexQuotaFetcher.ts";
|
||||
import { evaluateQuotaCutoff, getQuotaFetcher, type QuotaInfo } from "./quotaPreflight.ts";
|
||||
import { resolveProviderId } from "../../src/shared/constants/providers.ts";
|
||||
import * as semaphore from "./rateLimitSemaphore.ts";
|
||||
import { getCircuitBreaker } from "../../src/shared/utils/circuitBreaker";
|
||||
import { parseModel } from "./model.ts";
|
||||
@@ -491,7 +492,10 @@ export async function buildAutoCandidates(
|
||||
let quotaRemaining = 100;
|
||||
let quotaCutoffBlocked = false;
|
||||
let quotaCutoffReason: string | undefined;
|
||||
const fetcher = getQuotaFetcher(provider);
|
||||
// #10877: `provider` here may be a legacy/user-facing alias spelling
|
||||
// (target.provider/parseModel output); canonicalize before the fetcher
|
||||
// registry lookup so aliased combo members still hit quota-aware scoring.
|
||||
const fetcher = getQuotaFetcher(resolveProviderId(provider));
|
||||
const connection = target.connectionId ? connectionById.get(target.connectionId) : undefined;
|
||||
const authType = typeof connection?.authType === "string" ? connection.authType : null;
|
||||
const sessionAvailability =
|
||||
|
||||
@@ -14,6 +14,7 @@ import { isRecord } from "./comboData.ts";
|
||||
import type { SlaRoutingPolicy } from "../autoCombo/routerStrategy.ts";
|
||||
import { RESET_WINDOW_NAMES } from "./types.ts";
|
||||
import type { ResolvedComboTarget } from "./types.ts";
|
||||
import { resolveProviderId } from "../../../src/shared/constants/providers.ts";
|
||||
|
||||
const RESET_AWARE_SESSION_WINDOW_MS = 5 * 60 * 60 * 1000;
|
||||
const RESET_AWARE_WEEKLY_WINDOW_MS = 7 * 24 * 60 * 60 * 1000;
|
||||
@@ -138,7 +139,11 @@ export function resolveSlaRoutingPolicy(
|
||||
|
||||
export function getResetAwareProvider(target: ResolvedComboTarget): string | null {
|
||||
const provider = (target.providerId || target.provider || "").toLowerCase();
|
||||
return provider || null;
|
||||
// #10877: combo targets can carry a legacy/user-facing alias spelling
|
||||
// (e.g. "ollamacloud", "cx") while quota fetchers register under the
|
||||
// canonical provider id (e.g. "ollama-cloud", "codex"). Canonicalize here
|
||||
// so getQuotaFetcher() lookups downstream (quotaStrategies.ts) find them.
|
||||
return provider ? resolveProviderId(provider) : null;
|
||||
}
|
||||
|
||||
function normalizeResetAt(value: unknown): string | null {
|
||||
|
||||
@@ -409,115 +409,45 @@ async function settleAfterReady({ getExitState, logs, settleMs }) {
|
||||
}
|
||||
}
|
||||
|
||||
function assertExecutableExists(appExecutable) {
|
||||
if (existsSync(appExecutable)) return;
|
||||
|
||||
throw new Error(
|
||||
`Packaged OmniRoute executable not found at ${appExecutable}. Build it first with \`npm run build:<target> --prefix electron\` or set ELECTRON_SMOKE_APP_EXECUTABLE.`
|
||||
);
|
||||
}
|
||||
|
||||
// ── CI sandbox workaround ──────────────────────────────────
|
||||
// GitHub Actions runners cannot set SUID on chrome-sandbox (Linux)
|
||||
// and Windows runners may fail silently without --no-sandbox.
|
||||
function buildCiSpawnArgs(currentPlatform = platform()) {
|
||||
if (!process.env.CI) return [];
|
||||
|
||||
const spawnArgs = ["--no-sandbox", "--disable-gpu"];
|
||||
if (currentPlatform === "linux") {
|
||||
spawnArgs.push("--disable-dev-shm-usage");
|
||||
}
|
||||
return spawnArgs;
|
||||
}
|
||||
|
||||
const NATIVE_DRIVER_LOG_PATTERN = /\[DB\] Driver: (bun:sqlite|better-sqlite3|node:sqlite) \|/;
|
||||
const SQLJS_DRIVER_LOG_PATTERN = /\[DB\] Driver: sql\.js \|/;
|
||||
|
||||
/**
|
||||
* Regression guard for #7592: on a packaged app's SECOND launch against an
|
||||
* already-persisted DATA_DIR, a stale-ABI better-sqlite3 binary (resolved via
|
||||
* a Turbopack-hashed import) used to fail to load and silently fall through
|
||||
* to the sql.js (WASM) driver — which then OOMs/retry-loops on real-sized
|
||||
* databases. Asserts the startup log shows a native driver was selected.
|
||||
*/
|
||||
export function assertNativeDriverSelected(logs) {
|
||||
if (NATIVE_DRIVER_LOG_PATTERN.test(logs)) return;
|
||||
|
||||
if (SQLJS_DRIVER_LOG_PATTERN.test(logs)) {
|
||||
async function main() {
|
||||
const appExecutable = discoverPackagedExecutable();
|
||||
if (!existsSync(appExecutable)) {
|
||||
throw new Error(
|
||||
"Packaged Electron app fell back to the sql.js (WASM) driver instead of a native SQLite " +
|
||||
"driver — this is the regression #7592 guards against (stale-ABI better-sqlite3 binary)."
|
||||
`Packaged OmniRoute executable not found at ${appExecutable}. Build it first with \`npm run build:<target> --prefix electron\` or set ELECTRON_SMOKE_APP_EXECUTABLE.`
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
"Packaged Electron app logs contain no '[DB] Driver: ...' line — cannot confirm which SQLite " +
|
||||
"driver loaded."
|
||||
);
|
||||
}
|
||||
|
||||
async function waitForReady({ logs, smokeUrl, timeoutMs, settleMs, exitState }) {
|
||||
const startedAt = Date.now();
|
||||
let lastError = null;
|
||||
|
||||
while (Date.now() - startedAt < timeoutMs) {
|
||||
assertNoFatalLogs(logs.value);
|
||||
|
||||
if (exitState.spawnError !== null) {
|
||||
throw new Error(`Packaged Electron app failed to launch: ${exitState.spawnError.message}`);
|
||||
}
|
||||
if (exitState.exitCode !== null || exitState.signalCode !== null) {
|
||||
throw new Error(
|
||||
`Packaged Electron app exited before readiness: code=${exitState.exitCode} signal=${exitState.signalCode}`
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetchWithTimeout(smokeUrl, 1_000);
|
||||
if (response.status === 200) {
|
||||
assertNoFatalLogs(logs.value);
|
||||
console.log(`[electron-smoke] ready: ${smokeUrl} returned HTTP 200`);
|
||||
await settleAfterReady({
|
||||
getExitState: () => ({ exitCode: exitState.exitCode, signalCode: exitState.signalCode }),
|
||||
logs,
|
||||
settleMs,
|
||||
});
|
||||
console.log(`[electron-smoke] stable for ${settleMs}ms after readiness`);
|
||||
return;
|
||||
}
|
||||
lastError = new Error(`HTTP ${response.status}`);
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
}
|
||||
|
||||
await sleep(500);
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Packaged Electron app did not serve ${smokeUrl} within ${timeoutMs}ms. Last error: ${
|
||||
lastError instanceof Error ? lastError.message : String(lastError)
|
||||
}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches the packaged app once against `dataDir`, waits for readiness +
|
||||
* settle, tears it down, and returns the captured stdout/stderr text. Shared
|
||||
* by the single-launch path and the cold-restart (two-launch) path so both
|
||||
* exercise identical spawn/readiness/shutdown behavior.
|
||||
*/
|
||||
async function launchAndCollectLogs({ appExecutable, smokeUrl, dataDir, timeoutMs, settleMs, streamLogs }) {
|
||||
const smokeUrl = process.env.ELECTRON_SMOKE_URL || DEFAULT_URL;
|
||||
const timeoutMs = parsePositiveInteger(process.env.ELECTRON_SMOKE_TIMEOUT_MS, DEFAULT_TIMEOUT_MS);
|
||||
const settleMs = parsePositiveInteger(process.env.ELECTRON_SMOKE_SETTLE_MS, DEFAULT_SETTLE_MS);
|
||||
const dataDir =
|
||||
process.env.ELECTRON_SMOKE_DATA_DIR ||
|
||||
(await mkdtemp(join(tmpdir(), "omniroute-electron-smoke-")));
|
||||
const removeDataDir =
|
||||
!process.env.ELECTRON_SMOKE_DATA_DIR && process.env.ELECTRON_SMOKE_KEEP_DATA !== "1";
|
||||
const smokeEnv = buildSmokeEnv({ dataDir });
|
||||
|
||||
await assertPortIsFree(smokeUrl);
|
||||
await ensureSmokeEnvDirs(smokeEnv, dataDir);
|
||||
|
||||
const spawnArgs = buildCiSpawnArgs();
|
||||
// ── CI sandbox workaround ──────────────────────────────────
|
||||
// GitHub Actions runners cannot set SUID on chrome-sandbox (Linux)
|
||||
// and Windows runners may fail silently without --no-sandbox.
|
||||
const spawnArgs = [];
|
||||
if (process.env.CI) {
|
||||
spawnArgs.push("--no-sandbox", "--disable-gpu");
|
||||
if (platform() === "linux") {
|
||||
spawnArgs.push("--disable-dev-shm-usage");
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[electron-smoke] launching ${appExecutable}`);
|
||||
if (spawnArgs.length) console.log(`[electron-smoke] CI args: ${spawnArgs.join(" ")}`);
|
||||
console.log(`[electron-smoke] DATA_DIR=${dataDir}`);
|
||||
console.log(`[electron-smoke] waiting for ${smokeUrl}`);
|
||||
|
||||
const logs = { value: "" };
|
||||
const streamLogs = process.env.ELECTRON_SMOKE_STREAM_LOGS === "1";
|
||||
const child = spawn(appExecutable, spawnArgs, {
|
||||
detached: platform() !== "win32",
|
||||
env: smokeEnv,
|
||||
@@ -527,18 +457,60 @@ async function launchAndCollectLogs({ appExecutable, smokeUrl, dataDir, timeoutM
|
||||
child.stdout?.on("data", (chunk) => appendLog(logs, chunk, "[electron] ", streamLogs));
|
||||
child.stderr?.on("data", (chunk) => appendLog(logs, chunk, "[electron:err] ", streamLogs));
|
||||
|
||||
const exitState = { exitCode: null, signalCode: null, spawnError: null };
|
||||
let exitCode = null;
|
||||
let signalCode = null;
|
||||
let spawnError = null;
|
||||
child.once("exit", (code, signal) => {
|
||||
exitState.exitCode = code;
|
||||
exitState.signalCode = signal;
|
||||
exitCode = code;
|
||||
signalCode = signal;
|
||||
});
|
||||
child.once("error", (error) => {
|
||||
exitState.spawnError = error;
|
||||
spawnError = error;
|
||||
});
|
||||
|
||||
try {
|
||||
await waitForReady({ logs, smokeUrl, timeoutMs, settleMs, exitState });
|
||||
return logs.value;
|
||||
const startedAt = Date.now();
|
||||
let lastError = null;
|
||||
|
||||
while (Date.now() - startedAt < timeoutMs) {
|
||||
assertNoFatalLogs(logs.value);
|
||||
|
||||
if (spawnError !== null) {
|
||||
throw new Error(`Packaged Electron app failed to launch: ${spawnError.message}`);
|
||||
}
|
||||
|
||||
if (exitCode !== null || signalCode !== null) {
|
||||
throw new Error(
|
||||
`Packaged Electron app exited before readiness: code=${exitCode} signal=${signalCode}`
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetchWithTimeout(smokeUrl, 1_000);
|
||||
if (response.status === 200) {
|
||||
assertNoFatalLogs(logs.value);
|
||||
console.log(`[electron-smoke] ready: ${smokeUrl} returned HTTP 200`);
|
||||
await settleAfterReady({
|
||||
getExitState: () => ({ exitCode, signalCode }),
|
||||
logs,
|
||||
settleMs,
|
||||
});
|
||||
console.log(`[electron-smoke] stable for ${settleMs}ms after readiness`);
|
||||
return;
|
||||
}
|
||||
lastError = new Error(`HTTP ${response.status}`);
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Packaged Electron app did not serve ${smokeUrl} within ${timeoutMs}ms. Last error: ${
|
||||
lastError instanceof Error ? lastError.message : String(lastError)
|
||||
}`
|
||||
);
|
||||
} catch (error) {
|
||||
if (!streamLogs) {
|
||||
printLogTail(logs.value);
|
||||
@@ -547,43 +519,6 @@ async function launchAndCollectLogs({ appExecutable, smokeUrl, dataDir, timeoutM
|
||||
} finally {
|
||||
await stopApp(child);
|
||||
await waitForPortClosed(smokeUrl);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const appExecutable = discoverPackagedExecutable();
|
||||
assertExecutableExists(appExecutable);
|
||||
|
||||
const smokeUrl = process.env.ELECTRON_SMOKE_URL || DEFAULT_URL;
|
||||
const timeoutMs = parsePositiveInteger(process.env.ELECTRON_SMOKE_TIMEOUT_MS, DEFAULT_TIMEOUT_MS);
|
||||
const settleMs = parsePositiveInteger(process.env.ELECTRON_SMOKE_SETTLE_MS, DEFAULT_SETTLE_MS);
|
||||
const streamLogs = process.env.ELECTRON_SMOKE_STREAM_LOGS === "1";
|
||||
// #7592: rerun against the SAME (persisted) DATA_DIR and assert the second
|
||||
// launch selected a native SQLite driver, not the sql.js WASM fallback.
|
||||
const coldRestart = process.env.ELECTRON_SMOKE_COLD_RESTART === "1";
|
||||
const dataDir =
|
||||
process.env.ELECTRON_SMOKE_DATA_DIR ||
|
||||
(await mkdtemp(join(tmpdir(), "omniroute-electron-smoke-")));
|
||||
const removeDataDir =
|
||||
!process.env.ELECTRON_SMOKE_DATA_DIR && process.env.ELECTRON_SMOKE_KEEP_DATA !== "1";
|
||||
|
||||
try {
|
||||
await launchAndCollectLogs({ appExecutable, smokeUrl, dataDir, timeoutMs, settleMs, streamLogs });
|
||||
|
||||
if (!coldRestart) return;
|
||||
|
||||
console.log("[electron-smoke] cold-restart: relaunching against the same DATA_DIR");
|
||||
const secondLaunchLogs = await launchAndCollectLogs({
|
||||
appExecutable,
|
||||
smokeUrl,
|
||||
dataDir,
|
||||
timeoutMs,
|
||||
settleMs,
|
||||
streamLogs,
|
||||
});
|
||||
assertNativeDriverSelected(secondLaunchLogs);
|
||||
console.log("[electron-smoke] cold-restart: native SQLite driver confirmed on second launch");
|
||||
} finally {
|
||||
if (removeDataDir) {
|
||||
await rm(dataDir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import {
|
||||
assertNativeDriverSelected,
|
||||
buildSmokeEnv,
|
||||
FATAL_LOG_PATTERNS,
|
||||
LINUX_EXECUTABLE_NAMES,
|
||||
@@ -72,28 +71,3 @@ test("electron smoke force-terminates the Windows process tree before the parent
|
||||
assert.deepEqual(signals, ["SIGKILL"]);
|
||||
assert.deepEqual(waits, [2_000]);
|
||||
});
|
||||
|
||||
// #7592: on a cold restart against an already-persisted DATA_DIR, a stale-ABI
|
||||
// better-sqlite3 binary used to fail to load and silently fall through to the
|
||||
// sql.js (WASM) driver. These are the regression guards for that assertion.
|
||||
test("electron smoke accepts every native SQLite driver on the startup log", () => {
|
||||
for (const driver of ["bun:sqlite", "better-sqlite3", "node:sqlite"]) {
|
||||
assert.doesNotThrow(() =>
|
||||
assertNativeDriverSelected(`[electron] [DB] Driver: ${driver} | file: /data/storage.sqlite`)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("electron smoke flags a cold-restart fallback to the sql.js WASM driver", () => {
|
||||
assert.throws(
|
||||
() => assertNativeDriverSelected("[electron] [DB] Driver: sql.js | file: /data/storage.sqlite"),
|
||||
/fell back to the sql\.js \(WASM\) driver/
|
||||
);
|
||||
});
|
||||
|
||||
test("electron smoke flags startup logs missing any driver selection line", () => {
|
||||
assert.throws(
|
||||
() => assertNativeDriverSelected("[electron] [server] listening on 20128"),
|
||||
/no '\[DB\] Driver: \.\.\.' line/
|
||||
);
|
||||
});
|
||||
|
||||
66
tests/unit/quota-scoring-alias-lookup-10877.test.ts
Normal file
66
tests/unit/quota-scoring-alias-lookup-10877.test.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { getResetAwareProvider } from "../../open-sse/services/combo/quotaScoring.ts";
|
||||
import { registerQuotaFetcher, getQuotaFetcher } from "../../open-sse/services/quotaPreflight.ts";
|
||||
import { resolveProviderId } from "../../src/shared/constants/providers.ts";
|
||||
import type { ResolvedComboTarget } from "../../open-sse/services/combo/types.ts";
|
||||
|
||||
function buildTarget(provider: string): ResolvedComboTarget {
|
||||
return {
|
||||
kind: "model",
|
||||
stepId: "s1",
|
||||
executionKey: "e1",
|
||||
modelStr: `${provider}/some-model`,
|
||||
provider,
|
||||
providerId: provider,
|
||||
connectionId: "conn-1",
|
||||
weight: 1,
|
||||
label: null,
|
||||
} as ResolvedComboTarget;
|
||||
}
|
||||
|
||||
test("#10877: getResetAwareProvider() canonicalizes an alias-spelled provider so the fetcher registered under the canonical id is found", () => {
|
||||
registerQuotaFetcher("ollama-cloud", async () => ({ ok: true }) as never);
|
||||
|
||||
const target = buildTarget("ollamacloud");
|
||||
const lookedUpProvider = getResetAwareProvider(target);
|
||||
|
||||
assert.equal(
|
||||
lookedUpProvider,
|
||||
resolveProviderId("ollamacloud"),
|
||||
"getResetAwareProvider() should return the canonical provider id, not the raw alias"
|
||||
);
|
||||
|
||||
const fetcher = getQuotaFetcher(lookedUpProvider!);
|
||||
assert.notEqual(
|
||||
fetcher,
|
||||
undefined,
|
||||
"a fetcher registered under the canonical provider id must be found for an alias-spelled combo target"
|
||||
);
|
||||
});
|
||||
|
||||
test("#10877: getResetAwareProvider() is a no-op (same cache key) for already-canonical provider ids", () => {
|
||||
registerQuotaFetcher("codex", async () => ({ ok: true }) as never);
|
||||
|
||||
const target = buildTarget("codex");
|
||||
const lookedUpProvider = getResetAwareProvider(target);
|
||||
|
||||
assert.equal(lookedUpProvider, "codex");
|
||||
assert.notEqual(getQuotaFetcher(lookedUpProvider!), undefined);
|
||||
});
|
||||
|
||||
test("#10877: getResetAwareProvider() returns null when neither providerId nor provider is set", () => {
|
||||
const target = {
|
||||
kind: "model",
|
||||
stepId: "s1",
|
||||
executionKey: "e1",
|
||||
modelStr: "unknown/model",
|
||||
provider: "",
|
||||
providerId: "",
|
||||
connectionId: "conn-1",
|
||||
weight: 1,
|
||||
label: null,
|
||||
} as ResolvedComboTarget;
|
||||
|
||||
assert.equal(getResetAwareProvider(target), null);
|
||||
});
|
||||
Reference in New Issue
Block a user