Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ const nextConfig = {
"pino-pretty",
"thread-stream",
"pino-abstract-transport",
// `ws` must stay external so server-side WebSocket executors keep the real
// native masking implementation and optional helpers in the runtime bundle.
"ws",
"bufferutil",
"utf-8-validate",
"better-sqlite3",
// sqlite-vec ships a native vec0.so loaded at runtime via createRequire().
// Turbopack otherwise tries to bundle the .so and fails with "Unknown module
Expand Down
12 changes: 7 additions & 5 deletions src/sse/handlers/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import { enforceApiKeyPolicy } from "../../shared/utils/apiKeyPolicy";
import { hasProviderQuotaBypassScope } from "../../shared/constants/apiKeyPolicyScopes";
import { cloneLogPayload } from "@/lib/logPayloads";
import { handleInternalUsageCommand } from "@/lib/usage/internalUsageCommand";
import { shouldPersistUnavailableStateForComboFailure } from "../services/unavailableStatePolicy";
import {
applyTaskAwareRouting,
getTaskRoutingConfig,
Expand Down Expand Up @@ -1742,11 +1743,12 @@ async function handleSingleModelChat(
model,
providerProfile,
{
persistUnavailableState: !(
isCombo &&
result.status === 429 &&
(failureKind === "rate_limit" || failureKind === "transient")
),
persistUnavailableState: shouldPersistUnavailableStateForComboFailure({
isCombo,
provider,
status: result.status,
failureKind,
}),
isCombo,
}
);
Expand Down
22 changes: 22 additions & 0 deletions src/sse/services/unavailableStatePolicy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Policy for whether a combo fallback should persist connection unavailability.
*
* Combo-managed transient 429s stay in-memory for Antigravity because that path
* has dedicated quota handling. Other providers should persist the cooldown so
* the same connection is skipped on later requests, not just within the current
* combo attempt.
*/
export function shouldPersistUnavailableStateForComboFailure(options: {
isCombo?: boolean;
provider?: string | null;
status: number;
failureKind?: string | null;
}): boolean {
const isAntigravityComboTransient429 =
options.isCombo === true &&
options.provider === "antigravity" &&
options.status === 429 &&
(options.failureKind === "rate_limit" || options.failureKind === "transient");

return !isAntigravityComboTransient429;
}
3 changes: 3 additions & 0 deletions tests/unit/next-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ test("next config declares Turbopack aliases, runtime assets and server external

for (const packageName of [
"thread-stream",
"ws",
"bufferutil",
"utf-8-validate",
"better-sqlite3",
// sqlite-vec ships a native vec0.so loaded at runtime; without externalizing it
// the Turbopack build fails with "Unknown module type" on the .so (issue #3066).
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/unavailable-state-policy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import test from "node:test";
import assert from "node:assert/strict";

import { shouldPersistUnavailableStateForComboFailure } from "../../src/sse/services/unavailableStatePolicy.ts";

test("combo transient 429 persists for non-Antigravity providers", () => {
assert.equal(
shouldPersistUnavailableStateForComboFailure({
isCombo: true,
provider: "openai",
status: 429,
failureKind: "transient",
}),
true
);

assert.equal(
shouldPersistUnavailableStateForComboFailure({
isCombo: true,
provider: "anthropic",
status: 429,
failureKind: "rate_limit",
}),
true
);
});

test("combo transient 429 stays in-memory for Antigravity", () => {
assert.equal(
shouldPersistUnavailableStateForComboFailure({
isCombo: true,
provider: "antigravity",
status: 429,
failureKind: "transient",
}),
false
);
});
Loading