@@ -21,6 +21,35 @@ function sessionCatalogSnapshot(catalogs: readonly SessionCatalog[]): string {
2121 return JSON . stringify ( catalogs ) ;
2222}
2323
24+ function sessionCatalogMaterialSnapshot ( catalogs : readonly SessionCatalog [ ] ) : string {
25+ // Fast follow-up polls cover catalog/host/session identity sets, labels, connectivity,
26+ // and session title/status. Ordering and recency timestamps cannot pin the 5s cadence.
27+ return JSON . stringify (
28+ catalogs
29+ . map ( ( catalog ) => ( {
30+ id : catalog . id ,
31+ label : catalog . label ,
32+ hosts : catalog . hosts
33+ . map ( ( host ) => ( {
34+ hostId : host . hostId ,
35+ label : host . label ,
36+ connected : host . connected ,
37+ errorCode : host . error ?. code ,
38+ sessions : host . sessions
39+ . map ( ( session ) => ( {
40+ threadId : session . threadId ,
41+ name : session . name ,
42+ status : session . status ,
43+ archived : session . archived ,
44+ } ) )
45+ . toSorted ( ( left , right ) => left . threadId . localeCompare ( right . threadId ) ) ,
46+ } ) )
47+ . toSorted ( ( left , right ) => left . hostId . localeCompare ( right . hostId ) ) ,
48+ } ) )
49+ . toSorted ( ( left , right ) => left . id . localeCompare ( right . id ) ) ,
50+ ) ;
51+ }
52+
2453export function sessionCatalogListClient (
2554 snapshot : ApplicationGatewaySnapshot | undefined ,
2655 connected : boolean ,
@@ -204,6 +233,10 @@ export class SessionCatalogLiveState {
204233 return this . refetchOwner !== null ;
205234 }
206235
236+ get hasRequested ( ) {
237+ return this . progressSequence > 0 ;
238+ }
239+
207240 beginRefetch ( active : boolean ) : symbol | null {
208241 if ( ! active ) {
209242 return null ;
@@ -259,11 +292,13 @@ export class SessionCatalogLiveState {
259292 markFinal ( params : {
260293 catalogs : readonly SessionCatalog [ ] ;
261294 hadCatalogs : boolean ;
262- previousSnapshot : string ;
295+ previousMaterialSnapshot : string ;
263296 progressSequence : number ;
264297 } ) {
265298 this . sawChange =
266- params . hadCatalogs && params . previousSnapshot !== sessionCatalogSnapshot ( params . catalogs ) ;
299+ params . hadCatalogs &&
300+ ( this . sawChange ||
301+ params . previousMaterialSnapshot !== sessionCatalogMaterialSnapshot ( params . catalogs ) ) ;
267302 const finalCatalogIds = new Set ( params . catalogs . map ( ( catalog ) => catalog . id ) ) ;
268303 for ( const [ catalogId , previousHostIds ] of this . hostIdsByCatalog ) {
269304 if ( finalCatalogIds . has ( catalogId ) ) {
@@ -338,7 +373,7 @@ export class SessionCatalogLiveState {
338373 agentId : string ;
339374 catalogs : SessionCatalog [ ] ;
340375 pageDepths : ReadonlyMap < string , number > ;
341- } ) : { catalogs : SessionCatalog [ ] ; catalogId : string } | null {
376+ } ) : { catalogs : SessionCatalog [ ] ; catalogId : string ; materialChange : boolean } | null {
342377 if ( ! isSessionsCatalogHostEvent ( params . payload ) ) {
343378 return null ;
344379 }
@@ -386,8 +421,10 @@ export class SessionCatalogLiveState {
386421 if ( sessionCatalogSnapshot ( catalogs ) === sessionCatalogSnapshot ( params . catalogs ) ) {
387422 return null ;
388423 }
389- this . sawChange = true ;
390- return { catalogs, catalogId : event . catalog . id } ;
424+ const materialChange =
425+ sessionCatalogMaterialSnapshot ( catalogs ) !== sessionCatalogMaterialSnapshot ( params . catalogs ) ;
426+ this . sawChange ||= materialChange ;
427+ return { catalogs, catalogId : event . catalog . id , materialChange } ;
391428 }
392429
393430 schedule ( delayMs : number , isConnected : boolean , refresh : ( ) => void ) {
@@ -434,8 +471,8 @@ export class SessionCatalogLiveState {
434471 if ( this . activationTimer !== null ) {
435472 return ;
436473 }
437- // Browsers fire visibilitychange and focus as one foregrounding pair .
438- // The short window prevents that pair from triggering two fleet scans .
474+ // Presence, host updates, visibilitychange, and focus arrive in activation bursts .
475+ // One short window keeps the burst to a single fleet scan .
439476 this . activationTimer = globalThis . setTimeout ( ( ) => {
440477 this . activationTimer = null ;
441478 refresh ( ) ;
@@ -466,7 +503,7 @@ export async function refreshSessionCatalogsLive(params: {
466503 }
467504 const { progressId, progressSequence, requestOwner } = live . beginRequest ( generation ) ;
468505 const hadCatalogs = params . catalogs ( ) . length > 0 ;
469- const previousSnapshot = sessionCatalogSnapshot ( params . catalogs ( ) ) ;
506+ const previousMaterialSnapshot = sessionCatalogMaterialSnapshot ( params . catalogs ( ) ) ;
470507 let refetchOwner : symbol | null = null ;
471508 const requestIsCurrent = ( ) =>
472509 live . ownsRequest ( requestOwner ) &&
@@ -496,7 +533,7 @@ export async function refreshSessionCatalogsLive(params: {
496533 ...catalogs . map ( ( catalog ) => catalog . id ) ,
497534 ] ) ;
498535 params . applyFinal ( catalogs , revisedCatalogIds ) ;
499- live . markFinal ( { catalogs, hadCatalogs, previousSnapshot , progressSequence } ) ;
536+ live . markFinal ( { catalogs, hadCatalogs, previousMaterialSnapshot , progressSequence } ) ;
500537 } catch ( error ) {
501538 // A transient poll failure must not collapse already visible or expanded pages.
502539 if ( revisionIsCurrent ( ) ) {
0 commit comments