Compare commits

..

1 Commits

Author SHA1 Message Date
adevwithpurpose
ad672ef822 fix(sse): mark gemini-3.5-flash as thinking-capable
The base gemini-3.5-flash entry spread the shared GEMINI_35_FLASH_MODEL_SPEC
constant, which has supportsThinking:false because it is also spread into
several Antigravity flash-tier aliases that reject client-supplied thinking
params. That made the reasoning-routing policy resolve reasoning_effort as
"unsupported" for the base Google AI Studio model, producing a spurious
pre-provider HTTP 400 even though the model supports reasoning (it has an
effort-tier alias gemini-3.5-flash-high).

Set supportsThinking:true as an explicit override on the base
gemini-3.5-flash entry only, leaving the shared spec and the Antigravity
tier aliases unchanged.

Closes #10286
2026-08-15 03:02:39 -03:00
6 changed files with 86 additions and 100 deletions

View File

@@ -1 +0,0 @@
- fix(open-sse): stop concurrent requests colliding on the same dedup hash for non-OpenAI target formats (#10249)

View File

@@ -0,0 +1 @@
- fix(sse): mark gemini-3.5-flash as thinking-capable so reasoning_effort is no longer rejected with a spurious 400 (#10286)

View File

@@ -36,19 +36,12 @@ const inflight = new Map<string, Promise<unknown>>();
* Compute a deterministic hash for a request body.
* Includes: model, messages, temperature, tools, tool_choice, max_tokens, response_format
* Excludes: stream, user, metadata (don't affect LLM output)
*
* The prompt content can live under different keys depending on the target
* provider format the body has already been translated to: OpenAI-style
* bodies use `messages`, Gemini-translated bodies use `contents`, and
* Responses-API-translated bodies use `input`. Falling back to only
* `messages` made every non-OpenAI-format body hash the prompt as `null`,
* colliding different prompts onto the same dedup hash (#10249).
*/
export function computeRequestHash(requestBody: unknown): string {
const body = requestBody as Record<string, unknown>;
const canonical = {
model: body.model ?? null,
messages: body.messages ?? body.contents ?? body.input ?? null,
messages: body.messages ?? null,
temperature: typeof body.temperature === "number" ? body.temperature : 1.0,
tools: body.tools ?? null,
tool_choice: body.tool_choice ?? null,

View File

@@ -226,8 +226,16 @@ export const MODEL_SPECS: Record<string, ModelSpec> = {
},
// ── Gemini 3.5 Flash ─────────────────────────────────────────────
// #10286: the base Google AI Studio model DOES support reasoning (it has
// an effort-tier alias gemini-3.5-flash-high) — override the shared spec's
// supportsThinking:false here only. Do NOT flip GEMINI_35_FLASH_MODEL_SPEC
// itself: it is also spread into the Antigravity flash-tier aliases
// (gemini-3.5-flash-low/-extra-low, gemini-3-flash-agent, gemini-3.6-flash-*)
// which reject client-supplied thinking params because the model id itself
// selects the reasoning tier upstream.
"gemini-3.5-flash": {
...GEMINI_35_FLASH_MODEL_SPEC,
supportsThinking: true,
aliases: ["gemini-3.5-flash-high"],
},

View File

@@ -0,0 +1,76 @@
// Regression test for #10286: gemini-3.5-flash was incorrectly marked
// supportsThinking:false, causing a spurious pre-provider HTTP 400 for any
// request with reasoning_effort set, even though the base Google AI Studio
// model supports reasoning (it has an effort-tier alias gemini-3.5-flash-high).
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-repro-10286-"));
process.env.DATA_DIR = TEST_DATA_DIR;
process.env.API_KEY_SECRET = process.env.API_KEY_SECRET || "test-repro-10286-secret";
const caps = await import("../../src/lib/modelCapabilities.ts");
const core = await import("../../src/lib/db/core.ts");
const rulesDb = await import("../../src/lib/db/reasoningRoutingRules.ts");
const policy = await import("../../src/lib/reasoningRouting/policy.ts");
async function resetStorage() {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
rulesDb.invalidateReasoningRoutingRuleCache();
}
function ruleInput(patch: Record<string, unknown> = {}) {
return {
name: "Enable thinking on gemini-3.5-flash",
description: "",
scope: "global",
apiKeyId: null,
comboId: null,
connectionId: null,
modelPattern: "gemini-3.5-flash",
sourceEffort: "any",
requestTags: [],
tagMatchMode: "any",
effortMode: "inherit",
targetEffort: null,
targetKind: "keep",
targetModel: null,
targetComboId: null,
budgetAction: "preserve",
budgetTokens: null,
priority: 0,
enabled: true,
...patch,
};
}
test.beforeEach(resetStorage);
test.after(async () => {
await resetStorage();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
});
test("gemini-3.5-flash (AI Studio provider) resolves as thinking-capable", () => {
const resolved = caps.getResolvedModelCapabilities({
provider: "gemini",
model: "gemini-3.5-flash",
});
assert.equal(resolved.supportsThinking, true);
});
test("reasoning_effort 'high' on gemini-3.5-flash is NOT rejected by routing policy", async () => {
await rulesDb.createReasoningRoutingRule(ruleInput());
const decision = await policy.resolveReasoningRoutingRule({
sourceModel: "gemini/gemini-3.5-flash",
sourceModelAliases: ["gemini-3.5-flash"],
sourceEffort: "high",
hasReasoningSignal: true,
});
assert.ok(decision, "a matching rule must produce a decision");
assert.equal(decision.capability, "supported");
});

View File

@@ -1,91 +0,0 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { computeRequestHash, deduplicate, clearInflight } from "../../open-sse/services/requestDedup.ts";
// Regression tests for #10249: the dedup hash used to read only `body.messages`,
// so translated (target-format) bodies that carry the prompt under a different
// key (`contents` for Gemini, `input` for the Responses API) always hashed the
// prompt as `null`. Concurrent requests with different prompts then collided on
// the same dedup hash, joined the same in-flight promise, and the second caller
// silently received the first caller's response.
test("Gemini-format translated bodies with different prompts must NOT collide on dedup hash", async () => {
clearInflight();
const bodyA = {
contents: [{ role: "user", parts: [{ text: "Summarize the Q3 financial report attached." }] }],
temperature: 0,
};
const bodyB = {
contents: [{ role: "user", parts: [{ text: "Extract every invoice number from the attached PDF." }] }],
temperature: 0,
};
const hashA = computeRequestHash({ ...bodyA, model: "gemini/gemini-2.5-flash", stream: false });
const hashB = computeRequestHash({ ...bodyB, model: "gemini/gemini-2.5-flash", stream: false });
assert.notEqual(hashA, hashB, "Different prompts must have different dedup hashes");
const [resA, resB] = await Promise.all([
deduplicate(hashA, async () => "RESPONSE_A"),
deduplicate(hashB, async () => "RESPONSE_B"),
]);
assert.equal(resA.result, "RESPONSE_A");
assert.equal(resB.result, "RESPONSE_B");
assert.equal(resB.wasDeduplicated, false);
});
test("Responses-API input-format translated bodies with different prompts must NOT collide", async () => {
clearInflight();
const bodyA = {
input: [{ role: "user", content: [{ type: "input_text", text: "What is the capital of France?" }] }],
temperature: 0,
};
const bodyB = {
input: [{ role: "user", content: [{ type: "input_text", text: "Explain quantum entanglement." }] }],
temperature: 0,
};
const hashA = computeRequestHash({ ...bodyA, model: "openai/gpt-4.1", stream: false });
const hashB = computeRequestHash({ ...bodyB, model: "openai/gpt-4.1", stream: false });
assert.notEqual(hashA, hashB, "Different prompts must have different dedup hashes");
const [resA, resB] = await Promise.all([
deduplicate(hashA, async () => "RESPONSE_A"),
deduplicate(hashB, async () => "RESPONSE_B"),
]);
assert.equal(resA.result, "RESPONSE_A");
assert.equal(resB.result, "RESPONSE_B");
assert.equal(resB.wasDeduplicated, false);
});
test("Sanity: OpenAI-format bodies with different prompts DO get distinct hashes (unchanged behavior)", () => {
const bodyA = { messages: [{ role: "user", content: "Hello there" }], temperature: 0 };
const bodyB = { messages: [{ role: "user", content: "Goodbye now" }], temperature: 0 };
const hashA = computeRequestHash({ ...bodyA, model: "openai/gpt-4.1", stream: false });
const hashB = computeRequestHash({ ...bodyB, model: "openai/gpt-4.1", stream: false });
assert.notEqual(hashA, hashB);
});
test("Genuinely identical requests still hash identically and get deduplicated (perf feature preserved)", async () => {
clearInflight();
const body = {
contents: [{ role: "user", parts: [{ text: "Same prompt text every time" }] }],
temperature: 0,
};
const hash1 = computeRequestHash({ ...body, model: "gemini/gemini-2.5-flash", stream: false });
const hash2 = computeRequestHash({ ...body, model: "gemini/gemini-2.5-flash", stream: false });
assert.equal(hash1, hash2, "Identical bodies must still produce the same hash");
let callCount = 0;
const slowFn = async () => {
callCount += 1;
await new Promise((resolve) => setTimeout(resolve, 20));
return "SHARED_RESPONSE";
};
const [resA, resB] = await Promise.all([
deduplicate(hash1, slowFn),
deduplicate(hash2, slowFn),
]);
assert.equal(resA.result, "SHARED_RESPONSE");
assert.equal(resB.result, "SHARED_RESPONSE");
assert.equal(callCount, 1, "Identical concurrent requests must share a single upstream call");
assert.equal(resA.wasDeduplicated === true || resB.wasDeduplicated === true, true);
});