Skip to content

Commit 19e5511

Browse files
committed
Merge pre-output stream pass-through fix
2 parents 944db73 + 9704596 commit 19e5511

4 files changed

Lines changed: 16 additions & 20 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@gitcommit90/rerouted",
33
"productName": "ReRouted",
4-
"version": "0.5.2",
4+
"version": "0.5.3",
55
"description": "A local AI router for connected accounts, models, named routes, and automatic fallback.",
66
"author": "gitcommit90",
77
"license": "MIT",

src/lib/router.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -640,17 +640,7 @@ async function inspectEarlyResponsesSse(response, maxBytes = PREOUTPUT_INSPECTIO
640640
}
641641
// Metadata events such as response.created can precede a quota error.
642642
// Hold the stream until actual output (or completion) proves the account usable.
643-
if (bytes >= maxBytes) {
644-
await reader.cancel().catch(() => {});
645-
return {
646-
response: null,
647-
failure: {
648-
status: 502,
649-
error: `Upstream exceeded the ${maxBytes}-byte inspection budget before producing a usable response`,
650-
resetAt: null,
651-
},
652-
};
653-
}
643+
if (bytes >= maxBytes) break;
654644
}
655645

656646
if (done) {

tests/router-fallback.test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,9 +1434,9 @@ describe("same-provider OAuth account fallback", () => {
14341434
assert.deepEqual(calls, ["stream-1.test", "stream-2.test", "stream-3.test"]);
14351435
});
14361436

1437-
it("bounds pre-output stream inspection and reroutes an oversized metadata preamble", async () => {
1437+
it("passes through an oversized metadata preamble without locking or rerouting", async () => {
14381438
const store = createStore(tmpConfig());
1439-
const providers = ["Slow preamble", "Backup"].map((name, index) => ({
1439+
const providers = ["Large preamble", "Backup"].map((name, index) => ({
14401440
id: `prov_bounded_${index + 1}`,
14411441
type: "openai-compat",
14421442
name,
@@ -1474,6 +1474,12 @@ describe("same-provider OAuth account fallback", () => {
14741474
`data: ${JSON.stringify({ type: "response.created", padding: "x".repeat(70 * 1024) })}\n\n`
14751475
)
14761476
);
1477+
controller.enqueue(
1478+
new TextEncoder().encode(
1479+
`event: response.output_text.delta\ndata: ${JSON.stringify({ type: "response.output_text.delta", delta: "large preamble success" })}\n\n`
1480+
)
1481+
);
1482+
controller.close();
14771483
},
14781484
cancel() {
14791485
canceled = true;
@@ -1483,7 +1489,7 @@ describe("same-provider OAuth account fallback", () => {
14831489
);
14841490
}
14851491
return new Response(
1486-
`data: ${JSON.stringify({ choices: [{ delta: { content: "bounded fallback" } }] })}\n\ndata: [DONE]\n\n`,
1492+
`data: ${JSON.stringify({ choices: [{ delta: { content: "unexpected fallback" } }] })}\n\ndata: [DONE]\n\n`,
14871493
{ status: 200, headers: { "Content-Type": "text/event-stream" } }
14881494
);
14891495
},
@@ -1500,9 +1506,9 @@ describe("same-provider OAuth account fallback", () => {
15001506
await result.streamPipe({ write: (chunk) => chunks.push(String(chunk)) });
15011507

15021508
assert.equal(result.ok, true, JSON.stringify(result.error));
1503-
assert.equal(canceled, true);
1504-
assert.match(chunks.join(""), /bounded fallback/);
1505-
assert.deepEqual(calls, ["bounded-1.test", "bounded-2.test"]);
1509+
assert.equal(canceled, false);
1510+
assert.match(chunks.join(""), /large preamble success/);
1511+
assert.deepEqual(calls, ["bounded-1.test"]);
15061512
});
15071513

15081514
it("records streaming usage after the final SSE event instead of an early zero-token success", async () => {

0 commit comments

Comments
 (0)