Skip to content

agentHost: capture working bytes instead of stale staged blobs - #340634

Merged
roblourens merged 1 commit into
mainfrom
roblou/agents/git-snapshot-staged-stat-fix
Oct 9, 2026
Merged

roblourens merged 1 commit into
mainfrom
roblou/agents/git-snapshot-staged-stat-fix

Conversation

@roblourens

@roblourens roblourens commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

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\n for staged-new.txt instead of the newer working bytes edited\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 status even when Git considers its working file stat-identical to its staged blob. With a same-size edit and indistinguishable file metadata, git add can 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-tree process; 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

  • A new real-Git regression failed before the production change: both added and modified paths returned staged\n, while indexUnchanged stayed true. It passes with the change.
  • Standalone controlled Git comparison: copied-index strategy missed the edit in 100/100 iterations; HEAD-seeded strategy captured the correct bytes in 100/100, preserving the real index. Natural macOS timing alone did not reproduce the failure (0/100).
  • 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 --check and signed commit hygiene — passed.

Client output was refreshed with the repository's applyIncrementalClientChanges helper. 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)

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]>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 01:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: ec6ac57b Current: c6b55429

Changed (1)

sessions/chatCompositeBar/OverflowingTabs/Light
Before After
before after

@roblourens
roblourens marked this pull request as ready for review October 9, 2026 02:05
@roblourens
roblourens enabled auto-merge (squash) October 9, 2026 02:05
@roblourens
roblourens merged commit c672666 into main Oct 9, 2026
62 checks passed
@roblourens
roblourens deleted the roblou/agents/git-snapshot-staged-stat-fix branch October 9, 2026 02:17
@vs-code-engineering vs-code-engineering Bot added this to the 1.142.0 milestone Oct 9, 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.

3 participants