Skip to content

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

@LFA-1

Description

@LFA-1

Describe the bug

When using a model configured in GOOSE_PREDEFINED_MODELS with a custom context_limit (e.g., 1M for Claude Opus 4.6 with the context-1m beta header), the context limit resolves to 200k instead of 1M. This causes auto-compaction to fire at ~160k tokens (80% of 200k), destroying conversation history mid-session.

Two issues combine:

  1. GOOSE_CONTEXT_LIMIT in config.yaml is silently ignored. The code reads it via std::env::var("GOOSE_CONTEXT_LIMIT") in ModelConfig::new_base() (crates/goose/src/model.rs), which checks the process environment — not config.yaml. The desktop app (Electron) doesn't source shell profiles, so the value never reaches the code.

  2. Canonical registry overrides predefined models. In ModelConfig::with_canonical_limits(), the canonical registry lookup resolves goose-claude-4-6-opusanthropic/claude-opus-4.6context: 200000 and sets self.context_limit. The predefined models fallback (context_limit: 1000000) is only checked if self.context_limit.is_none() — but it's already set to 200k by the canonical registry.

Resolution chain:

Priority Source Value Used?
1 GOOSE_CONTEXT_LIMIT env var Not set (config.yaml value ignored)
2 Canonical model registry 200,000 ✅ Wins
3 GOOSE_PREDEFINED_MODELS 1,000,000 ❌ Never reached

To Reproduce

  1. Set GOOSE_CONTEXT_LIMIT: 1000000 in ~/.config/goose/config.yaml
  2. Select goose-claude-4-6-opus as the model (via UI dropdown or config)
  3. Confirm GOOSE_PREDEFINED_MODELS env var includes the model with context_limit: 1000000 and request_params: { anthropic_beta: ["context-1m-2025-08-07"] }
  4. Start a session and check the info-msg — context limit reports as 200k, not 1M
  5. Auto-compaction fires at ~160k tokens

Expected behavior

Context limit should be 1,000,000 tokens. Either:

  • GOOSE_CONTEXT_LIMIT from config.yaml should be respected (priority 1), OR
  • context_limit from the matching GOOSE_PREDEFINED_MODELS entry should take priority over the canonical registry default

Screenshots

N/A — reproducible via info-msg token reporting.


Please provide the following information

  • OS & Arch: macOS (Apple Silicon)
  • Interface: UI (desktop app)
  • Version: 1.27.2-block
  • Extensions enabled: Computer Controller, Memory, Extension Manager
  • Provider & Model: Databricks – goose-claude-4-6-opus

Additional context

Suggested fix (Option A — minimal): In with_canonical_limits(), check predefined models BEFORE the canonical registry. Predefined models are explicitly configured by the deployment team and should take priority over generic canonical defaults:

// Check predefined models first (explicit config > generic defaults)
if self.context_limit.is_none() {
    if let Some(pm) = find_predefined_model(&self.model_name) {
        self.context_limit = pm.context_limit;
    }
}

// Fall back to canonical registry
if self.context_limit.is_none() {
    if let Some(canonical) = ... {
        self.context_limit = Some(canonical.limit.context);
    }
}

Suggested fix (Option B — also needed): Make GOOSE_CONTEXT_LIMIT in config.yaml work by reading it via Config::global().get_param() (like GOOSE_MAX_TOKENS already does) instead of std::env::var().

Workaround: Set GOOSE_CONTEXT_LIMIT as a real environment variable visible to GUI apps via launchctl setenv GOOSE_CONTEXT_LIMIT 1000000, then restart the app.

Other reports: This was also reported in #goose-help on Slack (March 10, 2026) without resolution. Related: GitHub issue #4357 (closed October 2025) addressed a different surface of the same underlying problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions