Skip to content

Commit 6abfedc

Browse files
authored
fix: stale Control UI tabs stop retrying after updates (#123932)
* fix(ui): preserve stale client refresh compatibility * fix(ui): cover build-aware frozen clients
1 parent 8266adf commit 6abfedc

3 files changed

Lines changed: 41 additions & 16 deletions

File tree

‎src/gateway/server/ws-connection/connect-session.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,16 @@ export async function attachAuthenticatedGatewayConnect(
323323
requestOrigin,
324324
});
325325
if (controlUiBuildMismatch) {
326-
const message = "Control UI updated; reload this page to continue";
326+
// Build identity predates this rejection. Frozen clients recognize the shipped
327+
// protocol-mismatch signal and surface its literal reload guidance.
328+
const message = "protocol mismatch: Control UI updated; reload this page to continue";
327329
markHandshakeFailure("control-ui-build-mismatch", {
328330
clientBuildId: controlUiBuildMismatch.clientBuildId ?? "legacy",
329331
gatewayBuildId: controlUiBuildMismatch.gatewayBuildId,
330332
});
331333
sendHandshakeErrorResponse(ErrorCodes.UNAVAILABLE, message, {
332334
retryable: false,
333-
details: {
334-
code: ConnectErrorDetailCodes.CONTROL_UI_BUILD_MISMATCH,
335-
gatewayBuildId: controlUiBuildMismatch.gatewayBuildId,
336-
reloadRequired: true,
337-
},
335+
details: { code: ConnectErrorDetailCodes.PROTOCOL_MISMATCH },
338336
});
339337
logWsControl.warn(
340338
`control ui build rejected conn=${connId} clientBuild=${formatForLog(controlUiBuildMismatch.clientBuildId ?? "legacy")} gatewayBuild=${formatForLog(controlUiBuildMismatch.gatewayBuildId)}; reload required`,

‎src/gateway/server/ws-connection/message-handler.control-ui-build-admission.test.ts‎

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ const {
1212
handleGatewayRequestMock,
1313
incrementPresenceVersionMock,
1414
resolveRuntimeServiceBuildIdMock,
15+
setLastFrameMetaMock,
1516
upsertPresenceMock,
1617
} = vi.hoisted(() => ({
1718
handleGatewayRequestMock: vi.fn(),
1819
incrementPresenceVersionMock: vi.fn(() => 2),
1920
resolveRuntimeServiceBuildIdMock: vi.fn<() => string | null>(() => "gateway-build"),
21+
setLastFrameMetaMock: vi.fn(),
2022
upsertPresenceMock: vi.fn(),
2123
}));
2224

@@ -98,7 +100,17 @@ afterEach(() => {
98100
});
99101

100102
describe("Control UI build admission over WebSocket", () => {
101-
it("rejects a legacy same-origin document before registration or RPC dispatch", async () => {
103+
it.each([
104+
{
105+
name: "legacy same-origin document",
106+
clientBuildId: undefined,
107+
},
108+
{
109+
name: "explicit stale same-origin document",
110+
clientBuildId: "stale-build",
111+
},
112+
])("rejects a $name before registration or RPC dispatch", async (testCase) => {
113+
const { clientBuildId } = testCase;
102114
const wss = new WebSocketServer({ host: "127.0.0.1", port: 0 });
103115
await withDeadline(
104116
new Promise<void>((resolve) => {
@@ -138,7 +150,9 @@ describe("Control UI build admission over WebSocket", () => {
138150
nodeLifecycleDispatch: new GatewayNodeLifecycleDispatchTracker(),
139151
refreshHealthSnapshot: vi.fn(),
140152
send,
141-
close: (code, reason) => socket.close(code, reason),
153+
close: (code, reason) => {
154+
setTimeout(() => socket.close(code, reason), 25);
155+
},
142156
isClosed: () => socket.readyState >= WebSocket.CLOSING,
143157
clearHandshakeTimer: vi.fn(),
144158
getClient: () => connectedClient as never,
@@ -149,7 +163,7 @@ describe("Control UI build admission over WebSocket", () => {
149163
setHandshakeState: vi.fn(),
150164
advanceHandshakePhase: vi.fn(),
151165
setCloseCause: vi.fn(),
152-
setLastFrameMeta: vi.fn(),
166+
setLastFrameMeta: setLastFrameMetaMock,
153167
originCheckMetrics: { hostHeaderFallbackAccepted: 0 },
154168
logGateway: createLogger() as never,
155169
logHealth: createLogger() as never,
@@ -196,6 +210,7 @@ describe("Control UI build admission over WebSocket", () => {
196210
version: "2026.8.1",
197211
platform: "web",
198212
mode: "webchat",
213+
...(clientBuildId ? { buildId: clientBuildId } : {}),
199214
},
200215
role: "operator",
201216
caps: [],
@@ -204,21 +219,32 @@ describe("Control UI build admission over WebSocket", () => {
204219
}),
205220
);
206221

207-
expect(await response).toMatchObject({
222+
const rejection = await response;
223+
expect(rejection).toMatchObject({
208224
ok: false,
209225
error: {
210226
code: ErrorCodes.UNAVAILABLE,
227+
message: "protocol mismatch: Control UI updated; reload this page to continue",
211228
retryable: false,
212-
details: {
213-
code: ConnectErrorDetailCodes.CONTROL_UI_BUILD_MISMATCH,
214-
gatewayBuildId: "gateway-build",
215-
reloadRequired: true,
216-
},
229+
details: { code: ConnectErrorDetailCodes.PROTOCOL_MISMATCH },
217230
},
218231
});
232+
ws.send(
233+
JSON.stringify({
234+
type: "req",
235+
id: "post-rejection-rpc",
236+
method: "health",
237+
params: {},
238+
}),
239+
);
219240
expect(await closed).toBe(1008);
220241
expect(connectedClient).toBeNull();
221242
expect(upsertPresenceMock).not.toHaveBeenCalled();
243+
expect(setLastFrameMetaMock).toHaveBeenCalledWith({
244+
type: "req",
245+
method: "health",
246+
id: "post-rejection-rpc",
247+
});
222248
expect(handleGatewayRequestMock).not.toHaveBeenCalled();
223249
} finally {
224250
ws.terminate();

‎ui/src/e2e/login-gate.e2e.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ suite.define(() => {
120120
await gateway.waitForRequest("connect");
121121
await gateway.rejectDeferred("connect", {
122122
code: "INVALID_REQUEST",
123-
message: "protocol mismatch",
123+
message: "protocol mismatch: Control UI updated; reload this page to continue",
124124
details: { code: ConnectErrorDetailCodes.PROTOCOL_MISMATCH },
125125
});
126126

@@ -129,6 +129,7 @@ suite.define(() => {
129129
expect((await failure.textContent())?.toLowerCase()).toContain(
130130
"supported connection protocol",
131131
);
132+
expect(await page.locator(".login-gate__failure-refresh").isVisible()).toBe(true);
132133
await page.clock.runFor(1_600);
133134
expect(await gateway.getRequests("connect")).toHaveLength(1);
134135
} finally {

0 commit comments

Comments
 (0)