fix(tokens): generalize Gemini context-window detection by tier

windowByModelFamily matched Gemini models by exact version substring
("gemini-1.5-pro", "gemini-1.5-flash", "gemini-2"), so any newer
generation (3.x and beyond) fell through to defaultRemoteUnknownWindow
(128k) purely because this table hadn't been updated yet — observed
via hand's status line showing a >100% context gauge for a
"gemini-3.8-flash"-family model whose real window is far larger, and
which made harness's own preventive compaction unreachable (the
threshold check never fires against a window this far off).

Match on tier (Pro vs. everything else) instead of enumerating every
version: every Pro-tier Gemini release so far ships 2M, everything
else at least 1M, and both hold for a model this table has never seen
the exact version string of.
This commit is contained in:
sausheong committed 2026-09-05 22:06:59 +08:00
1 parent 986c233d39
commit 0ba1b4dbcc
2 files changed
+40 -3

No files matched your search

+23
View File
@@ -52,6 +52,29 @@ func TestContextWindowKnown(t *testing.T) {
}
}
// Regression: a Gemini generation newer than the ones explicitly
// enumerated (3.x and beyond) must not fall through to
// defaultRemoteUnknownWindow (128k) just because this table hasn't been
// updated with its exact version string yet — every non-Pro Gemini
// model since 1.5 has shipped at least a 1M window, and every Pro-tier
// release has shipped at least 2M.
func TestContextWindowGeminiFutureGenerationsDefaultByTier(t *testing.T) {
tests := []struct {
model string
want int
}{
{"openai/gemini-3.8-flash-global", 1000000}, // proxied under an unrelated provider label, as via a LiteLLM gateway
{"google/gemini-3-flash", 1000000},
{"google/gemini-3-pro", 2000000},
{"google/gemini-4.0-flash-lite", 1000000},
}
for _, tc := range tests {
t.Run(tc.model, func(t *testing.T) {
assert.Equal(t, tc.want, ContextWindow(tc.model))
})
}
}
func TestContextWindowUnknownRemoteReturnsRemoteFallback(t *testing.T) {
// Non-local unknown models default to 128k — frontier proxies are
// overwhelmingly 128k+, and reactive compaction handles overflow.