authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-04-13 13:16:08-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-04-13 20:16:08+00:00
logf5ecca4480b5b399833cdeade4c4abce1b74cf4d
tree580e530b777d6808afef9b597f25acddc983bd96
parentcadd7086462c2db3c92185d4a5488f9ad132cc34
signature Signed by PGP key B5690EEEBB952194

Clear tracked RPCs on reconnect (#2000)


2 files changed, 52 insertions(+), 0 deletions(-)

apps/web/src/rpc/wsTransport.test.ts+50
......@@ -417,6 +417,56 @@ describe("WsTransport", () => {
417417 await transport.dispose();
418418 }, 5_000);
419419
420 it("clears slow unary request tracking when the transport reconnects", async () => {
421 const slowAckThresholdMs = 25;
422 setSlowRpcAckThresholdMsForTests(slowAckThresholdMs);
423 const transport = createTransport("ws://localhost:3020");
424
425 const requestPromise = transport.request((client) =>
426 client[WS_METHODS.serverUpsertKeybinding]({
427 command: "terminal.toggle",
428 key: "ctrl+k",
429 }),
430 );
431
432 await waitFor(() => {
433 expect(sockets).toHaveLength(1);
434 });
435
436 const firstSocket = getSocket();
437 firstSocket.open();
438
439 await waitFor(() => {
440 expect(firstSocket.sent).toHaveLength(1);
441 });
442
443 const firstRequest = JSON.parse(firstSocket.sent[0] ?? "{}") as { id: string };
444
445 await waitFor(() => {
446 expect(getSlowRpcAckRequests()).toMatchObject([
447 {
448 requestId: firstRequest.id,
449 tag: WS_METHODS.serverUpsertKeybinding,
450 },
451 ]);
452 }, 1_000);
453
454 void requestPromise.catch(() => undefined);
455
456 await transport.reconnect();
457
458 expect(getSlowRpcAckRequests()).toEqual([]);
459
460 await waitFor(() => {
461 expect(sockets).toHaveLength(2);
462 });
463
464 const secondSocket = getSocket();
465 secondSocket.open();
466
467 await transport.dispose();
468 }, 5_000);
469
420470 it("sends unary RPC requests and resolves successful exits", async () => {
421471 const transport = createTransport("ws://localhost:3020");
422472
apps/web/src/rpc/wsTransport.ts+2
......@@ -12,6 +12,7 @@ import {
1212import { RpcClient } from "effect/unstable/rpc";
1313
1414import { ClientTracingLive } from "../observability/clientTracing";
15import { clearAllTrackedRpcRequests } from "./requestLatencyState";
1516import {
1617 createWsRpcProtocolLayer,
1718 makeWsRpcProtocolClient,
......@@ -189,6 +190,7 @@ export class WsTransport {
189190 throw new Error("Transport disposed");
190191 }
191192
193 clearAllTrackedRpcRequests();
192194 const previousSession = this.session;
193195 this.session = this.createSession();
194196 await this.closeSession(previousSession);