@@ -5,6 +5,12 @@ import { Atom } from "effect/unstable/reactivity";
55import { appAtomRegistry } from "./atomRegistry" ;
66
77export const SLOW_RPC_ACK_THRESHOLD_MS = 15_000 ;
8+ /**
9+ * Some requests are slow by design — they shell out to a package manager on the
10+ * server and only respond once the install finishes. Warning about those after
11+ * 15s is noise, so they get a much longer leash.
12+ */
13+ export const LONG_RUNNING_RPC_ACK_THRESHOLD_MS = 120_000 ;
814export const MAX_TRACKED_RPC_ACK_REQUESTS = 256 ;
915let slowRpcAckThresholdMs = SLOW_RPC_ACK_THRESHOLD_MS ;
1016
@@ -22,7 +28,12 @@ interface PendingRpcAckRequest {
2228}
2329
2430const pendingRpcAckRequests = new Map < string , PendingRpcAckRequest > ( ) ;
25- const untrackedRpcAckTags = new Set < string > ( [ WS_METHODS . previewAutomationConnect ] ) ;
31+ const untrackedRpcAckMethods = new Set < string > ( [ WS_METHODS . previewAutomationConnect ] ) ;
32+ const longRunningRpcAckMethods = new Set < string > ( [
33+ WS_METHODS . serverUpdateProvider ,
34+ WS_METHODS . serverRefreshProviders ,
35+ WS_METHODS . serverUpdateServer ,
36+ ] ) ;
2637
2738const slowRpcAckRequestsAtom = Atom . make < ReadonlyArray < SlowRpcAckRequest > > ( [ ] ) . pipe (
2839 Atom . keepAlive ,
@@ -37,34 +48,46 @@ function getSlowRpcAckRequestsValue(): ReadonlyArray<SlowRpcAckRequest> {
3748 return appAtomRegistry . get ( slowRpcAckRequestsAtom ) ;
3849}
3950
40- function shouldTrackRpcAck ( tag : string ) : boolean {
41- return ! tag . includes ( "subscribe" ) && ! untrackedRpcAckTags . has ( tag ) ;
51+ function shouldTrackRpcAck ( method : string ) : boolean {
52+ return ! method . includes ( "subscribe" ) && ! untrackedRpcAckMethods . has ( method ) ;
53+ }
54+
55+ function rpcAckThresholdMs ( method : string ) : number {
56+ return longRunningRpcAckMethods . has ( method )
57+ ? Math . max ( slowRpcAckThresholdMs , LONG_RUNNING_RPC_ACK_THRESHOLD_MS )
58+ : slowRpcAckThresholdMs ;
4259}
4360
4461export function getSlowRpcAckRequests ( ) : ReadonlyArray < SlowRpcAckRequest > {
4562 return getSlowRpcAckRequestsValue ( ) ;
4663}
4764
48- export function trackRpcRequestSent ( requestId : string , tag : string ) : void {
49- if ( ! shouldTrackRpcAck ( tag ) ) {
65+ /**
66+ * Starts the slow-request timer for one in-flight unary RPC. `method` is the
67+ * bare WS method (used to decide whether and how long to wait); `tag` is the
68+ * human-readable label shown in the toast, which defaults to the method.
69+ */
70+ export function trackRpcRequestSent ( requestId : string , method : string , tag = method ) : void {
71+ if ( ! shouldTrackRpcAck ( method ) ) {
5072 return ;
5173 }
5274
5375 clearTrackedRpcRequest ( requestId ) ;
5476 evictOldestPendingRpcRequestIfNeeded ( ) ;
5577
5678 const startedAtMs = Date . now ( ) ;
79+ const thresholdMs = rpcAckThresholdMs ( method ) ;
5780 const request : SlowRpcAckRequest = {
5881 requestId,
5982 startedAt : new Date ( startedAtMs ) . toISOString ( ) ,
6083 startedAtMs,
6184 tag,
62- thresholdMs : slowRpcAckThresholdMs ,
85+ thresholdMs,
6386 } ;
6487 const timeoutId = setTimeout ( ( ) => {
6588 pendingRpcAckRequests . delete ( requestId ) ;
6689 appendSlowRpcAckRequest ( request ) ;
67- } , slowRpcAckThresholdMs ) ;
90+ } , thresholdMs ) ;
6891
6992 pendingRpcAckRequests . set ( requestId , {
7093 request,
0 commit comments