Skip to content

fix(xai): resolve grok-composer-2.5-fast context for OAuth - #40046

Closed
XVVH wants to merge 1 commit into
NousResearch:mainfrom
XVVH:fix/grok-composer-context-262k
Closed

fix(xai): resolve grok-composer-2.5-fast context for OAuth#40046
XVVH wants to merge 1 commit into
NousResearch:mainfrom
XVVH:fix/grok-composer-context-262k

Conversation

@XVVH

@XVVH XVVH commented Jun 5, 2026

Copy link
Copy Markdown

Summary

grok-composer-2.5-fast (xAI OAuth / SuperGrok) is missing from GET /v1/models and models.dev. Hermes resolves its context via the generic grok → 131072 substring fallback, so the UI shows ~131.1k and the context compressor triggers at half of that (~65k tokens). Live /v1/responses probing shows the API enforces ~262144 tokens total (input + output). This PR adds grok-composer: 262144 before the catch-all, matching the pattern used for grok-build in 09afafb87.

Problem

  • Users on provider: xai-oauth with model: grok-composer-2.5-fast see 131072 in status / compressor init.
  • Aggressive context compression at the default 50% threshold (~65k) despite ~256K API headroom.
  • 200k is not validated for this slug (often confused with long_context_threshold on other Grok IDs in /v1/models).

Root cause

get_model_context_length() falls through models.dev (no entry) to longest-first substring match on DEFAULT_CONTEXT_LENGTHS. For grok-composer-2.5-fast, the only matching key today is grok (131072). Keys like grok-build / grok-4 do not substring-match this slug.

_CODEX_OAUTH_CONTEXT_FALLBACK is not used here (openai-codex only); xAI OAuth uses codex_responses transport but xai-oauth provider.

Solution

Add to DEFAULT_CONTEXT_LENGTHS (xAI Grok block):

"grok-composer": 262144,    # grok-composer-2.5-fast

Placed above "grok": 131072 so longest-first matching resolves Composer correctly.

Value 262144: from native probe — grow input on POST https://api.x.ai/v1/responses until HTTP 400 "The prompt is too long for this model's context window." Largest successful call had input_tokens + output_tokens ≈ 262143. Composer is absent from /v1/models (404 on per-model GET), so metadata cannot be sourced from the catalog endpoint.

Tests

  • Extend tests/agent/test_model_metadata.py::TestDefaultContextLengths::test_grok_substring_matching with ("grok-composer-2.5-fast", 262144).
  • Add test_grok_composer_context_length_is_262k in tests/run_agent/test_codex_xai_oauth_recovery.py (longest-match key is grok-composer, not grok).

Checklist

  • Substring specificity (does not change grok-4, grok-build, etc.)
  • No new entries in _CODEX_OAUTH_CONTEXT_FALLBACK
  • CI green (maintainer CI)

Related

  • 09afafb87grok-build → 256000 for OAuth / models.dev gap
  • #26664 / ce0e189d3grok-4.3 → 1M (substring specificity lesson)

User-facing

After merge, new sessions (or agent re-init) pick up 262144; compress-at-50% moves from ~65k → ~131k tokens. Existing compressed sessions are unchanged until /new or restart.

grok-composer-2.5-fast is absent from GET /v1/models and models.dev;
Hermes fell through to the generic grok substring (131072), causing
under-reported UI limits and aggressive context compression.

Live /v1/responses probing enforces ~262144 tokens total. Add
grok-composer: 262144 before the grok catch-all (longest-match).

Tests: extend test_grok_substring_matching; add
test_grok_composer_context_length_is_262k.
@XVVH
XVVH marked this pull request as ready for review June 5, 2026 19:08
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/xai xAI (Grok) labels Jun 5, 2026
@XVVH

XVVH commented Jun 7, 2026

Copy link
Copy Markdown
Author

Standby on merging this in - I've found a bug with tool web_search calling for grok-composer-2.5-fast. I'll submit another PR that supersedes this.

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

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have provider/xai xAI (Grok) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants