mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-22 04:19:40 +00:00
fix(qoder): check billing codes 110/112 before the busy heuristic
The inner payload of a billing block can carry `isQueued`, whose name matches the broad "queued" busy heuristic, so the envelope unwrapper and the CLI failure parser returned 503 upstream_busy instead of 429 qoder_billing_block. The exact billing codes are now checked first.
This commit is contained in:
@@ -131,6 +131,16 @@ async function unwrapQoderEnvelope(response: Response): Promise<Response> {
|
||||
|
||||
if (errorStatus) {
|
||||
reader.cancel();
|
||||
// Nested envelope codes 110/112: the account spent its daily credits.
|
||||
// 429 (not the outer 403) keeps the healthy PAT routable on other accounts.
|
||||
// Checked before the busy heuristic: the inner payload can carry `isQueued`.
|
||||
if (isQoderBillingBlock(errorMsg)) {
|
||||
return createQoderErrorResponse({
|
||||
status: 429,
|
||||
message: `[qoder error ${errorStatus}: ${sanitizeErrorMessage(truncate(errorMsg, 200))}]`,
|
||||
code: "qoder_billing_block",
|
||||
});
|
||||
}
|
||||
// #3510: a 403 envelope carrying the nested code 10605 is Qoder's temporary
|
||||
// queue throttle, not an auth failure. Surface it as 503 upstream_busy (same
|
||||
// classification as the CLI path) so healthy accounts are not parked on the
|
||||
@@ -143,15 +153,6 @@ async function unwrapQoderEnvelope(response: Response): Promise<Response> {
|
||||
retryAfterSeconds: parseQoderRetryAfterSeconds(errorMsg),
|
||||
});
|
||||
}
|
||||
// Nested envelope codes 110/112: the account spent its daily credits.
|
||||
// 429 (not the outer 403) keeps the healthy PAT routable on other accounts.
|
||||
if (isQoderBillingBlock(errorMsg)) {
|
||||
return createQoderErrorResponse({
|
||||
status: 429,
|
||||
message: `[qoder error ${errorStatus}: ${sanitizeErrorMessage(truncate(errorMsg, 200))}]`,
|
||||
code: "qoder_billing_block",
|
||||
});
|
||||
}
|
||||
const errType =
|
||||
errorStatus === 401 || errorStatus === 403 ? "authentication_error" : "provider_error";
|
||||
return new Response(
|
||||
|
||||
@@ -606,6 +606,12 @@ export function parseQoderCliFailure(stderrText: string, stdoutText = ""): Qoder
|
||||
return { status: 504, message: combined, code: "timeout" };
|
||||
}
|
||||
|
||||
// Exact billing codes 110/112 first: their inner payload can carry `isQueued`,
|
||||
// which the broad busy heuristic below would read as the 10605 throttle.
|
||||
if (isQoderBillingBlock(combined)) {
|
||||
return { status: 429, message: combined, code: "qoder_billing_block" };
|
||||
}
|
||||
|
||||
// Qoder answers a temporarily throttled account with a queued/busy envelope
|
||||
// (upstream code 10605) instead of an HTTP error. Classifying it as a generic
|
||||
// 502 upstream_error parked the connection on the long failure cooldown, so a
|
||||
@@ -615,10 +621,6 @@ export function parseQoderCliFailure(stderrText: string, stdoutText = ""): Qoder
|
||||
return { status: 503, message: combined, code: "upstream_busy" };
|
||||
}
|
||||
|
||||
if (isQoderBillingBlock(combined)) {
|
||||
return { status: 429, message: combined, code: "qoder_billing_block" };
|
||||
}
|
||||
|
||||
return { status: 502, message: combined, code: "upstream_error" };
|
||||
}
|
||||
|
||||
|
||||
@@ -88,3 +88,30 @@ test("CLI failure parser classifies nested code 112 as a billing block", () => {
|
||||
assert.equal(failure.status, 429);
|
||||
assert.equal(failure.code, "qoder_billing_block");
|
||||
});
|
||||
|
||||
function queuedFlagBody(code: string): string {
|
||||
// The 10605 throttle's inner payload carries `isQueued`; a billing block in the same shape
|
||||
// must not be read as the busy throttle because the word "queued" appears in that key.
|
||||
return JSON.stringify({
|
||||
code: "403",
|
||||
message: JSON.stringify({ code, message: JSON.stringify({ isQueued: false }) }),
|
||||
});
|
||||
}
|
||||
|
||||
for (const code of ["110", "112"]) {
|
||||
test(`nested code ${code} with isQueued:false is still a billing block, not upstream_busy`, async () => {
|
||||
const result = await unwrapQoderEnvelope(
|
||||
sseEnvelope({ statusCodeValue: 403, body: queuedFlagBody(code) })
|
||||
);
|
||||
|
||||
assert.equal(result.status, 429);
|
||||
const payload = (await result.json()) as ErrorPayload;
|
||||
assert.equal(payload.error.code, "qoder_billing_block");
|
||||
});
|
||||
|
||||
test(`CLI failure parser: nested code ${code} with isQueued:false is a billing block`, () => {
|
||||
const failure = parseQoderCliFailure(`qodercli failed: ${queuedFlagBody(code)}`);
|
||||
assert.equal(failure.status, 429);
|
||||
assert.equal(failure.code, "qoder_billing_block");
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user