@@ -7,6 +7,9 @@ import type { IRoomManager } from '@/socket/rooms'
77
88const logger = createLogger ( 'SubblocksHandlers' )
99
10+ /** Debounce interval for coalescing rapid subblock updates before persisting */
11+ const DEBOUNCE_INTERVAL_MS = 25
12+
1013type PendingSubblock = {
1114 latest : { blockId : string ; subblockId : string ; value : any ; timestamp : number }
1215 timeout : NodeJS . Timeout
@@ -22,7 +25,7 @@ const pendingSubblockUpdates = new Map<string, PendingSubblock>()
2225 * Removes the socket's operationIds from pending updates to prevent memory leaks.
2326 */
2427export function cleanupPendingSubblocksForSocket ( socketId : string ) : void {
25- for ( const [ key , pending ] of pendingSubblockUpdates . entries ( ) ) {
28+ for ( const [ , pending ] of pendingSubblockUpdates . entries ( ) ) {
2629 // Remove this socket's operation entries
2730 for ( const [ opId , sid ] of pending . opToSocket . entries ( ) ) {
2831 if ( sid === socketId ) {
@@ -52,6 +55,9 @@ export function setupSubblocksHandlers(socket: AuthenticatedSocket, roomManager:
5255 type : 'SESSION_ERROR' ,
5356 message : 'Session expired, please rejoin workflow' ,
5457 } )
58+ if ( operationId ) {
59+ socket . emit ( 'operation-failed' , { operationId, error : 'Session expired' } )
60+ }
5561 return
5662 }
5763
@@ -79,7 +85,7 @@ export function setupSubblocksHandlers(socket: AuthenticatedSocket, roomManager:
7985 existing . timeout = setTimeout ( async ( ) => {
8086 await flushSubblockUpdate ( workflowId , existing , roomManager )
8187 pendingSubblockUpdates . delete ( debouncedKey )
82- } , 25 )
88+ } , DEBOUNCE_INTERVAL_MS )
8389 } else {
8490 const opToSocket = new Map < string , string > ( )
8591 if ( operationId ) opToSocket . set ( operationId , socket . id )
@@ -89,7 +95,7 @@ export function setupSubblocksHandlers(socket: AuthenticatedSocket, roomManager:
8995 await flushSubblockUpdate ( workflowId , pending , roomManager )
9096 pendingSubblockUpdates . delete ( debouncedKey )
9197 }
92- } , 25 )
98+ } , DEBOUNCE_INTERVAL_MS )
9399 pendingSubblockUpdates . set ( debouncedKey , {
94100 latest : { blockId, subblockId, value, timestamp } ,
95101 timeout,
0 commit comments