openclaw - 💡(How to fix) Fix [Bug]: Google provider models fall to 200k context fallback due to empty discovery cache [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#60016Fetched 2026-04-08 02:37:23
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1

All Gemini models resolve to a 200k context window instead of their actual 1,048,576 token limit because the Google extension does not register a provider catalog, leaving models.json empty for Google and causing resolveContextTokensForModel() to fall through to DEFAULT_CONTEXT_TOKENS (200,000).

Root Cause

All Gemini models resolve to a 200k context window instead of their actual 1,048,576 token limit because the Google extension does not register a provider catalog, leaving models.json empty for Google and causing resolveContextTokensForModel() to fall through to DEFAULT_CONTEXT_TOKENS (200,000).

Fix Action

Fix / Workaround

  • Affected: All users of Google Gemini models via API key or Gemini CLI OAuth
  • Severity: Medium — sessions work but waste ~80% of available context
  • Frequency: Always (100% of Gemini sessions without explicit config workaround)
  • Consequence: Premature context compaction at 160-180k instead of ~900k; reduced session continuity and quality for long conversations

Workaround: Add explicit contextWindow to the model config in openclaw.json:

{
  "models": {
    "providers": {
      "google": {
        "models": [
          { "id": "gemini-3.1-pro-preview", "contextWindow": 1048576 }
        ]
      }
    }
  }
}

This works because resolveConfiguredProviderContextWindow() (step 3 in the resolution chain) fires before the discovery cache lookup. However, it requires manually listing every Google model used and does not scale.

Code Example

# Discovery cache shows no Google provider entry:
$ cat ~/.openclaw/agents/<agentId>/agent/models.json | jq '.providers | keys'
["ollama", "openai-codex"]
# Google is absent despite being configured and functional.

# Google API confirms 1M context support:
# gemini-3.1-pro-preview inputTokenLimit: 1048576

# Resolution chain (src/agents/context.ts):
# 1. contextTokensOverride -> not set
# 2. context1m param -> Anthropic-only, skipped
# 3. resolveConfiguredProviderContextWindow -> no explicit config entry
# 4. lookupContextTokens (discovery cache) -> no Google entry in models.json
# 5. fallbackContextTokens -> DEFAULT_CONTEXT_TOKENS = 200_000  <-- lands here

# Root cause: extensions/google/index.ts registers resolveDynamicModel
# and other runtime hooks but no catalog. Compare with extensions that
# work correctly (e.g., extensions/minimax/index.ts which registers catalog).

---

{
  "models": {
    "providers": {
      "google": {
        "models": [
          { "id": "gemini-3.1-pro-preview", "contextWindow": 1048576 }
        ]
      }
    }
  }
}
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

All Gemini models resolve to a 200k context window instead of their actual 1,048,576 token limit because the Google extension does not register a provider catalog, leaving models.json empty for Google and causing resolveContextTokensForModel() to fall through to DEFAULT_CONTEXT_TOKENS (200,000).

Steps to reproduce

  1. Configure a Google provider with GEMINI_API_KEY (no explicit contextWindow in config).
  2. Start an agent session using google/gemini-3.1-pro-preview.
  3. Run /status or check session context token limit.
  4. Observe context limit reported as ~200k instead of ~1M.
  5. Confirm by checking ~/.openclaw/agents/<agentId>/agent/models.json — no google provider entry exists.

Expected behavior

Gemini models should report a context window of 1,048,576 tokens, matching the Google API's inputTokenLimit for Gemini 3.x models. Other provider extensions (anthropic-vertex, openrouter, mistral, minimax) correctly populate the discovery cache via their provider-catalog.ts files.

Actual behavior

All Gemini models report a ~200k context window. Sessions compact at 160-180k instead of the available ~900k. The discovery cache (models.json) contains no Google provider entries. The resolution chain in resolveContextTokensForModel() (src/agents/context.ts) exhausts all lookup paths and falls through to fallbackContextTokens, which defaults to DEFAULT_CONTEXT_TOKENS = 200_000 (src/agents/defaults.ts).

OpenClaw version

2026.4.2

Operating system

macOS 15.4

Install method

npm global / pnpm dev

Model

google/gemini-3.1-pro-preview

Provider / routing chain

openclaw -> google (direct API key)

Additional provider/model setup details

Google provider configured via GEMINI_API_KEY environment variable. No explicit contextWindow override in openclaw.json models.providers.google. Agent uses google/gemini-3.1-pro-preview as primary model.

Logs, screenshots, and evidence

# Discovery cache shows no Google provider entry:
$ cat ~/.openclaw/agents/<agentId>/agent/models.json | jq '.providers | keys'
["ollama", "openai-codex"]
# Google is absent despite being configured and functional.

# Google API confirms 1M context support:
# gemini-3.1-pro-preview inputTokenLimit: 1048576

# Resolution chain (src/agents/context.ts):
# 1. contextTokensOverride -> not set
# 2. context1m param -> Anthropic-only, skipped
# 3. resolveConfiguredProviderContextWindow -> no explicit config entry
# 4. lookupContextTokens (discovery cache) -> no Google entry in models.json
# 5. fallbackContextTokens -> DEFAULT_CONTEXT_TOKENS = 200_000  <-- lands here

# Root cause: extensions/google/index.ts registers resolveDynamicModel
# and other runtime hooks but no catalog. Compare with extensions that
# work correctly (e.g., extensions/minimax/index.ts which registers catalog).

Impact and severity

  • Affected: All users of Google Gemini models via API key or Gemini CLI OAuth
  • Severity: Medium — sessions work but waste ~80% of available context
  • Frequency: Always (100% of Gemini sessions without explicit config workaround)
  • Consequence: Premature context compaction at 160-180k instead of ~900k; reduced session continuity and quality for long conversations

Additional information

Workaround: Add explicit contextWindow to the model config in openclaw.json:

{
  "models": {
    "providers": {
      "google": {
        "models": [
          { "id": "gemini-3.1-pro-preview", "contextWindow": 1048576 }
        ]
      }
    }
  }
}

This works because resolveConfiguredProviderContextWindow() (step 3 in the resolution chain) fires before the discovery cache lookup. However, it requires manually listing every Google model used and does not scale.

Proposed fix direction: Add extensions/google/provider-catalog.ts following the established pattern used by all other provider extensions (minimax, openrouter, anthropic-vertex, mistral, etc.). This would populate the discovery cache at startup with correct contextWindow values for known Gemini models. The existing resolveDynamicModel forward-compat resolver would continue handling unknown future model IDs at runtime.

extent analysis

TL;DR

The most likely fix is to add a provider-catalog.ts file to the Google extension to populate the discovery cache with correct context window values for Gemini models.

Guidance

  • Verify that the provider-catalog.ts file is missing from the Google extension by checking the extensions/google directory.
  • Create a provider-catalog.ts file in the extensions/google directory to populate the discovery cache with correct context window values for known Gemini models.
  • As a temporary workaround, add an explicit contextWindow configuration to the model config in openclaw.json for each Google model used.
  • Test the fix by running a new agent session and checking the context token limit using the /status command or by verifying the contents of ~/.openclaw/agents/<agentId>/agent/models.json.

Example

// extensions/google/provider-catalog.ts
import { ProviderCatalog } from '../provider-catalog';

const googleCatalog: ProviderCatalog = {
  providers: {
    google: {
      models: [
        { id: 'gemini-3.1-pro-preview', contextWindow: 1048576 },
        // Add other known Gemini models here
      ],
    },
  },
};

export default googleCatalog;

Notes

The proposed fix requires adding a new file to the Google extension, which may require updates to the build or deployment process. Additionally, the provider-catalog.ts file will need to be updated whenever new Gemini models are released.

Recommendation

Apply the workaround by adding an explicit contextWindow configuration to the model config in openclaw.json for each Google model used, as this provides a temporary solution until the provider-catalog.ts file can be added to the Google extension.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Gemini models should report a context window of 1,048,576 tokens, matching the Google API's inputTokenLimit for Gemini 3.x models. Other provider extensions (anthropic-vertex, openrouter, mistral, minimax) correctly populate the discovery cache via their provider-catalog.ts files.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING