Repository navigation
fix(bettergrep): clamp context lines to 50 instead of rejecting them - #20
Merged
Merged
Conversation
OpenCode 2 validates tool arguments against the schema, so grep calls with context, before_context or after_context above 20 failed with "Too big". OpenCode 1 skips that check and clamped them to 20 without telling the model. The cap is now 50 and the schema no longer sets a maximum, so both hosts accept larger values and clamp them to 50. The field descriptions state the cap. The formatter appended the output body with a spread call. With 50 context lines a result can reach about 520k lines, close to where Bun's argument limit throws RangeError, so it now appends in a loop. Release 1.2.1 for the three packages.
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.
OpenCode 2 validates tool arguments against the schema, so
grepcalls withcontext,before_contextorafter_contextabove 20 failed withToo big: expected number to be <=20and the model had to retry. OpenCode 1 does not enforce the schema maximum, so it clamped those values to 20 without telling the model.In the session history of one install, 189 of 14,818 v1 context values were above 20, ranging from 21 to 120, and all 10 such calls in v2 were rejected. A cap of 50 covers 99.8% of the v1 values.
Production changes
constants.ts:MAX_GREP_CONTEXTgoes from 20 to 50.schema.ts: the three context fields drop.max(). Both hosts now accept larger values, and the existing clamp innormalize.tsbrings them down to 50. Each field description states the cap.format.ts: the formatter appended the output body withlines.push(...formattedBody). With 50 context lines and 5,000 matches a result can reach about 520k lines. Bun 1.4.4 throwsRangeErrorat about 638k spread arguments, and Node already fails at about 153k, so the body is now appended in a loop.README.md: the context row states the clamp.Tests
src/v2/plugin.test.ts:context,before_contextandafter_contextset to 85 are accepted and run with 50. They fail onmainwith the schema error.typecheck,checkandbuildare clean, and 693 tests pass on Bun 1.4.4 (197 glob, 315 grep, 181 read).