Repository navigation
feat(core): move ChatGPT context caps into a separate plugin - #58194
Conversation
There was a problem hiding this comment.
I found nothing that should block a merge, and the change works as described. I ran a server from each checkout with a fake Sign in with ChatGPT (token sharing) credential and listed the models through /api/model:
- Base: every OpenAI model reports 1.05M context / 922k input.
- This PR: gpt-6.1-sol and gpt-6.1-sol-fast report 628k / 500k. gpt-6-, gpt-5.6- and gpt-5.5 report 400k / 272k.
- Opt-out:
"plugins": ["-opencode.provider.openai-context-caps"]restores the full windows. - Per-model override: a
limitset on one model in config wins, with the plugin on or off.
The three provider test files pass (31 tests), the new test file passes under --rerun-each 10, and typecheck in packages/core is clean. The new test is small and clear.
Public API: the only addition is the plugin ID opencode.provider.openai-context-caps, which config can now name (backwards compatible). Behaviour changes: token-sharing sign-ins drop from about 922k input to 500k or 272k, and newer models (gpt-7 and later) on the legacy Codex sign-ins go from 272k to 500k.
There was a problem hiding this comment.
Since the last review, the only new commit shortens the ChatGPT docs in providers.mdx. The new text still matches the code: the 500k/272k caps for ChatGPT sign-ins and the -opencode.provider.openai-context-caps opt-out. No code changed, so the earlier verification still applies. I found no new concerns.
Public API: unchanged since the last review. The only addition is the plugin ID opencode.provider.openai-context-caps, which config can now name (backwards compatible).
Issue for this PR
None
Type of change
What does this PR do?
Problem: The ChatGPT context caps were hardcoded inside the OpenAI plugin. They only covered the legacy Codex sign-ins, so Sign in with ChatGPT (token sharing) got each model's full 1.05M window. They also couldn't be turned off and weren't documented.
Change: Move the caps into their own plugin,
opencode.provider.openai-context-caps. It applies to all three ChatGPT sign-in methods. API-key connections are untouched.packages/core/src/plugin/ ├── provider.ts # registers the new plugin └── provider/ ├── openai.ts # keeps filtering, cost, headers; no longer sets limits + └── openai-context-caps.ts # only lowers limitsThe 272k and 500k values are the
context_windowdefaults returned by the live ChatGPT model list. That list also reports a 872kmax_context_window. When probed directly, the backend accepted 921,522 input tokens and rejected 921,922, so it enforces only the model's real ~922k window. The caps are a usage choice, not a backend requirement.Users can opt out with
"plugins": ["-opencode.provider.openai-context-caps"], or override one model'slimitin config, which applies after the plugin.Docs: a new ChatGPT section in
providers.mdxcovers the sign-in methods, why the limits exist, the limit table, and both ways to change them.Out of scope: model sync for token sharing is still commented out in
chatgpt.ts. When it returns, it can record the server's default and this plugin can apply it instead of its fixed values.How did you verify your code works?
bun run script/test.ts test/plugin/provider-openai-context-caps.test.ts test/plugin/provider-openai.test.ts test/plugin/provider-chatgpt.test.tsinpackages/core: 31 pass. The new test covers all three sign-in methods, the 6.1+ rule, an unchanged smaller model, and an API key that keeps the full window.--rerun-each 10on the new test file: 40 pass.bun run checkfrom the repo root: 34/34 tasks successful.Screenshots / recordings
N/A
Checklist
Added by the opencode bot (AI-generated).
Related: #47646, #46527
Public API: adds the internal plugin ID
opencode.provider.openai-context-caps, which config can disable (backwards compatible)