diff --git a/apps/web/src/rpc/requestLatencyState.ts b/apps/web/src/rpc/requestLatencyState.ts index 01c59ea0d5..d21e37b529 100644 --- a/apps/web/src/rpc/requestLatencyState.ts +++ b/apps/web/src/rpc/requestLatencyState.ts @@ -3,8 +3,9 @@ import { Atom } from "effect/unstable/reactivity"; import { appAtomRegistry } from "./atomRegistry"; -export const SLOW_RPC_ACK_THRESHOLD_MS = 2_500; +export const SLOW_RPC_ACK_THRESHOLD_MS = 15_000; export const MAX_TRACKED_RPC_ACK_REQUESTS = 256; +let slowRpcAckThresholdMs = SLOW_RPC_ACK_THRESHOLD_MS; export interface SlowRpcAckRequest { readonly requestId: string; @@ -56,12 +57,12 @@ export function trackRpcRequestSent(requestId: string, tag: string): void { startedAt: new Date(startedAtMs).toISOString(), startedAtMs, tag, - thresholdMs: SLOW_RPC_ACK_THRESHOLD_MS, + thresholdMs: slowRpcAckThresholdMs, }; const timeoutId = setTimeout(() => { pendingRpcAckRequests.delete(requestId); appendSlowRpcAckRequest(request); - }, SLOW_RPC_ACK_THRESHOLD_MS); + }, slowRpcAckThresholdMs); pendingRpcAckRequests.set(requestId, { request, @@ -119,9 +120,14 @@ function evictOldestPendingRpcRequestIfNeeded(): void { } export function resetRequestLatencyStateForTests(): void { + slowRpcAckThresholdMs = SLOW_RPC_ACK_THRESHOLD_MS; clearAllTrackedRpcRequests(); } +export function setSlowRpcAckThresholdMsForTests(thresholdMs: number): void { + slowRpcAckThresholdMs = thresholdMs; +} + export function useSlowRpcAckRequests(): ReadonlyArray { return useAtomValue(slowRpcAckRequestsAtom); } diff --git a/apps/web/src/wsTransport.test.ts b/apps/web/src/wsTransport.test.ts index af02a5288f..da5404b239 100644 --- a/apps/web/src/wsTransport.test.ts +++ b/apps/web/src/wsTransport.test.ts @@ -5,7 +5,11 @@ import { __resetClientTracingForTests, configureClientTracing, } from "./observability/clientTracing"; -import { getSlowRpcAckRequests, resetRequestLatencyStateForTests } from "./rpc/requestLatencyState"; +import { + getSlowRpcAckRequests, + resetRequestLatencyStateForTests, + setSlowRpcAckThresholdMsForTests, +} from "./rpc/requestLatencyState"; import { getWsConnectionStatus, getWsConnectionUiState, @@ -292,6 +296,8 @@ describe("WsTransport", () => { }); it("marks unary requests as slow until the first server ack arrives", async () => { + const slowAckThresholdMs = 25; + setSlowRpcAckThresholdMsForTests(slowAckThresholdMs); const transport = new WsTransport("ws://localhost:3020"); const requestPromise = transport.request((client) => @@ -320,7 +326,7 @@ describe("WsTransport", () => { tag: WS_METHODS.serverUpsertKeybinding, }, ]); - }, 5_000); + }, 1_000); socket.serverMessage( JSON.stringify({ @@ -343,7 +349,7 @@ describe("WsTransport", () => { expect(getSlowRpcAckRequests()).toEqual([]); await transport.dispose(); - }, 10_000); + }, 5_000); it("sends unary RPC requests and resolves successful exits", async () => { const transport = new WsTransport("ws://localhost:3020");