Handle buffer overflows gracefully and truncate diffs fairly (#5083)

- Gracefully fall back to file-name summaries when staged diffs exceed
  node/ssh execution maxBuffer limits, preventing generation failures.
- Split oversized diffs by file and allocate budget via water-filling,
  ensuring single huge files do not starve smaller human changes.
- Clip truncated diff sections on line boundaries to avoid half-lines.
This commit is contained in:
Jinjing
2026-06-09 23:56:36 -07:00
committed by GitHub
parent c12164c8cc
commit 256e0ef81a
9 changed files with 265 additions and 24 deletions
+5 -1
View File
@@ -35,7 +35,11 @@ export function buildCommitMessagePrompt(
context: CommitMessageDraftContext,
customPrompt: string
): string {
const patch = truncateDiffForPrompt(context.stagedPatch)
// Why: the staged patch is dropped when it's too large to read, so fall back to
// the file summary and tell the agent why the diff is missing.
const patch = context.stagedPatch.trim()
? truncateDiffForPrompt(context.stagedPatch)
: '(diff omitted — too large to read; infer the change from the staged file list above)'
const base = [
'You are generating a single git commit message.',
'Return only the commit message text. Do not include a preamble, quotes, or code fences.',