Skip to content

Commit 13330c5

Browse files
committed
fix(client-runtime): reload the thread list when a reconnect reaches an upgraded server
1 parent f01279f commit 13330c5

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎packages/client-runtime/src/state/shell-sync.test.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,11 +1154,13 @@ describe("environment shell cold start from a vouched cache", () => {
11541154
Queue.offer(subscribeInputs, subscribeInput).pipe(Effect.as(Stream.fromQueue(events))),
11551155
),
11561156
} as unknown as WsRpcProtocolClient;
1157-
const newSession = (): RpcSession.RpcSession => ({
1157+
const newSession = (
1158+
serverVersion = input.serverVersion ?? SERVER_VERSION,
1159+
): RpcSession.RpcSession => ({
11581160
...session(client),
11591161
initialConfig: Effect.succeed({
11601162
shellResumeCompletionMarker: true,
1161-
environment: { serverVersion: input.serverVersion ?? SERVER_VERSION },
1163+
environment: { serverVersion },
11621164
} as never),
11631165
});
11641166
const activeSession = yield* SubscriptionRef.make(Option.some(newSession()));
@@ -1209,6 +1211,8 @@ describe("environment shell cold start from a vouched cache", () => {
12091211
httpLoads,
12101212
shellState,
12111213
resubscribe: SubscriptionRef.set(activeSession, Option.some(newSession())),
1214+
reconnectToServer: (serverVersion: string) =>
1215+
SubscriptionRef.set(activeSession, Option.some(newSession(serverVersion))),
12121216
stateWhere: (predicate: (state: EnvironmentShellState) => boolean) =>
12131217
SubscriptionRef.changes(shellState).pipe(
12141218
Stream.filter(predicate),
@@ -1315,6 +1319,18 @@ describe("environment shell cold start from a vouched cache", () => {
13151319
}),
13161320
);
13171321

1322+
it.effect("reloads over HTTP when a reconnect reaches an upgraded server", () =>
1323+
Effect.gen(function* () {
1324+
const h = yield* makeColdStart({ vouch: undefined });
1325+
expect(yield* Queue.take(h.subscribeInputs)).toMatchObject({ afterSequence: HTTP_SEQUENCE });
1326+
1327+
// An upgrade can rebuild projections that replay would not resend.
1328+
yield* h.reconnectToServer("2.0.0");
1329+
expect(yield* Queue.take(h.subscribeInputs)).toMatchObject({ afterSequence: HTTP_SEQUENCE });
1330+
expect(yield* Ref.get(h.httpLoads)).toBe(2);
1331+
}),
1332+
);
1333+
13181334
it.effect("saves a vouch stamped at the HTTP snapshot", () =>
13191335
Effect.gen(function* () {
13201336
const h = yield* makeColdStart({ vouch: undefined });

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,10 @@ export const makeEnvironmentShellState = Effect.fn("EnvironmentShellState.make")
470470
// A shell from a server snapshot resumes from its in-memory cursor. Cached data, or a
471471
// snapshot taken with other omissions, reloads over HTTP so a valid cursor cannot
472472
// preserve incomplete data; only a matching cache vouch lets the first subscription resume.
473-
const hasAuthoritativeSnapshot = (yield* Ref.get(authoritativeOmission)) === omissionKey;
473+
// A server upgrade can rebuild projections that replay would not resend.
474+
const hasAuthoritativeSnapshot =
475+
(yield* Ref.get(authoritativeOmission)) === omissionKey &&
476+
((yield* Ref.get(lineageVouch))?.serverVersion ?? null) === serverVersion;
474477
const cacheVouch = yield* Ref.getAndSet(cacheResumeVouch, undefined);
475478
let canResume = hasAuthoritativeSnapshot;
476479
let current = yield* SubscriptionRef.get(state);

0 commit comments

Comments
 (0)