Skip to content

fix(opencode): add input limit for compaction - #8465

Merged
rekram1-node merged 5 commits into
anomalyco:devfrom
bndnsmth:openai-codex-input-limit
Jan 15, 2026
Merged

rekram1-node merged 5 commits into
anomalyco:devfrom
bndnsmth:openai-codex-input-limit

Conversation

@bndnsmth

@bndnsmth bndnsmth commented Jan 14, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

How did you verify your code works?

  • Tested with several large sessions via bun dev to confirm compaction triggers

Copilot AI review requested due to automatic review settings January 14, 2026 14:35
@github-actions

Copy link
Copy Markdown
Contributor

Hey! Your PR title openai: add input limit for codex-5.2 doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@bndnsmth bndnsmth changed the title openai: add input limit for codex-5.2 fix(opencode): add input limit for codex-5.2 Jan 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR attempts to address the ChatGPT Pro plan's lower context limit compared to the API limit by adding an input field to the model's limit configuration for the gpt-5.2-codex model.

Changes:

  • Added input: 272000 to the limit object for the gpt-5.2-codex model configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/opencode/src/plugin/codex.ts Resolved
@bndnsmth
bndnsmth marked this pull request as draft January 14, 2026 14:46
@bndnsmth
bndnsmth marked this pull request as ready for review January 14, 2026 15:16
const count = input.tokens.input + input.tokens.cache.read + input.tokens.output
const output = Math.min(input.model.limit.output, SessionPrompt.OUTPUT_TOKEN_MAX) || SessionPrompt.OUTPUT_TOKEN_MAX
const usable = context - output
const usable = input.model.limit.input || context - output

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an input limit is provided, it's always the usable limit. This can be less than context - output.

@bndnsmth
bndnsmth marked this pull request as ready for review January 14, 2026 17:23
@bndnsmth

bndnsmth commented Jan 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Auto-compaction now triggers based on the optional input limit.

There is a separate issue (I believe with all models) where the next outgoing message can overrun context/input limits. In this scenario, the error should be caught with an auto-compaction running on thread history, and then a retry of the latest message occurring. Perhaps integrated into SessionRetry.retryable with a force auto-compaction. I won't attempt that in this PR.

@@ -361,38 +361,6 @@ export async function CodexAuthPlugin(input: PluginInput): Promise<Hooks> {
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See anomalyco/models.dev#646, this is now upstream including limit.input

@bndnsmth bndnsmth changed the title fix(opencode): add input limit for codex-5.2 fix(opencode): add input limit for compaction Jan 14, 2026
@rekram1-node

Copy link
Copy Markdown
Collaborator

/review

@rekram1-node

Copy link
Copy Markdown
Collaborator

What a G

@github-actions

Copy link
Copy Markdown
Contributor

lgtm

@rekram1-node

Copy link
Copy Markdown
Collaborator

Auto-compaction now triggers based on the optional input limit.

There is a separate issue (I believe with all models) where the next outgoing message can overrun context/input limits. In this scenario, the error should be caught with an auto-compaction running on thread history, and then a retry of the latest message occurring. Perhaps integrated into SessionRetry.retryable with a force auto-compaction. I won't attempt that in this PR.

Yeah i mean this is awesome so thank you! Interesting idea would like to see it

@rekram1-node
rekram1-node merged commit 8d720f9 into anomalyco:dev Jan 15, 2026
5 checks passed
@greggh

greggh commented Jan 16, 2026

Copy link
Copy Markdown

Can this be an option to deal with models that get a bit weird or just plain broken long before their context window ends? The zai coding plan really starts to degrade fast into errors for a lot of us (See other threads) around 120k context. It would be interesting to be able to set this limit to 120k and have it auto compact at that point for that model.

@bndnsmth

Copy link
Copy Markdown
Contributor Author

@greggh the input limit is available in the config. You could provide a custom model config:

"providerId": {
    "models": {
      "modelId": {
        "limit": { "input": 120000, "context": 200000 },
      },
    },
  },

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default Codex context length not matching Pro plan

4 participants