mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-13 18:32:12 +03:00
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host. Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean. Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
71 lines
3.3 KiB
TypeScript
71 lines
3.3 KiB
TypeScript
// #10268: "[BUG] API call failed (attempt 1/3): InternalServerError [HTTP 503]" — Hermes
|
|
// Agent / Cursor coding-agent fan-out landed on the same structural admission gate as
|
|
// #10183 and burned its 3 retries on OmniRoute's own `chat_admission_busy` 503, which it
|
|
// misread as an upstream capacity error. Same root cause, same fix (heap-conditional
|
|
// shedding in `admitChatStructure`): this test is the permanent regression guard proving
|
|
// the exact reported 503 shape is still produced when heap pressure is GENUINELY high,
|
|
// so the #4380 heap-amplification shed path is preserved rather than removed outright.
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
admitChatStructure,
|
|
ChatAdmissionController,
|
|
type ChatAdmissionLease,
|
|
} from "../../src/shared/middleware/chatBodyAdmission.ts";
|
|
|
|
function heavyBody() {
|
|
const messages = Array.from({ length: 201 }, (_, i) => ({ role: "user", content: `prompt ${i}` }));
|
|
const tools = Array.from({ length: 32 }, (_, i) => ({
|
|
type: "function",
|
|
function: { name: `tool_${i}`, description: "a".repeat(64), parameters: { type: "object" } },
|
|
}));
|
|
return { model: "grok-4.5-fast-high", messages, tools, stream: true };
|
|
}
|
|
|
|
test("#10268: 2nd structurally-heavy agent request is rejected 503 (chat_admission_busy) under real heap pressure", async () => {
|
|
const controller = new ChatAdmissionController(1);
|
|
const first = await admitChatStructure(heavyBody(), null, { controller, queueMs: 0 });
|
|
assert.equal(first.admit, true);
|
|
const lease = (first as { admit: true; lease: ChatAdmissionLease | null }).lease;
|
|
assert.ok(lease);
|
|
try {
|
|
const second = await admitChatStructure(heavyBody(), null, {
|
|
controller,
|
|
queueMs: 0,
|
|
// Simulate genuine heap pressure (#10183/#10268 fix: shedding is now
|
|
// conditional on this, not unconditional on capacity alone).
|
|
heapPressureCheck: () => true,
|
|
});
|
|
assert.equal(second.admit, false); // reported failure path, still reachable under real pressure
|
|
const res = (second as { admit: false; response: Response }).response;
|
|
assert.equal(res.status, 503); // client is shown HTTP 503
|
|
const body = await res.json();
|
|
assert.equal(body.error?.message, "Structurally heavy chat request capacity is busy; retry shortly.");
|
|
assert.equal(body.error?.code, "chat_admission_busy");
|
|
assert.equal(body.error?.reason, "structure_limit");
|
|
} finally {
|
|
lease.release();
|
|
}
|
|
});
|
|
|
|
test("#10268: 2nd structurally-heavy agent request is admitted on a healthy heap (the fix)", async () => {
|
|
const controller = new ChatAdmissionController(1);
|
|
const first = await admitChatStructure(heavyBody(), null, { controller, queueMs: 0 });
|
|
assert.equal(first.admit, true);
|
|
const lease = (first as { admit: true; lease: ChatAdmissionLease | null }).lease;
|
|
assert.ok(lease);
|
|
try {
|
|
const second = await admitChatStructure(heavyBody(), null, {
|
|
controller,
|
|
queueMs: 0,
|
|
// No override: default heap probe reads live process stats (healthy here),
|
|
// reproducing legitimate Hermes/Cursor fan-out traffic that must no longer
|
|
// be shed on ample free RAM.
|
|
});
|
|
assert.equal(second.admit, true, "healthy heap must admit legitimate agent fan-out");
|
|
if (second.admit) second.lease?.release();
|
|
} finally {
|
|
lease.release();
|
|
}
|
|
});
|