Repository navigation
agentHost: capture working bytes instead of stale staged blobs - #340634
Merged
Merged
Conversation
Use the existing HEAD-seeded temporary index when staged changes could reuse cached blob metadata despite newer same-size working bytes. Preserve index copying for HEAD-equivalent indexes and leave the real index unchanged. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Packaged Windows validation remains necessary because the original failure occurred on Windows and was not reproduced there locally.
0 open findings
What changed in this PR
Fixes Agent Host Git snapshots returning stale staged blobs by avoiding copied indexes when staged changes exist.
Changes:
- Restricts index copying to HEAD-equivalent indexes.
- Adds unit and real-Git regression coverage.
- Documents the snapshot invariant.
| File | Description |
|---|---|
agentHostGitService.ts |
Falls back to HEAD-seeded indexes for staged changes. |
agentHostGitService.test.ts |
Updates status eligibility expectations. |
agentHostGitService.integrationTest.ts |
Reproduces stale staged-blob behavior deterministically. |
e2e/README.md |
Documents required capture behavior. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
roblourens
marked this pull request as ready for review
October 9, 2026 02:05
roblourens
enabled auto-merge (squash)
October 9, 2026 02:05
Paul (pwang347)
approved these changes
Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Failure
Main Windows build 482526, tested SHA
4d22bd07b6db27fc0b254da9bb259ab1cabf47a6, failed the real-Git test:captureWorkingTreeAsTree captures working tree content when the index differs from HEAD, including in linked worktrees.Its copied-index snapshot returned
staged\nforstaged-new.txtinstead of the newer working bytesedited\n. The HEAD-seeded fallback and linked-worktree outputs matched.This is a working-tree snapshot correctness issue, not an expected intermediate state or a retryable provider error. It is separate from #340421.
Cause and fix
The capture optimization copies the real index and restages status-reported paths into that temporary copy. A staged path remains in
git statuseven when Git considers its working file stat-identical to its staged blob. With a same-size edit and indistinguishable file metadata,git addcan therefore reuse the old staged blob rather than rehash the working bytes.Restrict index copying to HEAD-equivalent indexes. If the index contains staged changes, use the existing HEAD-seeded fallback, which does not carry the staged blobs' stat cache. The real index remains byte-for-byte unchanged.
The clean-tree early return, scoped staging/pathspec handling, linked-worktree handling, and copied-index optimization for unstaged/untracked changes remain intact. Captures with staged changes pay the existing extra
read-treeprocess; correctness takes priority over that optimization in the affected case.The deterministic regression uses real Git with
core.checkStat=minimal,core.trustctime=false, and equal working-file timestamps before and after staging/editing. It verifies both a staged addition and a staged modification, exact working bytes, the status shape, and preservation of the real index.This reproduces the unsafe stat-cache assumption and the CI's stale-blob outcome on macOS. It does not establish that the Windows worker had these exact Git configuration values; packaged Windows validation is required.
Provenance
Vijay Upadya's September 30 optimization/test in #339016 introduced the copied-index path. The October 1 fix in #339051 preserves the copied index's timestamp for racily clean edits; that fix was already present in the failing main revision. This change additionally avoids reusing staged blob metadata when status is still staged but working bytes are stat-indistinguishable.
Validation
staged\n, whileindexUnchangedstayed true. It passes with the change.env -u COPILOT_HOME VSCODE_SKIP_PRELAUNCH=1 ./scripts/test-integration.sh --run src/vs/platform/agentHost/test/node/agentHostGitService.integrationTest.ts --reporter dot— 97 passed.env -u COPILOT_HOME VSCODE_SKIP_PRELAUNCH=1 ./scripts/test.sh --run src/vs/platform/agentHost/test/node/agentHostGitService.test.ts --reporter dot— 56 passed.env -u COPILOT_HOME VSCODE_SKIP_PRELAUNCH=1 ./scripts/test-integration.sh --run src/vs/platform/agentHost/test/node/agentHostGitService.integrationTest.ts --grep 'captureWorkingTreeAsTree' --reporter dot— five repetitions, 7 passed each: 35 capture passes including the originally failing title.npm run typecheck-client— passed.npm run eslint -- src/vs/platform/agentHost/node/agentHostGitService.ts src/vs/platform/agentHost/test/node/agentHostGitService.test.ts src/vs/platform/agentHost/test/node/agentHostGitService.integrationTest.ts— passed.node build/lib/formatter.ts --verify src/vs/platform/agentHost/node/agentHostGitService.ts src/vs/platform/agentHost/test/node/agentHostGitService.test.ts src/vs/platform/agentHost/test/node/agentHostGitService.integrationTest.ts— passed.git diff --checkand signed commit hygiene — passed.Client output was refreshed with the repository's
applyIncrementalClientChangeshelper. No dependency installation, model fixtures, timeouts, skips, or unrelated Git extension changes.GitHub 37869900881 completed green overall at
08dd43b353cc. All three Electron integration logs explicitly confirm both the originally failing linked-worktree/index-diff test and the new stat-identical staged-file regression passed on Windows, Linux, and macOS; these are executed passes, not skipped tests or inferred job results.Both packaged Windows/Linux/macOS definition-111 builds completed green overall at the same revision, with publishing and release disabled: 482552 and 482553. All six Electron integration tasks passed on their first attempt. Their logs explicitly confirm both the originally failing test and the new deterministic regression executed and passed in each run (12 packaged regression passes). Required cross-platform repeat validation is complete.
(Written by Copilot)