Skip to content

Commit d56cbc8

Browse files
Zexiclaude
authored andcommitted
fix: cap diff size to prevent SQLite/V8 crash on large files
apply_patch deleting a binary file (e.g. a 142 MB DMG) called createTwoFilesPatch on the full file content, producing a 380 MB diff string that was stored verbatim in part.data. When any query loaded all rows for that session Node's sqlite StatementSync::All tried to convert the 380 MB buffer to a V8 string, hitting an internal V8 assertion and crashing the sidecar. - apply_patch.ts: skip diff generation for deleted files larger than 512 KB (binary files have no useful unified diff anyway). - edit.ts trimDiff: return "" for any diff already over 512 KB, guarding all callers against unexpectedly large inputs. Also manually truncated the offending DB row (prt_e1826dea2001zbyfymhOP3BOom, 380 MB → 201 bytes). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 16d893c commit d56cbc8

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

packages/opencode/src/tool/apply_patch.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,13 @@ export const ApplyPatchTool = Tool.define(
165165
),
166166
)
167167
const contentToDelete = source.text
168-
const deleteDiff = trimDiff(createTwoFilesPatch(filePath, filePath, contentToDelete, ""))
168+
// Skip diff for large/binary files to prevent storing hundreds of MB in SQLite.
169+
// V8 string limit is ~512MB; a 142MB binary file produces a 380MB+ diff.
170+
const DIFF_SIZE_LIMIT = 512 * 1024 // 512 KB
171+
const deleteDiff =
172+
contentToDelete.length > DIFF_SIZE_LIMIT
173+
? ""
174+
: trimDiff(createTwoFilesPatch(filePath, filePath, contentToDelete, ""))
169175

170176
const deletions = contentToDelete.split("\n").length
171177

packages/opencode/src/tool/edit.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,10 @@ export const ContextAwareReplacer: Replacer = function* (content, find) {
635635
}
636636
}
637637

638+
const DIFF_MAX_BYTES = 512 * 1024 // 512 KB — keeps SQLite rows manageable and well under V8's string limit
639+
638640
export function trimDiff(diff: string): string {
641+
if (diff.length > DIFF_MAX_BYTES) return ""
639642
const lines = diff.split("\n")
640643
const contentLines = lines.filter(
641644
(line) =>

0 commit comments

Comments
 (0)