Repository navigation
fix(google): clamp max output tokens per model, without inventing a ceiling for unknown ids (rebase of #2512) #2576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { clampGoogleMaxOutputTokens, maxOutputTokensForGoogleModel } from "../src/adapters/google"; | ||
|
|
||
| describe("google maxOutputTokens clamp", () => { | ||
| test("returns model-specific max output tokens limit", () => { | ||
| expect(maxOutputTokensForGoogleModel("gemini-3.7-flash")).toBe(65536); | ||
| expect(maxOutputTokensForGoogleModel("gemini-3.7-flash-tiered")).toBe(65536); | ||
| expect(maxOutputTokensForGoogleModel("gemini-3-pro")).toBe(65535); | ||
| expect(maxOutputTokensForGoogleModel("claude-3-7-sonnet")).toBe(64000); | ||
| expect(maxOutputTokensForGoogleModel("claude-3-5-sonnet@20241022")).toBe(64000); | ||
| expect(maxOutputTokensForGoogleModel("gpt-oss-120b")).toBe(32768); | ||
| }); | ||
|
|
||
| test("an unrecognized model has no invented ceiling", () => { | ||
| // A cap we cannot justify silently truncates the operator's explicit request. Aliases, | ||
| // gateway ids, and models newer than this table must pass through untouched. | ||
| expect(maxOutputTokensForGoogleModel("custom-unknown-model")).toBeUndefined(); | ||
| expect(clampGoogleMaxOutputTokens("custom-unknown-model", 128000)).toBe(128000); | ||
| expect(maxOutputTokensForGoogleModel("some-gateway/gemini-3-pro")).toBeUndefined(); | ||
| }); | ||
|
|
||
| test("family matching does not fire on incidental substrings", () => { | ||
| // "includes(pro)" matched my-prototype-model; "includes(oss)" matched crossover-v2. | ||
| expect(maxOutputTokensForGoogleModel("my-prototype-model")).toBeUndefined(); | ||
| expect(maxOutputTokensForGoogleModel("crossover-v2")).toBeUndefined(); | ||
| expect(maxOutputTokensForGoogleModel("gemini-3-pro-preview")).toBe(65535); | ||
| expect(maxOutputTokensForGoogleModel("gemini-3.5-flash")).toBe(65536); | ||
| }); | ||
|
|
||
| test("downward clamps excessive requested tokens to model max", () => { | ||
| expect(clampGoogleMaxOutputTokens("gemini-3.7-flash", 128000)).toBe(65536); | ||
| expect(clampGoogleMaxOutputTokens("gemini-3-pro", 100000)).toBe(65535); | ||
| expect(clampGoogleMaxOutputTokens("claude-3-7-sonnet", 100000)).toBe(64000); | ||
| expect(clampGoogleMaxOutputTokens("gpt-oss-120b", 64000)).toBe(32768); | ||
| }); | ||
|
|
||
| test("preserves requested tokens when within model max", () => { | ||
| expect(clampGoogleMaxOutputTokens("gemini-3.7-flash", 4096)).toBe(4096); | ||
| expect(clampGoogleMaxOutputTokens("gemini-3-pro", 8192)).toBe(8192); | ||
| expect(clampGoogleMaxOutputTokens("claude-3-7-sonnet", 32000)).toBe(32000); | ||
| }); | ||
|
|
||
| test("returns undefined when requested tokens is undefined or non-positive", () => { | ||
| expect(clampGoogleMaxOutputTokens("gemini-3.7-flash", undefined)).toBeUndefined(); | ||
| expect(clampGoogleMaxOutputTokens("gemini-3.7-flash", 0)).toBeUndefined(); | ||
| expect(clampGoogleMaxOutputTokens("gemini-3.7-flash", -10)).toBeUndefined(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When Google Antigravity live discovery selects
claude-sonnet-4-6-thinking, the repository metadata atscripts/model-metadata.source.json:12511-12529records a 128,000-token output limit, but this family-wide branch makesclampGoogleMaxOutputTokens(..., 100000)return 64,000. Before this change the requested 100,000 tokens reached upstream; now it is silently truncated, so read exact ceilings from the canonical provider metadata and pass through unmatched Claude IDs rather than treating every Claude model as 64,000.AGENTS.md reference: src/AGENTS.md:L18-L18
Useful? React with 👍 / 👎.