MisakaNatsuxun (Discord, 10-23) set a custom OpenAI-compatible provider's
Advanced > Context window to 1M. Routing still showed 200K for
deepseek-v4.1-flash-free, and dsh was told contextWindow 200000.
Cause: WindowOf capped the provider-wide "*" window at ListedWindow(m)
(#2112, 273ab9c23). ListedWindow falls back to catalog.ContextOf, a guess
by model id from any vendor on models.dev. For a relay with no catalog of
its own, opencode's deepseek-v4.1-flash-free (200000) or Anthropic's
claude-sonnet-4-5 (200000) capped the user's 1M. WindowOf feeds Served,
so /v1/models, the Routing picker, the editor's model chips and every
agent config (dsh's contextWindow too) got 200K.
Fix: "*" is capped only by the provider's own word: catalog.Window
(m.Context, set from its live list, its own models.dev catalog or plan
models) and m.MaxContext. #2112's OpenCode Go case still caps, since that
catalog sets m.Context. A per-model entry already won and still does.
Siblings: Max output (replyLimit) already took the user's value over
m.Output and the catalog, on old and new (checked "*"=128000). Anthropic-
and Responses-type custom providers read the same WindowOf and are fixed
with it. Left alone: with no window set, OutputWithin still caps a
user's Max output at the guessed window.
Tests, each red on the old code (ListedWindow put back by hand):
- provider TestProviderWindowSetOverAnotherVendorsGuess: "map[*:1000000]:
claude-sonnet-4-5 told 200000, want 1000000"
- agent TestDshToldTheWindowSetForACustomProvider (opencode's
deepseek-v4.1-flash-free fixture, dshRouteConfig and
dshProviderLines): told contextWindow 200000
Sandbox HOME, fake OpenAI /models on 127.0.0.1:3481, relay "*"=1M:
- old binary: /v1/models relay/deepseek-v4.1-flash-free 200000,
relay/claude-sonnet-4-5 200000; connecting dsh wrote contextWindow
200000; no 1M on the Sonnet chip in the editor or the Routing picker.
- new binary (this tree, -tags dev): 1000000 for both, dsh config
written fresh says contextWindow 1000000 / maxTokens 32000 (ca4a1cde0's
cap at the model's output); Routing picker "DeepSeek V4.1 Flash Free
1M"; relay-a (anthropic), relay-r (responses) 1M; relay-lo "*"=128K
stays 128000.
Not tried: a real relay account, and dsh making a real request.
Run at 62cf0c76d (this tree on origin/main 032d88c13): gofmt -l clean;
go vet darwin, linux -tags nogui, windows clean; go test -tags nogui
-timeout 45m ./... : 69 ok, 19 no test files, no FAIL (agent 336s,
gateway 474s, gui 123s, provider 187s). GUI files in chromium and
webkit: context-picks 10/10, provider-advanced-fold 25/25,
provider-output-picks 2/2, compact-at 4/4, gui-ja 3/3, gui-zh-tw 3/3,
gui-de 3/3, i18n-keys 3/3.
OpenCode Go set to 512K for all its models (Contexts["*"]) told Claude
Code 512K for cat-jam-free too, whose window is 262144 (models.dev), so
Claude Code ran past the model's real window before compacting and the
vendor refused the request.
WindowOf now caps the "*" value at the model's own window when one is
known: the listed window (vendor list or models.dev), or the larger
max_context_window a model may be raised to (Codex's 872K), so a Codex
raised to 600K stays raised. A model with no known window takes the "*"
value as before, and a window set for the model itself is the user's
word and is told as set. The gateway's windowOf (fallback.go) reads the
served entry's window, which is WindowOf's, after a per-model value, so
the gateway's own fit uses the same number the agent is told.
Run:
- TestProviderWindowNoLargerThanTheModels: the models.dev bytes for
opencode-go cat-jam-free (262144) and a 1M model with "*" at 512000:
262144, 512000, 512000 for an unknown model, a per-model 400000 kept;
Codex 272K/872K with "*" 600K stays 600K, capped at a 400K max. FAILs
on the old WindowOf (cat-jam-free told 512000).
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows on
internal/provider and internal/gateway; go test -tags nogui
./internal/provider/ ./internal/gateway/.
Not tried: a real OpenCode Go account with Claude Code.