Type reconciliation observations by their actual owners

This commit is contained in:
Brennan Benson
2026-11-12 01:45:33 -08:00
parent 001c6a84ba
commit f69c719a0b
5 changed files with 19 additions and 10 deletions
@@ -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<string>()
private readonly observations = new Map<string, Map<Observation, Set<string>>>()
private readonly observations = new Map<string, Map<ClientHostedPageObservation, Set<string>>>()
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<Observation, Set<string>>()
const observations =
this.observations.get(key) ?? new Map<ClientHostedPageObservation, Set<string>>()
const held = observations.get(observer) ?? new Set<string>()
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)
@@ -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,
@@ -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)
@@ -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
@@ -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)
}