Read a restored worktree again instead of serving its not-git snapshot (#10224)

When a worktree folder disappears, the workspace git service can cache a
not-git snapshot before it notices and suspends the workspace. After the
folder comes back, a plain getSnapshot returned that cached snapshot
before it tried to resume, so checkout status said "not a git repository"
until the 60 s missing-folder probe. The Changes panel of a just-restored
worktree had no repository header during that time.

Resume a suspended workspace first, then serve the cached snapshot.

This made e2e worktree-restore.spec.ts:167 flaky in CI.

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
This commit is contained in:
paseo-bot[bot] authored and GitHub committed 2026-11-19 12:48:36 +00:00
1 parent 4929ed5a0f
commit 32218adfec
2 files changed
+28 -3

No files matched your search

@@ -2381,6 +2381,29 @@ describe("WorkspaceGitServiceImpl with workspace folders that no longer exist",
await service.dispose();
});
test("a plain snapshot read resumes a suspended workspace whose folder is back, instead of returning the non-git snapshot cached while it was gone", async () => {
const workspace = await createTemporaryFolder();
const git = createFolderBackedGit();
const service = createService(git.deps);
const subscription = service.registerWorkspace({ cwd: workspace }, vi.fn());
await waitForObservationToSettle(service, 1);
await rm(workspace, { recursive: true, force: true });
service.onWorkspaceStateMayHaveChanged(workspace);
await vi.advanceTimersByTimeAsync(1_000);
await waitForRefreshesToSettle(service);
expect((await service.getSnapshot(workspace)).git.isGit).toBe(false);
await advanceThroughDegradedPolls(service);
await waitForObservationToSettle(service, 0);
await mkdir(workspace);
const snapshot = await service.getSnapshot(workspace);
expect(snapshot.git.isGit).toBe(true);
subscription.unsubscribe();
await service.dispose();
});
test("a resumed workspace rebuilds observation from fresh facts, not the non-git facts cached while its folder was gone", async () => {
const workspace = await createTemporaryFolder();
const git = createFolderBackedGit();
@@ -834,12 +834,14 @@ export class WorkspaceGitServiceImpl implements WorkspaceGitService {
cwd = resolve(cwd);
const request = this.normalizeRefreshRequest(options, "getSnapshot");
const target = this.ensureWorkspaceTarget(cwd);
if (!request.force && target.latestSnapshot) {
return target.latestSnapshot;
}
// The snapshot cached while the folder was gone can say "not git". Resume
// first, so a restored folder is read again instead of served from it.
if (target.folderMissing) {
await this.resumeWorkspaceIfFolderRestored(target);
}
if (!request.force && target.latestSnapshot) {
return target.latestSnapshot;
}
return this.requestWorkspaceSnapshot(target, request);
}