diff --git a/packages/opencode/src/kilocode/review/review.ts b/packages/opencode/src/kilocode/review/review.ts index 66926e49816..5d6c8e90eeb 100644 --- a/packages/opencode/src/kilocode/review/review.ts +++ b/packages/opencode/src/kilocode/review/review.ts @@ -376,19 +376,23 @@ export namespace Review { const untracked = await $`git ls-files --others --exclude-standard -z`.cwd(Instance.directory).quiet().nothrow() if (untracked.exitCode === 0) { const paths = untracked.stdout.toString().split("\0").filter(Boolean) - // Run diffs in parallel — sequential spawns are slow with many untracked files - const diffs = await Promise.all( - paths.map((p) => - // --no-index exits 1 when files differ, which is expected - $`git -c core.quotepath=false diff --no-index -- /dev/null ${p}` - .cwd(Instance.directory) - .quiet() - .nothrow() - .then((fd) => fd.stdout.toString()), - ), - ) - for (const out of diffs) { - if (out) raw += out + // Process in batches to avoid spawning hundreds of git processes + const batch = 20 + for (let i = 0; i < paths.length; i += batch) { + const chunk = paths.slice(i, i + batch) + const diffs = await Promise.all( + chunk.map((p) => + // --no-index exits 1 when files differ, which is expected + $`git -c core.quotepath=false diff --no-index -- /dev/null ${p}` + .cwd(Instance.directory) + .quiet() + .nothrow() + .then((fd) => fd.stdout.toString()), + ), + ) + for (const out of diffs) { + if (out) raw += out + } } }