Skip to content

fix(git): enforce working diff file limits during reads - #34767

Closed
OrcaWin wants to merge 1 commit into
mainfrom
OrcaWin/awesome-git
Closed

OrcaWin wants to merge 1 commit into
mainfrom
OrcaWin/awesome-git

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​64 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​64
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1

ELI5

Opening a changing file in a Git diff can read far more data than the existing 10 MiB limit allows. Enforce the limit while reading so a concurrent writer cannot make Orca load an arbitrarily large file.

What Changed

readWorkingTreeFile now uses the existing readNodeFileWithinLimit reader with regularFileOnly: true. The reader checks the opened file, limits buffer capacity, and probes for growth past the limit. Its handle closes on success and failure.

An oversized file keeps the existing binary/omitted-body result. Directories remain absent, ENOENT remains a proven deletion, and other failures remain uncacheable reads. No new reader, limit, process, polling, or cache is introduced.

Why

The previous implementation checked stat(path).size and then called unbounded readFile(path). A build, log writer, or file replacement between those operations could bypass the size guard. The same race exists when a file grows after opening.

The regression test uses a real temporary file and schedules its write immediately after the real path stat completes, without timers. It then calls the production blob reader:

Workload Before After
8-byte file grows to 10,485,761 bytes after stat 10,485,761 text characters returned 0 body characters; existing oversized-file result
File grows to 65,536 bytes after stat Complete contents returned Complete contents returned

The oversized case fails on the original implementation, which reports a normal text blob. This proves the guard was bypassed; it is not an application-wide memory or latency benchmark. The shared reader additionally bounds growth during the read and avoids blocking if a regular-file path is replaced by a FIFO on supported hosts.

Linked Issue

Internal Git performance/resource audit; no existing issue.

Visual Proof

N/A — the existing over-limit file representation is preserved. The change enforces its resource bound during concurrent writes; no renderer component or interaction changes.

Testing

  • The new deterministic concurrent-write regression fails before the fix.
  • 47 focused tests pass across the new regression, existing diff tests, settled-cache tests, and real-Git absence/corruption tests.
  • Full combined gate completed 27/28 checks; unit-failure recovery and remaining coverage gaps are documented below.
ORCA_BACKGROUND_LAUNCH=1 pnpm test src/main/git/source-control/working-tree-blob-read-limit.test.ts src/main/git/status-diff.test.ts src/main/git/status-diff-settled-cache.test.ts src/main/git/source-control/blob-absence-real-git.test.ts --maxWorkers=2

Executed locally on Linux with Node 24.22.0 and the project's test runner. Windows/macOS/WSL/SSH were not executed. The reused reader handles platform-specific file-open flags, and this change leaves existing host-path routing intact. Local and remote runtime callers share the same provider implementation; no RPC, preload, mobile, Git-provider, or mixed-version protocol changes are needed. Folder workspaces do not gain any new Git assumptions.

Combined validation: the six-fix interaction stack passed 110 tests across 14 files; final cache controls passed 32 tests across six files. The canonical ORCA_BACKGROUND_LAUNCH=1 pnpm check:changed --maxWorkers=2 at 0e0cefa57be finished 27/28 checks, with unit tests failing; all non-unit checks passed. The results cache recorded 72 failures among 2,977 current file/project entries. No complete broad green pass is claimed.

Recovery: 61 originally failed files passed 546 tests on rerun. Three original test failures received reviewed test-only budget-fixture/editor-lifecycle corrections. On final combined source ecc09aa544c, all 29 tests across the four corrected files pass, and changed-code quality reports zero findings across those four files. The four-file incremental gate at d63f823ac17 passed 25/26 checks, including unit tests; its sole casting-annotation finding was then corrected and the quality scan rerun successfully. The final follow-up changes only that annotation.

Fresh release fixtures recover five of the eight cross-version suites. Three remain unverified: structured agent-session wire, reported lossy terminal snapshot, and runtime-source fence. Their failed attempts hit archive/extraction deadlines (45 seconds), a setup-hook deadline (180 seconds), and teardown RPC errors; the harness and these suites are unchanged from the audit baseline. The initial generated caches also contained missing files after explicit ENOSPC errors on tmpfs inodes. A standalone single-ref preparation also hit its extraction deadline. Main-filesystem extraction, disabled shared caching, and serial retries are documented separately; these results do not establish a complete mixed-version integration pass. Earlier focused mobile and actual Git 2.25.5 checks remain separate evidence. Native macOS/Windows, physical mobile devices and live SSH/WSL are also unexecuted coverage gaps.

Review

  • Reuses the existing bounded reader and 10 MiB blob limit.
  • Reviewed handle lifetime, missing/error classification, platform routing, and cache safety.

@OrcaWin

OrcaWin commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator Author

The stat-then-readFile race only lets a file that grows during a millisecond window overshoot the 10 MiB cap by the bytes written in that window, so the practical impact is negligible. As written, the oversized branch also drops main's TOO_LARGE_BLOB/tooLarge (#34882), which would regress the 'diff too large' message, and the PR conflicts with main. Closing under the strict bar.

@OrcaWin OrcaWin closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant