fix(core): skip oversized ripgrep match lines instead of aborting grep#35699
Open
C0d3N1nja97342 wants to merge 1 commit into
Open
fix(core): skip oversized ripgrep match lines instead of aborting grep#35699C0d3N1nja97342 wants to merge 1 commit into
C0d3N1nja97342 wants to merge 1 commit into
Conversation
A match whose JSON record exceeds the 64 KiB parse guard (a line longer than ~65536 bytes — minified bundles, base64, data rows) used to fail the entire grep with "Ripgrep JSON record exceeded N bytes", discarding every other match. rg itself exits 0 and emits the record fine; the guard was opencode's own. Skip the oversized record (return undefined, filtered out of the stream) instead of failing, so the remaining matches are still returned. The display layer already truncates lines.text to 2000 chars, so the full oversized content was never surfaced anyway. Truly invalid JSON still fails. Closes anomalyco#35523
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 #35523
Type of change
What does this PR do?
grepaborts the entire search withRipgrep JSON record exceeded 65536 byteswhenever a single match sits on a line longer than ~64 KiB (minified bundles, base64, large data rows) — every other match in the same call is thrown away.The guard is opencode's own, in
packages/core/src/ripgrep.ts(theparsecallback insiderun,grepbranch):ripgrep itself exits 0 and emits the record fine — the failure is purely opencode rejecting its own output. I confirmed with real rg 15.1.0 that
--max-columnsdoes not help here: in--jsonmode it leaveslines.textat the full length, and--max-columns-longdrops the match entirely. So the fix belongs in the parse guard, not the rg args.Change: when a record exceeds
MAX_RECORD_BYTES, returnundefined(skipped by the existingStream.filterjust downstream) instead of failing. The remaining matches are still returned. Truly invalid JSON at normal length still fails with the same error as before.Why this is the right trade: the display path already truncates
lines.textto 2000 chars (inMatch.makefurther down ingrep), so the full content of an oversized line was never surfaced to the model/user anyway. Skipping one unusable line is strictly better than discarding the whole result set.(Note: a previous version of this PR targeted
v2; reopened againstdev, which is where 1.17.x ships and where GitHub links the issue correctly.)How did you verify your code works?
Ran in an
oven/bun:1.3.14container with git installed (the existing "keeps ignored files out of catch-all find results" test shells out togit init), against thedevbranch tip:skips oversized match lines instead of failing the whole grep: writesbig.txt(a 70000-byte line containing the pattern) andsmall.txt(a normal line), greps the pattern, assertssmall.txtis returned,big.txtis skipped, and the call does not throw.Effect.failand passes with the fix.ripgrep.test.tspass.bun run typecheck(tsgo --noEmit) inpackages/coreis clean.Checklist