Skip to content

fix: prioritize predefined model context_limit over canonical registry#7888

Merged
DOsinga merged 2 commits intoblock:mainfrom
extrasmall0:fix/predefined-model-context-limit-priority
Mar 25, 2026
Merged

fix: prioritize predefined model context_limit over canonical registry#7888
DOsinga merged 2 commits intoblock:mainfrom
extrasmall0:fix/predefined-model-context-limit-priority

Conversation

@extrasmall0
Copy link
Copy Markdown
Contributor

When a model is configured via GOOSE_PREDEFINED_MODELS with a custom context_limit (e.g., 1M for extended context), the value is ignored if the same model exists in the canonical registry. The canonical lookup runs first in with_canonical_limits() and sets context_limit to its default (200k for most models), so the predefined check never fires since context_limit is already Some(...).

This causes auto-compaction to trigger at ~160k tokens instead of the configured 1M, destroying conversation history mid-session.

The fix moves the predefined models check before the canonical registry lookup. Since predefined models represent explicit operator configuration, they should take priority over generic defaults. The env var (GOOSE_CONTEXT_LIMIT) still has the highest priority since it is resolved in new_base() before with_canonical_limits() runs.

Resolution chain after this fix:

Priority Source Behavior
1 GOOSE_CONTEXT_LIMIT env var Set in new_base(), never overwritten
2 GOOSE_PREDEFINED_MODELS Checked first in with_canonical_limits()
3 Canonical model registry Fallback if neither above sets the value

Fixes #7839

GOOSE_PREDEFINED_MODELS context_limit was never used when the model
also existed in the canonical registry, because the canonical lookup
ran first and always set context_limit to its default (e.g. 200k).

Move the predefined models check before the canonical registry lookup
so explicitly configured limits take priority.

Fixes block#7839

Signed-off-by: Extra Small <[email protected]>
@extrasmall0 extrasmall0 force-pushed the fix/predefined-model-context-limit-priority branch from 9b4551d to 0b82cac Compare March 14, 2026 16:04
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: 0b82cac67e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

pub fn with_canonical_limits(mut self, provider_name: &str) -> Self {
// Check predefined models first — these are explicitly configured by the
// operator/deployment and should take priority over generic canonical defaults.
if let Some(pm) = find_predefined_model(&self.model_name) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Match predefined models by provider before overriding limits

Because this predefined lookup now runs before canonical defaults and matches only on model_name, a GOOSE_PREDEFINED_MODELS entry for one provider can override context_limit for a different provider that exposes the same model name (for example, gpt-4o appears under multiple providers in the canonical mappings). In multi-provider setups, this can raise the effective limit above a provider’s real window, delaying compaction and causing avoidable upstream request failures once token usage passes that provider’s actual max; the predefined match should be scoped to provider_name before applying.

Useful? React with 👍 / 👎.

jeffa-block added a commit to jeffa-block/goose that referenced this pull request Mar 15, 2026
`ModelConfig::new_base()` read `GOOSE_CONTEXT_LIMIT` via
`std::env::var()`, which only checks environment variables.  Users
who set the value in config.yaml (e.g. `GOOSE_CONTEXT_LIMIT: 1000000`)
had it silently ignored for the lead model.

Switch to `Config::global().get_param()` which checks environment
variables first (preserving existing behaviour) then falls back to
config.yaml.  This matches how `GOOSE_MAX_TOKENS` is already read in
the same file and how `GOOSE_CONTEXT_LIMIT` is read for the worker
model in `init.rs`.

Partially addresses block#7839 (Option B). Complements block#7888 which fixes
predefined model priority (Option A).
Copy link
Copy Markdown
Collaborator

@DOsinga DOsinga left a comment

Choose a reason for hiding this comment

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

Pushed one small cleanup — removed a comment that restated what the code does. Everything else looks good. Thanks!

@DOsinga DOsinga added this pull request to the merge queue Mar 25, 2026
Merged via the queue into block:main with commit 09879ed Mar 25, 2026
21 checks passed
vincenzopalazzo pushed a commit to vincenzopalazzo/goose that referenced this pull request Mar 26, 2026
block#7888)

Signed-off-by: Extra Small <[email protected]>
Signed-off-by: Douwe Osinga <[email protected]>
Co-authored-by: Douwe Osinga <[email protected]>
Signed-off-by: Vincenzo Palazzo <[email protected]>
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.

Context limit resolution ignores GOOSE_PREDEFINED_MODELS and config.yaml — falls back to canonical registry 200k default

2 participants