mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-20 13:52:28 +03:00
Right call not to reuse the combo loop's `fallbackCount`: it only increments after a leg fails or is skipped, so the second target would still report 0 at dispatch. Stamping the ordered index (or round-robin offset) at the gate is the only place the number is actually known. This PR also carries the batch's file-size rebaseline, since it merges first and the ceiling has to cover every intermediate state. --- Validated in one consolidated worktree cut from `release/v3.8.51`, boarded with the other 19 PRs of this batch. Two in-batch conflicts, both additive and resolved by keeping each side: the `ENVIRONMENT.md` table (#13035 + #13011) and the `chatHelpers.ts` import block (#12975 on the tip + #13017). - `typecheck:core` clean; `check:dashboard-typecheck` OK (206 pre-existing, within baseline); `check:changelog-integrity` OK; `check:docs-counts` migrations ✓ - complexity 2816 / baseline 3218 and cognitive-complexity 1271 / baseline 1437 — both under baseline - 531 of 532 focused assertions green across the batch's 46 test files - `check-file-size` rebaselined for the batch's real growth (annotation `_rebaseline_2026_09_11_mergebatch_v3851_houminxi`, landed on #13038), attributed per PR The single red is **not this batch**: `tests/unit/combo/quota-weighted-strategy.test.ts` → "A/B isolation: 7 hard-empty + 2 at 0.5% + 1 at 40%, floor=1" asserts an order between two connections of identical weight and flakes on the pure tip too — 2 failures in 4 runs at `origin/release/v3.8.51` with nothing from this batch applied. ⚠️ base-red inherited: #12732 — `Docs Gates`, `Merge integrity`, `No new ESLint warnings`, `Unit Tests fast-path` and `Fast Quality Gates` reproduce on the pure tip (provider count 356 vs the 358 the modules define, SKILL.md drift, and `open-sse/utils/stream.ts` at 3115 > frozen 3098, untouched here). Thanks @HouMinXi — the live evidence on these (X500 logs, `storage.sqlite` state, real `/v1/models` probes, the 36-minute outage write-up) is what let a 20-PR batch be reviewed as a unit.
160 lines
4.9 KiB
TypeScript
160 lines
4.9 KiB
TypeScript
/**
|
|
* #11462: the nested runtime-unit loop (open-sse/services/combo/runtimeUnits.ts,
|
|
* used by the pipeline/fusion combo strategies via dispatchPrelude.ts and
|
|
* fusionPanel.ts) had the same bare-`errorResponse()` gap as the round-robin
|
|
* strategy's "Maximum combo retry limit reached" 503 — no diagnostics trace.
|
|
*/
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { executeRuntimeUnitCombo } from "../../open-sse/services/combo/runtimeUnits.ts";
|
|
import type {
|
|
ResolvedComboUnit,
|
|
ComboNestingContext,
|
|
} from "../../open-sse/services/combo/types.ts";
|
|
|
|
function noopLog() {
|
|
return { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} };
|
|
}
|
|
|
|
function failResponse(): Response {
|
|
return new Response(JSON.stringify({ error: { message: "upstream 500" } }), {
|
|
status: 500,
|
|
headers: { "content-type": "application/json" },
|
|
});
|
|
}
|
|
|
|
test(
|
|
"#11462: nested runtime-unit combo's attempt-budget-exceeded 503 must carry " +
|
|
"the combo diagnostics trace (poolSize/attemptOrder/terminalReason)",
|
|
async () => {
|
|
const units: ResolvedComboUnit[] = [
|
|
{
|
|
kind: "model",
|
|
stepId: "step-a",
|
|
executionKey: "a",
|
|
modelStr: "openai/ru-a",
|
|
provider: "openai",
|
|
providerId: null,
|
|
connectionId: null,
|
|
weight: 1,
|
|
label: null,
|
|
},
|
|
{
|
|
kind: "model",
|
|
stepId: "step-b",
|
|
executionKey: "b",
|
|
modelStr: "anthropic/ru-b",
|
|
provider: "anthropic",
|
|
providerId: null,
|
|
connectionId: null,
|
|
weight: 1,
|
|
label: null,
|
|
},
|
|
];
|
|
|
|
const nesting: ComboNestingContext = {
|
|
depth: 0,
|
|
maxDepth: 5,
|
|
visitedComboNames: [],
|
|
rootComboName: "ru-probe-11462",
|
|
// Budget of 1 trips on the very first attempt, deterministically hitting the
|
|
// terminal branch under test without needing every unit to actually fail.
|
|
attemptBudget: { count: 0, limit: 1 },
|
|
};
|
|
|
|
const result = await executeRuntimeUnitCombo({
|
|
body: { messages: [{ role: "user", content: "hi" }] },
|
|
combo: { name: "ru-probe-11462", strategy: "pipeline" },
|
|
strategy: "pipeline",
|
|
units,
|
|
handleSingleModel: async () => failResponse(),
|
|
log: noopLog() as never,
|
|
config: { maxRetries: 0 },
|
|
allCombos: [],
|
|
nesting,
|
|
baseOptions: {} as never,
|
|
runCombo: async () => failResponse(),
|
|
});
|
|
|
|
assert.equal(result.response.status, 503);
|
|
const body = (await result.response.json()) as {
|
|
error: { message: string };
|
|
diagnostics?: { poolSize: number; attemptOrder: unknown[]; terminalReason: string };
|
|
};
|
|
assert.equal(body.error.message, "Maximum combo retry limit reached");
|
|
assert.ok(body.diagnostics, "runtime-unit 503 should carry a diagnostics field");
|
|
assert.ok(typeof body.diagnostics?.poolSize === "number");
|
|
assert.ok(Array.isArray(body.diagnostics?.attemptOrder));
|
|
assert.equal(body.diagnostics?.terminalReason, "max_attempts_exceeded");
|
|
}
|
|
);
|
|
|
|
test("nested runtime-unit dispatch stamps fallbackAttempts from the unit index", async () => {
|
|
const units: ResolvedComboUnit[] = [
|
|
{
|
|
kind: "model",
|
|
stepId: "step-a",
|
|
executionKey: "a",
|
|
modelStr: "openai/ru-a",
|
|
provider: "openai",
|
|
providerId: null,
|
|
connectionId: null,
|
|
weight: 1,
|
|
label: null,
|
|
},
|
|
{
|
|
kind: "model",
|
|
stepId: "step-b",
|
|
executionKey: "b",
|
|
modelStr: "anthropic/ru-b",
|
|
provider: "anthropic",
|
|
providerId: null,
|
|
connectionId: null,
|
|
weight: 1,
|
|
label: null,
|
|
},
|
|
];
|
|
const nesting: ComboNestingContext = {
|
|
depth: 0,
|
|
maxDepth: 5,
|
|
visitedComboNames: [],
|
|
rootComboName: "ru-fallback-12339",
|
|
attemptBudget: { count: 0, limit: 8 },
|
|
};
|
|
const seen: Array<{ model: string; fallbackAttempts?: number }> = [];
|
|
const ok = () =>
|
|
new Response(JSON.stringify({ choices: [{ message: { content: "ok" } }] }), {
|
|
status: 200,
|
|
headers: { "content-type": "application/json" },
|
|
});
|
|
await executeRuntimeUnitCombo({
|
|
body: { messages: [{ role: "user", content: "hi" }] },
|
|
combo: { name: "ru-fallback-12339", strategy: "pipeline" },
|
|
strategy: "pipeline",
|
|
units,
|
|
handleSingleModel: async (_body, modelStr, target) => {
|
|
seen.push({
|
|
model: modelStr,
|
|
fallbackAttempts: (target as { fallbackAttempts?: number } | undefined)?.fallbackAttempts,
|
|
});
|
|
if (modelStr === "openai/ru-a") {
|
|
return new Response(JSON.stringify({ error: { message: "upstream 500" } }), {
|
|
status: 500,
|
|
headers: { "content-type": "application/json" },
|
|
});
|
|
}
|
|
return ok();
|
|
},
|
|
log: noopLog() as never,
|
|
config: { maxRetries: 0, retryDelayMs: 0 },
|
|
allCombos: [],
|
|
nesting,
|
|
baseOptions: {} as never,
|
|
runCombo: async () => failResponse(),
|
|
});
|
|
assert.equal(seen.length, 2);
|
|
assert.equal(seen[0].fallbackAttempts, 0);
|
|
assert.equal(seen[1].fallbackAttempts, 1);
|
|
});
|