Skip to content

Reply: honor per-model context token overrides#32559

Open
zwright8 wants to merge 3 commits intoopenclaw:mainfrom
zwright8:codex/pr26712-reply-context-token-overrides
Open

Reply: honor per-model context token overrides#32559
zwright8 wants to merge 3 commits intoopenclaw:mainfrom
zwright8:codex/pr26712-reply-context-token-overrides

Conversation

@zwright8
Copy link
Copy Markdown

@zwright8 zwright8 commented Mar 3, 2026

Summary

Validation

  • pnpm exec vitest run src/auto-reply/reply/model-selection.test.ts src/auto-reply/reply/directive-handling.model.test.ts

Context

This PR is one focused slice extracted from:

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 3, 2026

Greptile Summary

This PR honors per-model context-token overrides (contextTokens and context1m params) during model selection in the auto-reply pipeline. It extracts the logic into a shared resolveContextTokens helper and ensures consistent usage across both get-reply-directives.ts and directive-handling.persist.ts.

Key changes:

  • model-selection.ts: resolveContextTokens now accepts provider and resolves a per-model entry from agentCfg.models (direct key lookup first, then normalized fallback). Priority order is: global agentCfg.contextTokens → per-model params.contextTokens → per-model context1m → catalog lookup → DEFAULT_CONTEXT_TOKENS.
  • get-reply-directives.ts: Passes the previously-missing provider to resolveContextTokens; the resolved provider from modelState is correctly used before the call.
  • directive-handling.persist.ts: Replaces the inline ad-hoc expression with the shared helper, removing the now-redundant lookupContextTokens / DEFAULT_CONTEXT_TOKENS imports.
  • model-selection.test.ts: Four new unit tests cover the main priority scenarios.

Observation — untested edge case: There is no test for when per-model params has both contextTokens set to an invalid value (e.g., 0 or negative) and context1m: true. Under the current logic this correctly falls through to use CONTEXT_1M_TOKENS, but an explicit test would help prevent regressions if the ternary is ever refactored.

Confidence Score: 5/5

  • This PR is safe to merge — the changes are additive, well-tested, and the priority fallback chain is consistent with existing behaviour.
  • The logic is straightforward: a new provider parameter is threaded through a single helper and the two call-sites are updated consistently. Input validation (finite, positive, truncated) is sound. Four targeted unit tests cover all priority tiers. No existing tests are broken and the behavioural change (per-model override) is additive, not breaking.
  • No files require special attention.

Last reviewed commit: e748da9

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e748da9614

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +636 to +637
: modelParams?.context1m === true
? CONTEXT_1M_TOKENS
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Gate context1m override to supported Anthropic models

This branch treats any params.context1m: true as a universal 1_048_576 token window, but context1m is only valid for supported Anthropic Opus/Sonnet models; for other models/providers, the request path does not enable the matching capability and this inflated limit can let oversized prompts through local truncation, resulting in downstream model-limit failures. This regression appears whenever a model entry has context1m: true outside the supported Anthropic set.

Useful? React with 👍 / 👎.

@zwright8 zwright8 force-pushed the codex/pr26712-reply-context-token-overrides branch from e748da9 to 1b90111 Compare March 3, 2026 05:06
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b901112f1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +617 to +620
const parsed = resolveModelRefFromString({
raw: rawKey,
defaultProvider: params.provider,
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use agent default provider when parsing model keys

In resolveContextTokens, unqualified agents.defaults.models keys are reparsed with defaultProvider: params.provider, which makes keys like gpt-4o follow the currently selected provider instead of the config’s default-provider semantics used elsewhere. When a config includes both an unqualified default-provider entry and an explicit entry for another provider with the same model id, this can select the wrong model params and apply the wrong context token limit for replies.

Useful? React with 👍 / 👎.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant