Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/opencode/src/tool/apply_patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ export const ApplyPatchTool = Tool.define(
),
)
const contentToDelete = source.text
const deleteDiff = trimDiff(createTwoFilesPatch(filePath, filePath, contentToDelete, ""))
// Skip diff for large/binary files to prevent storing hundreds of MB in SQLite.
// V8 string limit is ~512MB; a 142MB binary file produces a 380MB+ diff.
const DIFF_SIZE_LIMIT = 512 * 1024 // 512 KB
const deleteDiff =
contentToDelete.length > DIFF_SIZE_LIMIT
? ""
: trimDiff(createTwoFilesPatch(filePath, filePath, contentToDelete, ""))

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

Expand Down
3 changes: 3 additions & 0 deletions packages/opencode/src/tool/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,10 @@ export const ContextAwareReplacer: Replacer = function* (content, find) {
}
}

const DIFF_MAX_BYTES = 512 * 1024 // 512 KB — keeps SQLite rows manageable and well under V8's string limit

export function trimDiff(diff: string): string {
if (diff.length > DIFF_MAX_BYTES) return ""
const lines = diff.split("\n")
const contentLines = lines.filter(
(line) =>
Expand Down
Loading