fix(workspace): publish checkout status after restore (#10406)

A client that read checkout status while the worktree was absent can keep that response after Restore. Send the current status to subscribed clients before publishing the recovered workspace.

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-21 12:39:02 +00:00
1 parent 344da5d088
commit 6946d0a429
3 files changed
+32 -2

No files matched your search

+8
View File
@@ -1722,6 +1722,14 @@ export class Session {
): Promise<void> {
try {
await this.syncWorkspaceGitObserverForWorkspace(workspace);
if (workspace.kind !== "directory" && this.wantsEvent("checkout_status_update")) {
// Recovery can refresh Git before this session starts observing again.
// Publish the current status to replace any read made while archived.
const snapshot = await this.workspaceGitService.getSnapshot(workspace.cwd, {
includeForge: false,
});
this.checkoutSession.emitStatusUpdate(workspace.cwd, snapshot, { force: true });
}
await this.emitWorkspaceUpdateForWorkspaceId(workspace.workspaceId);
} catch (error) {
this.sessionLogger.warn(
@@ -541,7 +541,11 @@ export class CheckoutSession {
}
}
emitStatusUpdate(cwd: string, snapshot: WorkspaceGitRuntimeSnapshot): void {
emitStatusUpdate(
cwd: string,
snapshot: WorkspaceGitRuntimeSnapshot,
options?: { force: boolean },
): void {
try {
const requestId = `subscription:${cwd}`;
const payload = {
@@ -557,7 +561,7 @@ export class CheckoutSession {
}),
};
const fingerprint = JSON.stringify(payload);
if (this.statusUpdateFingerprints.get(cwd) === fingerprint) return;
if (!options?.force && this.statusUpdateFingerprints.get(cwd) === fingerprint) return;
this.statusUpdateFingerprints.set(cwd, fingerprint);
this.host.emit({
type: "checkout_status_update",
@@ -250,6 +250,17 @@ test("existing branch changes remain visible after archive and restore", async (
commitFile(repoDir, "feature.txt", "feature change\n");
runGit(repoDir, "switch", "main");
await client.connect();
const events = client.observeEvents(["checkout_status_update"]);
const updates: { cwd: string; isGit: boolean; baseRef: string | null }[] = [];
events.subscribe({
snapshot: () => {},
update: (message) => {
if (message.type === "checkout_status_update") {
updates.push(message.payload);
}
},
});
await events.ready;
const created = await client.createWorkspace({
source: {
kind: "worktree",
@@ -266,9 +277,16 @@ test("existing branch changes remain visible after archive and restore", async (
expect(before.error).toBeNull();
expect(before.files.map((file) => file.path)).toEqual(["feature.txt"]);
expect((await client.getCheckoutStatus(cwd)).baseRef).toBe("main");
const gitStatus = { cwd, isGit: true, baseRef: "main" };
await client.checkoutRefresh(cwd);
expect(updates).toContainEqual(expect.objectContaining(gitStatus));
expect((await client.archiveWorkspace(workspace.id)).error).toBeNull();
expect(existsSync(cwd)).toBe(false);
await client.checkoutRefresh(cwd);
expect((await client.getCheckoutStatus(cwd)).isGit).toBe(false);
updates.length = 0;
await client.restoreWorkspace(workspace.id);
expect(updates).toContainEqual(expect.objectContaining(gitStatus));
expect(runGit(cwd, "rev-parse", "HEAD")).toBe(head);
expect((await client.getCheckoutStatus(cwd)).baseRef).toBe("main");
const after = await client.getCheckoutDiff(cwd, { mode: "base" });