Skip to content

fix(git): reject incomplete diff reads instead of empty content - #34967

Closed
OrcaWin wants to merge 1 commit into
mainfrom
OrcaWin/git-incomplete-diff-reads
Closed

OrcaWin wants to merge 1 commit into
mainfrom
OrcaWin/git-incomplete-diff-reads

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​85 $\color{#cf222e}{\Huge{\mathbf{−}}}$​12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​73
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​136 $\color{#cf222e}{\Huge{\mathbf{−}}}$​112 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24

Problem and behavior

An unreadable working file or Git object currently becomes empty text in a successful diff response. A missing staged blob can look like a complete deletion; a corrupt history object can look like no changes. The existing failed blob marker only prevented cache retention.

Reject these incomplete reads before building or caching a diff. Existing RPC rejection handling can display the error. Proven additions/deletions, unborn branches, root commits, binary previews, and oversized-file fallbacks keep their existing behavior.

Implementation

  • Reuse one blob-read assertion across working/index, branch, commit and submodule commit-range readers; remove their empty-success catch paths.
  • Verify tree-path absence with a successful empty literal ls-tree lookup. Actual Git can emit its normal “path not in HEAD” message when the HEAD commit object is missing, so that message alone is insufficient proof of absence.
  • Recognize an unborn HEAD only after resolving its symbolic branch and proving the raw branch ref absent. A ref whose object is missing remains a failure.
  • Successful blob reads add no Git subprocess. A missing tree-path diagnostic adds one bounded exact-path lookup; an unborn HEAD adds symbolic/raw-ref probes. This is correctness work rather than a latency optimization.

Evidence

Real temporary Git repositories exercise the production readers. Deleting a staged blob reproduces the old successful empty-side response; deleting historical blobs reproduces empty comparison content. An unreadable working file is rejected and its bytes remain intact after access is restored. Repairing objects recovers correct diffs without retaining an empty result.

The initial regression against unchanged production failed both assertions, with four valid-addition/deletion/root controls passing. Final coverage also checks each historical reader, missing HEAD objects, binary read failure and unusable host paths.

Validation

  • Focused diff/cache/submodule suites: 66/66 passed on Linux with Node 24.22.0.
  • Actual Git 2.25.5: 11/11 real-repository tests passed, including unborn/add/delete/root controls and corruption/recovery.
  • Full final pnpm tc: passed. Focused lint and format checks passed. Independent production source review passed; literal bracket/nested path lookup was independently checked on Git 2.25.5.
  • Required pnpm check:changed --maxWorkers=2 --base=2d3e7e452000c26433650d75422e79a06be80684 was attempted. It caught unsupported buffer-option fields, which were removed; the final full typecheck passes. Its broad affected-test selection produced no test results for over ten minutes and was stopped. The aggregate gate is incomplete; no full-green claim. Explicit suites above are the verified runtime evidence.
  • All tests used background launch. Native macOS/Windows, WSL and live SSH were not run. Existing provider routing, wire shapes and Git 2.25 argv compatibility are preserved. Folder workspaces retain their existing Git gates; mobile receives the existing RPC refusal shape.

Integration requirement

Keep this draft blocked on the editor rejected-load protection in #25407 before marking it ready. That PR prevents error text from becoming editable working-file content. This patch fixes the backend's false-success responses and does not duplicate that renderer change. It also overlaps the blob-read module touched by #34778; combine its literal-object read with these absence/failure checks and rerun these regressions when resolving the source conflict.

Visual proof

Backend response/error change, with real-Git before/after assertions above; no layout or styling changes. Rendered editable-error integration remains part of #25407.

@OrcaWin

OrcaWin commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator Author

main already keeps failed blob reads out of the settled diff cache (reusable=!readFailed). Turning those reads into rejections makes the renderer show editable 'Error loading diff' text that can be saved over the working file (#25407 is still open). It also discards a good working-tree side when the other side fails, hard-fails on transient WSL/SSH errors, and adds an ls-tree spawn to every add/delete/untracked diff. All of this is for corrupt-object and EACCES cases that healthy repos never hit.

@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