Skip to content

Commit dfe87da

Browse files
ahalekellyclaude
andcommitted
fix(client-runtime): keep unchanged projects on shell reload
An authoritative shell snapshot replaced every project object, so each reconnect gave project atoms, the project list, and handlers built from it new identities, and re-rendered every home thread row. Keep a previous project when it equals its replacement, as thread shells already do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 879d92b commit dfe87da

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

‎packages/client-runtime/src/state/shellReducer.test.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,31 @@ describe("applyShellStreamEvent", () => {
8585
});
8686

8787
it("authoritative lower-sequence reset replaces client-ahead structural state", () => {
88+
const unchanged = { ...v2Project, id: ProjectId.make("project-unchanged"), repositoryIdentity };
8889
const previous = {
8990
...v2ShellSnapshot,
9091
snapshotSequence: 9,
91-
projects: [{ ...v2Project, title: "Client ahead", repositoryIdentity }],
92+
projects: [{ ...v2Project, title: "Client ahead", repositoryIdentity }, unchanged],
9293
threads: [{ ...v2ThreadShell, title: "Local-only thread" }],
9394
};
9495
const next = mergeShellSnapshotProjects(previous, {
9596
...v2ShellSnapshot,
9697
snapshotSequence: 3,
97-
projects: [{ ...v2Project, title: "Server reset", repositoryIdentity: null }],
98+
projects: [
99+
{ ...v2Project, title: "Server reset", repositoryIdentity: null },
100+
{ ...unchanged, scripts: [...unchanged.scripts] },
101+
],
98102
threads: [{ ...v2ThreadShell, title: "Server thread" }],
99103
});
100104

101105
expect(next.snapshotSequence).toBe(3);
102106
expect(next.projects[0]?.title).toBe("Server reset");
103107
expect(next.projects[0]?.repositoryIdentity).toEqual(repositoryIdentity);
108+
expect(next.projects[1]).toBe(unchanged);
109+
expect(
110+
mergeShellSnapshotProjects(next, { ...v2ShellSnapshot, projects: [...next.projects] })
111+
.projects,
112+
).toBe(next.projects);
104113
expect(next.threads[0]?.title).toBe("Server thread");
105114
});
106115

‎packages/client-runtime/src/state/shellReducer.ts‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import {
2+
OrchestrationProjectShell,
23
OrchestrationV2ThreadShell,
34
RepositoryIdentity,
45
ThreadPullRequestLink,
5-
type OrchestrationProjectShell,
66
type OrchestrationV2ShellSnapshot,
77
type OrchestrationV2ShellStreamItem,
88
} from "@t3tools/contracts";
99
import * as Schema from "effect/Schema";
1010

1111
const sameThreadShell = Schema.toEquivalence(OrchestrationV2ThreadShell);
12+
const sameProjectShell = Schema.toEquivalence(OrchestrationProjectShell);
1213
const sameLinks = Schema.toEquivalence(Schema.UndefinedOr(Schema.Array(ThreadPullRequestLink)));
1314
const sameRepositoryIdentity = Schema.toEquivalence(
1415
Schema.UndefinedOr(Schema.NullOr(RepositoryIdentity)),
@@ -116,16 +117,16 @@ export function mergeShellSnapshotProjects(
116117
}
117118

118119
const previousById = new Map(previous.projects.map((project) => [project.id, project] as const));
119-
return {
120-
...next,
121-
projects: next.projects.map((project) => {
122-
const prior = previousById.get(project.id);
123-
if (resolvedRootSet?.has(project.workspaceRoot) === true) {
124-
return project;
125-
}
126-
return retainRepositoryIdentity(prior, project);
127-
}),
128-
};
120+
// Project atoms and shell persistence compare by reference, so unchanged projects keep their objects.
121+
const projects = next.projects.map((project) => {
122+
const prior = previousById.get(project.id);
123+
const merged = retainRepositoryIdentity(prior, project);
124+
return prior !== undefined && sameProjectShell(prior, merged) ? prior : merged;
125+
});
126+
const unchanged =
127+
projects.length === previous.projects.length &&
128+
projects.every((project, index) => project === previous.projects[index]);
129+
return { ...next, projects: unchanged ? previous.projects : projects };
129130
}
130131

131132
export function applyShellStreamEvent(

0 commit comments

Comments
 (0)