Skip to content

Anvil does not parse context sizes for chatgpt models #376

Description

@Infinoid

Affected surface

Model or provider routing

What did Anvil do?

It seems anvil does not parse the context size of codex::gpt-5.6-luna and other codex models, from the CHATGPT_MODELS_URL response. Anvil then falls back to a default value of 128000, sending the wrong size limit to the ACP client, and summarizing more often than necessary.

What should it have done?

Parse the model's max context and use it. It looks like the endpoint returns model data like:

{
  "slug": "gpt-5.6-luna",
  "context_window": 272000,
  "max_context_window": 872000,
  …
}

Those numbers look the same for all gpt-5.6-* models. They don't match the model's documented limit of 1050000 tokens, but the numbers do exist, and Anvil should use them.

Alternately, you could make the magic fallback number configurable.

Reproduction

  • have a valid ~/.codex/auth.json (OIDC token)
  • Run ACP server: anvil --default-model=codex::gpt-5.6-luna
  • send /context
  • see "Context window: N tokens used (model max unknown)" in the response

Session and environment

Linux, anvil 0.28.4, codex::gpt-5.6-luna.

Transcript, logs, or protocol messages

Model detection snippet:

2026-09-20T19:42:53.386669Z  INFO anvil: Codex backend enabled in ChatGPT subscription mode (Responses API on chatgpt.com)
...
2026-09-20T19:42:53.593638Z  INFO anvil_client::codex_client: using Codex models manifest client_version for ChatGPT model discovery client_version=0.153.0
2026-09-20T19:42:54.101853Z  INFO anvil_client::codex_client: ChatGPT /models returned 5 slugs after filtering: ["gpt-5.5", "gpt-5.6-luna", "gpt-5.6-terra", "gpt-5.6-sol", "gpt-6-astra"]
2026-09-20T19:42:54.101919Z  INFO anvil: startup discovery: 5 model(s) found

/context:

Session context

  • Working directory: /home/infinoid/dev
  • Mode: LUTZ
  • Permission mode: auto
  • Model: codex::gpt-5.6-luna (5 known in catalog)
  • Context window: 84384 tokens used (model max unknown)
  • Conversation turns: 11 (~305 user / ~3908 agent / ~80171 tool exchanges)

/setup codex status:

Codex login status:
auth_mode: chatgpt
routing: ChatGPT subscription (Responses API on chatgpt.com)
api_key: n/a (ChatGPT-only account; subscription routing does not need one)
[snip account ids]

ACP usage report with incorrect size:

[2026-09-20T18:28:27.529Z] <<< AGENT → CLIENT [NOTIFICATION] session/update
{
  "jsonrpc": "2.0",
  "method": "session/update",
  "params": {
    "sessionId": "0444c834-399a-4835-abb3-86cfea7cd015",
    "update": {
      "sessionUpdate": "usage_update",
      "used": 68350,
      "size": 128000,
      "cost": {
        "amount": 0,
        "currency": "USD"
      }
    }
  }
}

Activity

  1. added a commit that references this issue on Sep 20, 2026
    1174409
  2. Infinoid commented on Sep 20, 2026

    @Infinoid
    Author

    I was unable to open a PR due to repo permissions. But with this patch, I verified locally that parsing context_window and passing it through was enough to get it working.

    With that patch, the size is correct:

    [2026-09-20T20:41:26.692Z] <<< AGENT → CLIENT [NOTIFICATION] session/update
    {
      "jsonrpc": "2.0",
      "method": "session/update",
      "params": {
        "sessionId": "0444c834-399a-4835-abb3-86cfea7cd015",
        "update": {
          "sessionUpdate": "usage_update",
          "used": 32350,
          "size": 272000,
          "cost": {
            "amount": 0,
            "currency": "USD"
          }
        }
      }
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions