Skip to content

Tracked-file diffs have no size guard: staging a large file reintroduces the memory blowup fixed in #1118 #1120

Description

@backnotprop

Summary

PR #1118 bounds server memory for large untracked files: anything over 5 MiB is shown as a binary addition without loading its contents, and freshness fingerprints use size and mtime metadata instead of reading the file.

There is one path that reintroduces the original blowup. The git status panel offers a stage toggle on untracked files. Staging a large file moves it out of ls-files --others and into the tracked diff (git diff HEAD), which has no size guard. Reproduced during review: after git add on a 51 MB text artifact, the server again buffered a 55 MB patch at roughly 240 MB RSS.

This is really an instance of a pre-existing gap rather than a regression from #1118: any huge tracked text file modified in the working tree hits the same unguarded path today.

Possible fixes

  • Apply the same size guard to tracked working-tree diffs in runGitDiff (render oversized tracked changes as binary, same as the untracked path)
  • Or refuse or warn on /api/git-add when the target file exceeds the threshold
  • Either way, keep the two runtimes in sync (Bun packages/server/ and Pi apps/pi-extension/server/); the shared logic lives in packages/shared/review-core.ts

Repro

  1. head -c 51000000 /dev/urandom | base64 > artifact.js in a repo under review (text content so git emits a full text diff)
  2. Open code review, see the file listed as a binary addition (correct, bounded)
  3. Click stage on it, watch server RSS climb as the tracked diff buffers the full patch

Credit to @kcosr, whose #1118 fixed the untracked side and whose review surfaced this remaining edge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions