fix: prevent xAI/Grok tool payloads from tripping grammar complexity#17404
Open
brendandebeasi wants to merge 6 commits intoanomalyco:devfrom
Open
fix: prevent xAI/Grok tool payloads from tripping grammar complexity#17404brendandebeasi wants to merge 6 commits intoanomalyco:devfrom
brendandebeasi wants to merge 6 commits intoanomalyco:devfrom
Conversation
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This was referenced Mar 14, 2026
added 6 commits
March 20, 2026 09:14
Estimate Grok tool budget using full wire payload size and prune the actual tool map sent to streamText so oversized grammars no longer slip through activeTools-only filtering.
Use a safe typed lookup for optional tool limits and adjust the cherry-picked xAI tests to the current Provider.getModel API in dev without changing runtime behavior.
Match existing session test patterns using providerID/modelID constants so CI typecheck resolves branded provider IDs consistently.
Use Provider.getModel parameter typing for xAI provider IDs in new tests to satisfy branded provider type checks in upstream CI.
b1890de to
6df8a0f
Compare
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.
Issue for this PR
Closes #17405
Type of change
What does this PR do?
Grok requests were still able to include oversized tool payloads even when
activeToolswas reduced, because the fulltoolsmap could still be sent tostreamText. On xAI models this can triggergrammar is too complexfailures.This PR hardens the xAI path by:
40)toolsobject sent tostreamTextfor xAI so dropped tools cannot leak throughWhy this works: xAI grammar complexity is sensitive to total tool schema payload; enforcing limits on the exact outgoing tool payload prevents over-budget requests from reaching Grok.
Related context:
vercel/ai#8024)How did you verify your code works?
bun test test/session/llm.test.ts(packages/opencode) -> pass (12/12)bun typecheck(packages/opencode) -> pass/chat/completionsendpoint:opencode run ... --model xai/grok-4toolspayload stays within count <= 40 and bytes <= 20000CLI oneshot xAI smoke test passed,requests=1)Screenshots / recordings
N/A (non-UI change)
Checklist