anomalyco / anomalyco/opencode
fix(openai): OAuth transform treats Codex product budget as endpoint context limit
@jlongster is already working on this.
Since Aug 25, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
OpenCode's ChatGPT OAuth transform treats Codex client/product budget metadata as GPT-5.6 Sol's physical endpoint limit. This causes automatic compaction hundreds of thousands of tokens before the authenticated endpoint reaches its actual limit.
This differs from #38851: that issue reports the premature-compaction symptom, while its current diagnosis assumes the Codex 372k catalog value represents endpoint capacity. A controlled adjacent-boundary experiment contradicts that assumption for the tested account and route.
Environment
- OpenCode:
1.18.18 - Authentication: ChatGPT OAuth
- Model:
openai/gpt-5.6-sol - Platform: macOS arm64
- Test date: 2026-08-24
- External plugins: disabled with
--pure - Automatic compaction: disabled
- Pruning: disabled
- Database: isolated temporary database
Current behavior
OpenCode 1.18.18 resolves the OAuth model limits as:
context: 500,000
input: 372,000
output: 128,000
Current upstream subsequently changed these values to:
context: 400,000
input: 272,000
output: 128,000
That change was merged in #39082.
OpenCode uses the resulting input limit for automatic compaction, even when the authenticated endpoint accepts substantially more input.
Controlled experiment
The experiment used:
- A separate
OPENCODE_DB OPENCODE_DISABLE_AUTOCOMPACT=1OPENCODE_DISABLE_PRUNE=1OPENCODE_DISABLE_PROJECT_CONFIG=1opencode run --pure- A one-step agent with every tool denied
- Deterministic repeated
xtokens - A response instruction of
Reply exactly OK - Separate databases for every request
Representative invocation:
test_dir="$(mktemp -d)"
perl -e 'print " x" x 920752; print "\nReply exactly OK.\n"' |
OPENCODE_DB="$test_dir/opencode.db" \
OPENCODE_DISABLE_AUTOCOMPACT=1 \
OPENCODE_DISABLE_PRUNE=1 \
OPENCODE_DISABLE_PROJECT_CONFIG=1 \
OPENCODE_CONFIG_CONTENT='{
"share": "disabled",
"snapshot": false,
"compaction": {
"auto": false,
"prune": false
},
"permission": "deny",
"agent": {
"probe": {
"mode": "primary",
"model": "openai/gpt-5.6-sol",
"variant": "none",
"steps": 1,
"permission": "deny",
"prompt": "Return exactly OK. Do not use tools."
}
}
}' \
opencode run \
--pure \
--agent probe \
--model openai/gpt-5.6-sol \
--variant none \
--dir "$test_dir"
The payload repetition count may require adjustment when local/global system instructions differ. The authoritative count below is the provider-reported input usage.
Results
A bounded binary search produced adjacent outcomes:
| Provider input | Result |
|---|---|
| 921,858 | Accepted |
| 921,859 target | ContextOverflowError |
The accepted request reported:
input: 921,858
output: 5
finish: stop
response: OK
No compaction markers were recorded.
The rejected response did not return usage metadata. Its 921,859 target is inferred from an otherwise identical deterministic payload containing exactly one additional x token.
The normal OpenCode database received no probe sessions.
Expected behavior
OpenCode should not assume that a Codex client/product context budget is the physical capacity of the ChatGPT OAuth endpoint.
It should either:
- Obtain account- and route-specific capacity metadata from the authenticated endpoint; or
- Support an explicit model-limit override that survives the OAuth transform.
A conservative compaction reserve should remain in place after resolving the correct input capacity.
Analysis
The current behavior originated from this sequence:
- #36247 and #36248 copied the then-current Codex 372k catalog budget into OpenCode's OAuth model limits.
- #38976 and #39082 later copied Codex CLI 0.144.6's lower 272k catalog budget.
- Those changes were verified against Codex catalog files and unit tests, not direct OAuth requests above the catalog budget.
Codex catalog values can represent subscription usage policy, account entitlement, rollout policy, or client safety budgeting. They do not necessarily represent the endpoint's physical context capacity.
The observed endpoint accepted approximately the complete public GPT-5.6 Sol input window for this account and route. OpenAI's public API documentation lists:
context: 1,050,000
input: 922,000
output: 128,000
This report does not claim that every ChatGPT plan, account, originator, or route has the same capacity. It demonstrates that one universal hardcoded OAuth value is not valid for the tested route.
Proposed resolution
Please avoid replacing endpoint-capacity metadata with a static Codex product budget.
Possible solutions:
- Preserve an explicit
provider.openai.models.<model>.limitoverride after OAuth transformation. - Resolve limits dynamically from authenticated account/route metadata.
- Represent Codex product budgeting separately from physical model limits.
- Use conservative static values only as fallbacks when route-specific metadata is unavailable.
This is not a request to hardcode 921,858 globally.
Related issues and changes
- #38851 - premature compaction symptom
- #36247 - original GPT-5.6 OAuth limit report
- #36248 - introduced 500k/372k/128k mapping
- #38976 - requested reduction following Codex catalog changes
- #39082 - merged 400k/272k/128k mapping
- openai/codex#40258 - originator-dependent Codex catalog behavior
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.