@@ -95,6 +95,7 @@ export class SessionDataController implements ReactiveController, SessionCatalog
9595 private activeSessionLineageRetryTimer : ReturnType < typeof globalThis . setTimeout > | null = null ;
9696 private reconnectListRevision : number | null = null ;
9797 private gatewaySource : ApplicationContext < RouteId > [ "gateway" ] | null = null ;
98+ private gatewayConnectionRevision = 0 ;
9899 private gatewayClient : GatewayBrowserClient | null = null ;
99100 private gatewayConnected = false ;
100101 // Bind mutation completions to one epoch so stale failures cannot cross reconnects.
@@ -422,19 +423,18 @@ export class SessionDataController implements ReactiveController, SessionCatalog
422423 return ;
423424 }
424425 const gateway = this . context ?. gateway ;
425- const sameClientDisconnected =
426+ const sameGatewayDisconnected =
426427 gateway !== undefined &&
427428 gateway === this . gatewaySource &&
428429 gateway . snapshot . client !== null &&
429- gateway . snapshot . client === this . gatewayClient &&
430430 gateway . snapshot . phase !== "connected" ;
431- if ( sameClientDisconnected && this . reconnectListRevision === null ) {
431+ if ( sameGatewayDisconnected && this . reconnectListRevision === null ) {
432432 this . reconnectListRevision = sessions . canonicalListRevision + 1 ;
433433 }
434434 const waitingForReconnectList =
435435 this . reconnectListRevision !== null &&
436436 sessions . canonicalListRevision < this . reconnectListRevision ;
437- if ( ! sameClientDisconnected && ! waitingForReconnectList ) {
437+ if ( ! sameGatewayDisconnected && ! waitingForReconnectList ) {
438438 // Keep the result and agent scope paired until the first canonical list
439439 // after reconnect; chat startup may publish a partial reconciliation first.
440440 this . reconnectListRevision = null ;
@@ -465,9 +465,12 @@ export class SessionDataController implements ReactiveController, SessionCatalog
465465 private synchronizeGateway ( gateway : ApplicationContext < RouteId > [ "gateway" ] ) : void {
466466 const client = gateway . snapshot . client ;
467467 const connected = gateway . snapshot . phase === "connected" ;
468+ const sessionSourceChanged =
469+ gateway !== this . gatewaySource ||
470+ gateway . connectionRevision !== this . gatewayConnectionRevision ;
468471 const clientChanged = client !== this . gatewayClient ;
469472 const connectedStarted = connected && ! this . gatewayConnected ;
470- const sourceOrClientChanged = gateway !== this . gatewaySource || client !== this . gatewayClient ;
473+ const sourceOrClientChanged = sessionSourceChanged || clientChanged ;
471474 const connectionChanged = connected !== this . gatewayConnected ;
472475 // Presence and auth snapshots must not retire this client's in-flight
473476 // native or catalog pages unless its connection phase actually changes.
@@ -476,6 +479,7 @@ export class SessionDataController implements ReactiveController, SessionCatalog
476479 }
477480 this . invalidateSessionMutations ( ) ;
478481 this . gatewaySource = gateway ;
482+ this . gatewayConnectionRevision = gateway . connectionRevision ;
479483 this . gatewayClient = client ;
480484 this . gatewayConnected = connected ;
481485 this . presenceInstanceId = client ?. instanceId ;
@@ -493,7 +497,10 @@ export class SessionDataController implements ReactiveController, SessionCatalog
493497 }
494498 return ;
495499 }
496- this . clearSessionCache ( ) ;
500+ // Session rows belong to the logical Gateway, not one replaceable socket client.
501+ if ( sessionSourceChanged ) {
502+ this . clearSessionCache ( ) ;
503+ }
497504 this . resetSessionCatalogConnection ( ) ;
498505 if ( connected && this . sessionsSource && this . host . sidebarSessionStatusFilter ( ) !== "active" ) {
499506 void this . refreshSidebarSessions ( ) ;
0 commit comments