Skip to content

GPT 5.5 **SMALLER** context limits are not respected #24751

Closed

Description

@asaf-genie

Description

opencode uses hard coded context limits values for gpt-5.5, ignoring values set in opencode.jsonc.

I suspect it's due to PR #24212 which added this to codex.ts:

// gpt-5.5 models temporarily have restricted context window size for codex plans
if (model.id.includes("gpt-5.5")) {
  model.limit = {
    context: 400_000,
    //@ts-expect-error incorrect type for v1 sdk but works
    input: 272_000,
    output: 128_000,
  }
}

It should probably either overwrite only when the values are not specified in the config, or use max(400_000, model.limit.context) (same for input/output) to allow lower values (which is useful because gpt-5.5 is very expensive)

Plugins

None

OpenCode version

1.14.28

Steps to reproduce

  1. Add this to ~/.config/opencode/opencode.jsonc in provider.openai.models:
"gpt-5.4": {
  "limit": {
    "context": 200000,
    "input": 150000,
    "output": 50000,
  },
},
"gpt-5.5": {
  "limit": {
    "context": 200000,
    "input": 150000,
    "output": 50000,
  },
},
  1. Run opencode models openai --verbose and check context limits for both models. gpt-5.4 will respect the overrides, gpt-5.5 will not. Alternatively, start a conversation with gpt-5.5, you'll see that the context window stats are relative to 400k context window not 200k.

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 28, 2026
  2. github-actions commented on Apr 28, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of (or closely related to) an existing issue. Please check:

  3. sjawhar commented on Apr 29, 2026

    @sjawhar

    Confirming this. I just chased the same bug — running openai/gpt-5.5 via Codex OAuth on a Pro/Plus plan, compaction kicks in around ~250k tokens despite the model having 922k input / 1M context.

    Root cause is exactly what you identified: CodexAuthPlugin.auth.loader in packages/opencode/src/plugin/codex.ts:394-402 unconditionally replaces model.limit for any gpt-5.5 model:

    if (model.id.includes("gpt-5.5")) {
      model.limit = {
        context: 400_000,
        input: 272_000,
        output: 128_000,
      }
    }

    The user-config override in provider.ts runs after this, but only applies fields the user explicitly set:

    if (configLimit) {
      if (configLimit.context) model.limit.context = configLimit.context
      if (configLimit.input) model.limit.input = configLimit.input
      if (configLimit.output) model.limit.output = configLimit.output
    }

    So a user who only sets { context: 1050000, output: 128000 } (the natural pattern, since input is implied) silently keeps input: 272000 from the plugin hardcode. With usable() = input - reserved = 252_000, compaction triggers at the first 250k+ message.

    Debug evidence — the relevant overflow check from a real session before the workaround:

    service=session.overflow modelID=gpt-5.5 
      tokens={"total":647998,"input":1,"output":158,"reasoning":0,"cache":{"write":524,"read":647315}} 
      count=647998 limit=252000 overflow=true 
      modelLimit={"context":1050000,"input":272000,"output":128000}
    

    Note modelLimit.input=272000 despite context=1050000 — that's the user's context override applied while input stayed at the codex hardcode.

    Workaround: explicitly add all three fields to user config:

    "openai": {
      "models": {
        "gpt-5.5": {
          "limit": {
            "context": 1050000,
            "input": 922000,   // <-- this is the field that gets silently overwritten
            "output": 128000
          }
        }
      }
    }

    Proposed real fix: when user provides any explicit limit override, fall back to the original models.dev snapshot for unspecified fields (not to whatever a plugin auth.loader has mutated the limit to). I have an implementation on a fork: sjawhar@f4ab23a6270e — it captures the original limits before plugin loaders run, then uses them as the fallback in the override loop. The plugin still gets to enforce its restriction when no user override exists, but the user's intent wins when they have explicitly configured the model.

    Tested with the same gpt-5.5 + Codex OAuth setup — compaction now correctly fires near the 902k threshold (922k input - 20k reserved) instead of 252k.

  4. rekram1-node commented on Apr 29, 2026

    @rekram1-node
    Collaborator

    this is NOT a bug, this is the context limit for the openai codex oauth model right now, only the api gets the 1M context window

  5. sjawhar commented on Apr 29, 2026

    @sjawhar

    Correction to my earlier comment — my proposed "snapshot fallback" fix was wrong, and I've reverted it.

    The 400k context cap on Codex (ChatGPT subscription) gpt-5.5 is server-side enforced by Codex, not just a client-side hardcode. Per OpenAI's launch announcement (Apr 23, 2026):

    In Codex, GPT-5.5 is also available for Edu and Go plans with a 400K context window

    The context window in Codex is 400K tokens, not the 1M available through the Chat API.

    API access is coming "very soon"

    So CodexAuthPlugin's hardcode {context: 400_000, input: 272_000, output: 128_000} correctly reflects what Codex actually serves. Letting users override this with snapshot defaults causes the conversation to grow past Codex's hard cap, then triggers reactive context_length_exceeded errors and emergency compaction (verified — the binary I built with the override-bypass fix produces noticeably worse behavior than the default).

    The original report (this issue and #24561) appears to actually be the same Codex tier limit, not a config-respect bug. The hardcode is doing its job.

    The legitimate underlying problem is: users on the developer API tier (1M context) currently can't use it because gpt-5.5 hasn't been released for general API access yet (per OpenAI's announcement). Once it ships:

    • API key auth (auth.type === "api"): codex.ts loader doesn't fire, so the snapshot's 1M is used → user can choose to override
    • OAuth/Codex auth (auth.type === "oauth"): plugin enforces 400k → matches server reality

    For now, ChatGPT subscription users have to live with 400k context (252k usable input after the 20k compaction buffer) for gpt-5.5. That's an OpenAI product decision, not an opencode bug.

    Apologies for the earlier confusion. Reverted: sjawhar@f3872ba848b2

  6. asaf92 commented on Apr 29, 2026

    @asaf92

    this is NOT a bug, this is the context limit for the openai codex oauth model right now, only the api gets the 1M context window

    @rekram1-node I'm not talking about 1 million context window. I'm trying to set a shorter length of 200k, and it gets changed to the hardcoded values.

  7. rekram1-node commented on Apr 29, 2026

    @rekram1-node
    Collaborator

    Ah sorry the other notes confused me, yeah let me look at that

  8. changed the title [-]GPT 5.5 context limits are not respected[/-] [+]GPT 5.5 **SMALLER** context limits are not respected[/+] on Apr 30, 2026
  9. asaf-genie commented on Apr 30, 2026

    @asaf-genie
    Author

    Thanks, I also changed the title to make it clear.
    Do I need to open a new issue or is it possible to reopen this one?

  10. rekram1-node commented on Apr 30, 2026

    @rekram1-node
    Collaborator

    re-opened

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions