fix(metadata): grok-4.20 context window is 1M, not 2M - #109898
Open
MaxFreedomPollard wants to merge 1 commit into
Open
MaxFreedomPollard wants to merge 1 commit into
MaxFreedomPollard wants to merge 1 commit into
Conversation
docs.x.ai/docs/models/grok-4.20 lists "Context window 1,000,000", and the models index carries grok-4.20-0309-reasoning, grok-4.20-0309-non-reasoning and grok-4.20-multi-agent-0309 at 1M — all of which resolve through this catalog key. The 2M entry over-advertised the window by 2x, so compression only kicked in after the endpoint had already started rejecting the request. grok-4-fast keeps its own 2M row; the shared _PRE_CATALOG_STALE_KEYS comment now reads "2M / 1M" and the key still qualifies (1M is strictly above the "grok-4" catch-all at 256,000). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
DEFAULT_CONTEXT_LENGTHSadvertises a 2M window for Grok 4.20 (agent/model_metadata.py:374):xAI documents half that. From https://docs.x.ai/docs/models/grok-4.20, the "At a glance" panel:
The models index at https://docs.x.ai/docs/models agrees across the whole family —
grok-4.20-0309-reasoning,grok-4.20-0309-non-reasoningandgrok-4.20-multi-agent-0309are each listed at 1M. All of those resolve through this one catalog key: the comment two lines above notes that "grok-4-fast / grok-4.20 also match their -(non-)reasoning and -multi-agent variants".The xAI block exists precisely because
/v1/modelson api.x.ai returns nocontext_length, so this table is the window for these ids — there is no live value to correct it. Over-advertising by 2x is the dangerous direction: compression never triggers, and the first signal the user gets is the endpoint rejecting the request outright.grok-4-fastis documented at 2M and keeps its own value; only thegrok-4.20row moves.Related Issue
No issue. The
_PRE_CATALOG_STALE_KEYSguard this touches came from #85434 (merged, "fix(xai): drop stale 256K grok-4.6 context cache + generalize pre-catalog guard").grok-4.20still belongs in that frozenset after the change: the docstring requires a key whose catalog value is strictly above every shorter matching key and the 256K fallback, and 1,000,000 clears thegrok-4catch-all (256,000), thegrokcatch-all (131,072) and the fallback. Only the shared inline comment needed updating, sincegrok-4-faston the same line stays at 2M.Open question, deliberately not changed here:
"grok-build-latest": 500000(line 373) carries the comment "grok-build-latest aliases grok-4.5". The docs' alias rule is<modelname>-latest is aliased to the latest version, i.e. the latest version of that model name — and the onlygrok-buildmodel in the index isgrok-build-0.1at 256k, which is also what the neighbouring"grok-build": 256000entry says. That reads likegrok-build-latestshould be 256K, not 500K (a 2x over-advertisement in the same direction as the bug fixed here), but the aliasing may be deliberate for the Grok Build CLI route, so I have left it alone rather than guess. Happy to follow up in a separate PR if a maintainer confirms.Type of Change
Changes Made
agent/model_metadata.py:"grok-4.20"→1000000inDEFAULT_CONTEXT_LENGTHS; the_PRE_CATALOG_STALE_KEYSinline comment (line 1361) now reads# 2M / 1M— matching the"grok-4.3", "grok-4.6", # 1M / 500Kstyle on the line above — since the two keys on that line no longer share a window.tests/agent/test_grok_420_context_window.py(new):get_model_context_length(..., provider="xai")returns 1M forgrok-4.20and for the three documented variants; the catalog entry is 1M;grok-4-faststill resolves to its own 2M.How to Test
On
main, apply only the test file:scripts/run_tests.sh tests/agent/test_grok_420_context_window.py→ 2 failed, 1 passed:On this branch: 3 passed.
Wider sweep — all 10 test files referencing
grok-4.20,grok-4-fastor_PRE_CATALOG_STALE_KEYS(includestest_model_metadata.py,test_xai_retirement.py,test_migrate_xai.py,test_codex_transport.py): 581 passed, 0 failed.Manually:
/contextongrok-4.20-0309-reasoningnow reports 1,000,000; a session that previously ran past ~1M tokens without compressing now compresses at the documented threshold instead of failing at the endpoint.Checklist
Code
fix(scope):,feat(scope):, etc.)grok-4.20and_PRE_CATALOG_STALE_KEYS. No open PR changes this window; the open_PRE_CATALOG_STALE_KEYSPRs (fix(metadata): Sakana Fugu context window is 1M, not the 256K fallback #109720 Sakana Fugu, fix(metadata): Nemotron context windows from the live catalogs (262K, 1M only for the :free promos) #109719 Nemotron, fix(agent): stop GLM-5.3 from using a 202K context window #87866 GLM-5.3, fix(metadata): resolve deepseek-v4.1-flash to its real 1M window #107250 deepseek-v4.1-flash) each carry a different key. No recent commit onagent/model_metadata.pytouches the grok rows.scripts/run_tests.sh: all passedruff checkon the touched files: All checks passed!Documentation & Housekeeping
cli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/A