fix(xai): scope native web_search to swap-only + reconcile composer ctx to 200k

Salvage corrections on top of @XVVH's #44341:
- Make native web_search injection a 1:1 swap for an already-present client
  web_search function, NOT an additive grant. The original unconditionally
  appended {"type":"web_search"} on every is_xai_responses turn with any
  tools, force-enabling Grok server-side search even when the user never
  enabled the web toolset (bypassing Hermes web-provider config + tool-trace
  plumbing). Now gated on a client web_search actually being present.
- Reconcile grok-composer context to 200000 (merged in #47908) rather than
  262144; 200k is xAI's published usable context window for Composer 2.5,
  262144 is the /v1/responses input+output budget.
- Update tests to match scoped behavior + add a no-web-toolset guard test.
- AUTHOR_MAP entry for #44341 salvage.

Incomplete-guard (server-side *_call items at in_progress no longer flip
has_incomplete_items) and preflight built-in-tool allowlist kept as-is.
This commit is contained in:
teknium1
2026-06-17 17:33:32 -07:00
committed by Teknium
parent 6f89e17a33
commit c5eb64b9f7
6 changed files with 89 additions and 38 deletions
@@ -949,15 +949,18 @@ def test_grok_4_still_resolves_to_256k():
assert DEFAULT_CONTEXT_LENGTHS[matched_key] == 256_000
def test_grok_composer_context_length_is_262k():
def test_grok_composer_context_length_is_200k():
"""grok-composer-2.5-fast is OAuth-only and missing from /v1/models.
Without a specific entry it fell through to the generic ``grok`` 131k
catch-all, under-reporting ~262k enforced on /v1/responses.
catch-all. xAI publishes a 200k usable context window for Composer 2.5
on Grok Build (SuperGrok / Premium+); /v1/responses additionally caps
the input+output budget at ~262144, but the usable context (what we
track) is 200k.
"""
from agent.model_metadata import DEFAULT_CONTEXT_LENGTHS
assert DEFAULT_CONTEXT_LENGTHS["grok-composer"] == 262_144
assert DEFAULT_CONTEXT_LENGTHS["grok-composer"] == 200_000
slug = "grok-composer-2.5-fast"
matched_key = max(
(k for k in DEFAULT_CONTEXT_LENGTHS if k in slug.lower()),
@@ -966,7 +969,7 @@ def test_grok_composer_context_length_is_262k():
assert matched_key == "grok-composer", (
f"Expected longest-first match on grok-composer for {slug}, got {matched_key}"
)
assert DEFAULT_CONTEXT_LENGTHS[matched_key] == 262_144
assert DEFAULT_CONTEXT_LENGTHS[matched_key] == 200_000
# ---------------------------------------------------------------------------