diff --git a/src/main/runtime/browser/client-pages/client-hosted-page-reconciliation-window.ts b/src/main/runtime/browser/client-pages/client-hosted-page-reconciliation-window.ts index c9a8cbe5ad7..ba2c3fac021 100644 --- a/src/main/runtime/browser/client-pages/client-hosted-page-reconciliation-window.ts +++ b/src/main/runtime/browser/client-pages/client-hosted-page-reconciliation-window.ts @@ -1,15 +1,15 @@ +import type { ClientHostedPageObservation } from '../../construction/runtime-identity-state' export const DEFAULT_CLIENT_HOSTED_RECONCILIATION_WINDOW_MS = 45_000 /** A client with no paired-device identity, which no host attach can ever speak for. */ const ANONYMOUS_CLIENT = '\0anonymous' const READ_REPLY = Symbol('read-reply') -type Observation = object | symbol /** Restart snapshots precede host inventories; hold browser-row culling until each client's host reconciles. * One client's attach proves nothing about another; bound never-attached clients by the deadline. */ export class ClientHostedPageReconciliationWindow { private readonly reconciledClients = new Set() - private readonly observations = new Map>>() + private readonly observations = new Map>>() constructor( private readonly openedAt: number, @@ -31,10 +31,11 @@ export class ClientHostedPageReconciliationWindow { observe( frames: readonly { worktree: string; clientHostedPagesUnreconciled?: true; removed?: true }[], pairedDeviceId?: string, - observer: Observation = READ_REPLY + observer: ClientHostedPageObservation = READ_REPLY ): void { const key = clientKey(pairedDeviceId) - const observations = this.observations.get(key) ?? new Map>() + const observations = + this.observations.get(key) ?? new Map>() const held = observations.get(observer) ?? new Set() for (const frame of frames) { if (frame.clientHostedPagesUnreconciled && !frame.removed) { @@ -55,7 +56,10 @@ export class ClientHostedPageReconciliationWindow { } } - forgetObservation(pairedDeviceId: string | undefined, observer: Observation): void { + forgetObservation( + pairedDeviceId: string | undefined, + observer: ClientHostedPageObservation + ): void { const key = clientKey(pairedDeviceId) const observations = this.observations.get(key) observations?.delete(observer) diff --git a/src/main/runtime/construction/runtime-identity-state.ts b/src/main/runtime/construction/runtime-identity-state.ts index 6356df12a90..ea4a9ce5aa7 100644 --- a/src/main/runtime/construction/runtime-identity-state.ts +++ b/src/main/runtime/construction/runtime-identity-state.ts @@ -71,6 +71,8 @@ import type { TerminalHandleAccess } from '../agent-senders/runtime-agent-sender import { RuntimeConstructionServices } from './runtime-construction-services' +export type ClientHostedPageObservation = MobileSessionTabSubscription | symbol + export type MobileSessionTabSubscription = { listener: ( snapshot: RuntimeMobileSessionTabsResult, diff --git a/src/main/runtime/rpc/methods/session-tabs/session-tabs-inventory.ts b/src/main/runtime/rpc/methods/session-tabs/session-tabs-inventory.ts index 4f42a76ec87..b095b026b07 100644 --- a/src/main/runtime/rpc/methods/session-tabs/session-tabs-inventory.ts +++ b/src/main/runtime/rpc/methods/session-tabs/session-tabs-inventory.ts @@ -28,7 +28,7 @@ export async function subscribeSessionTabsInventory( } const cleanupPrefix = `session.tabs:${connectionId ?? 'local'}:*` const subscriptionId = requestId ? `${cleanupPrefix}:${requestId}` : cleanupPrefix - const observation = {} + const observation = Symbol('session-tabs-stream') const inventoryController = new AbortController() // For the stream's whole life, not just the census: a desktop unsubscribe arrives as this abort. const onTransportAbort = (): void => runtime.cleanupSubscription(subscriptionId) diff --git a/src/main/runtime/rpc/methods/session-tabs/session-tabs.ts b/src/main/runtime/rpc/methods/session-tabs/session-tabs.ts index 4002380815b..8b036ab4cdb 100644 --- a/src/main/runtime/rpc/methods/session-tabs/session-tabs.ts +++ b/src/main/runtime/rpc/methods/session-tabs/session-tabs.ts @@ -131,7 +131,7 @@ export const SESSION_TAB_METHODS = [ }, emit ) => { - const observation = {} + const observation = Symbol('session-tabs-stream') let subscriptionId: string | null = null let released = false let endOnRelease = true diff --git a/src/main/runtime/session-tabs/mobile-session-tab-subscriptions.ts b/src/main/runtime/session-tabs/mobile-session-tab-subscriptions.ts index 22d253d6e71..44455726f30 100644 --- a/src/main/runtime/session-tabs/mobile-session-tab-subscriptions.ts +++ b/src/main/runtime/session-tabs/mobile-session-tab-subscriptions.ts @@ -1,4 +1,7 @@ -import type { MobileSessionTabSubscription } from '../construction/runtime-identity-state' +import type { + ClientHostedPageObservation, + MobileSessionTabSubscription +} from '../construction/runtime-identity-state' import type { RuntimeMobileSessionTabsResult } from '../../../shared/runtime-session-contracts' import { RuntimeWorkspaceFileTargets } from '../workspaces/workspace-file-session-targets' export abstract class RuntimeMobileSessionTabSubscriptions extends RuntimeWorkspaceFileTargets { @@ -55,14 +58,14 @@ export abstract class RuntimeMobileSessionTabSubscriptions extends RuntimeWorksp observeClientHostedPageSnapshots( frames: readonly RuntimeMobileSessionTabsResult[], clientNavigationId?: string, - observer?: object + observer?: ClientHostedPageObservation ): void { this.clientHostedPageReconciliation.observe(frames, clientNavigationId, observer) } forgetClientHostedPageObservation( clientNavigationId: string | undefined, - observer: object + observer: ClientHostedPageObservation ): void { this.clientHostedPageReconciliation.forgetObservation(clientNavigationId, observer) }