You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
core: grep fails entirely when a matching line is not valid UTF-8 #51912
Grep fails with Invalid ripgrep match output and returns no matches at all when any matching line isn't valid UTF-8, such as a Latin-1 or GBK source file. Matches in other files are lost too.
rg --json reports data that isn't valid UTF-8 as { "bytes": "<base64>" } instead of { "text": "..." }. RawMatch in packages/core/src/ripgrep.ts only accepts text for path, lines and submatches[].match. The failed decode fails the whole result stream, not just that row.
This is the same problem as #23629, which was auto-closed as stale. That report was against the old packages/opencode grep; the current packages/core implementation has the same gap.
Thanks for the clear report. I was able to reproduce this on 2.0.18, and it still happens on the latest dev (86ce19d).
Steps: in a project containing utf8.txt (needle) and latin1.txt (needle caf + byte 0xE9), the model calls grep with pattern needle. The tool returns Invalid ripgrep match output and no matches at all, so the valid utf8.txt match is lost too. In the TUI the step shows as a failed search. The recording below (from 2.0.18) shows it, and the script below reproduces it with a simulated model.
This matches your analysis: RawMatch in packages/core/src/ripgrep.ts only accepts { text }, while ripgrep sends { bytes } for non-UTF-8 data, and the decode failure aborts the whole stream. Related: #23629 (the same symptom in the old v1 grep) and your PR #51913.
recording.mp4
Reproduction script (drive.ts)
// Reproduces #51912: grep fails when a matching line is not valid UTF-8.import{Effect,Stream}from"effect"import{Llm,OpenCodeDriver}from"opencode-drive"constlatin1=newUint8Array([...newTextEncoder().encode("needle caf"),0xe9,0x0a])exportdefaultOpenCodeDriver.use({
...(process.env.OC_DEV ? {opencode: {dev: process.env.OC_DEV}} : {}),project: {git: true,files: {"utf8.txt": "needle\n","latin1.txt": latin1,},},tui: {recording: true},},({ ui, llm })=>Effect.gen(function*(){yield*llm.serve((request,index)=>{constbody=JSON.stringify(request)// First turn (no grep result yet): ask for a grep call.if(!body.includes("call_grep"))returnStream.make(Llm.toolCall({index: 0,id: "call_grep",name: "grep",input: {pattern: "needle"}}),Llm.finish("tool-calls"),)// Print what the grep tool returned to the model.consthit=body.match(/"[^"]*(Invalidripgrep|latin1\.txt|utf8\.txt)[^"]*"/g)console.log("GREP TOOL RESULT SEEN BY MODEL:",hit)returnStream.make(Llm.text("Grep done."))})yield*ui.submit("Search for needle")yield*ui.waitFor("Grep done.",{timeout: 30000})yield*Effect.sleep("1 second")yield*ui.screenshot("grep-result")}),)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
Activity
github-actions commentedon Sep 28, 2026
This issue might be a duplicate of an existing issue. Please check:
bytesinstead oftext, causing the output parser to fail.opencodejr commentedon Oct 28, 2026
Thanks for the clear report. I was able to reproduce this on 2.0.18, and it still happens on the latest
dev(86ce19d).Steps: in a project containing
utf8.txt(needle) andlatin1.txt(needle caf+ byte0xE9), the model callsgrepwith patternneedle. The tool returnsInvalid ripgrep match outputand no matches at all, so the validutf8.txtmatch is lost too. In the TUI the step shows as a failed search. The recording below (from 2.0.18) shows it, and the script below reproduces it with a simulated model.This matches your analysis:
RawMatchinpackages/core/src/ripgrep.tsonly accepts{ text }, while ripgrep sends{ bytes }for non-UTF-8 data, and the decode failure aborts the whole stream. Related: #23629 (the same symptom in the old v1 grep) and your PR #51913.recording.mp4
Reproduction script (drive.ts)
Run it with opencode-drive:
opencode-drive run ./drive.ts. It drivesopencodefrom yourPATH; setOC_DEVto the path of an OpenCode checkout to run that from source instead.