fix(background-activity): reconcile shells for directories subscribed by the stream

The background activity indicator went stale for sessions living in a
directory that is not a registered repo. Running shells were only synced
for repo directories derived from the repos query, so session directories
subscribed over the event stream were never reconciled, leaving the
indicator visible after the shell had exited.

Report the directories actually subscribed (mid-connection updates and
pending directories flushed after connect) from the event stream through
onDirectoriesSubscribed, and reconcile running shells and pending
permissions/forms for them in the event context.
This commit is contained in:
Chris Scott committed 2026-10-15 13:00:08 +00:00
1 parent 59ffe6c586
commit 37b4ab89f0
5 files changed
+232 -29

No files matched your search

@@ -15,9 +15,19 @@ interface Subscriber {
onStatusChange?: EventStreamStatusHandler
onHealthChange?: (state: EventStreamHealthState) => void
onResync?: () => void
onDirectoriesSubscribed?: (directories: string[]) => void
directories: Set<string>
}
interface SubscriberInput {
onEvent: OpenCodeEventHandler
onStatusChange?: EventStreamStatusHandler
onHealthChange?: (state: EventStreamHealthState) => void
directories: string[]
onResync?: () => void
onDirectoriesSubscribed?: (directories: string[]) => void
}
interface OpenCodeEventStreamOptions {
transport?: EventStreamTransport
}
@@ -45,14 +55,8 @@ export class OpenCodeEventStream {
this.transport = options.transport ?? createBrowserEventStreamTransport()
}
subscribeGlobalMonitor(input: {
directories: string[]
onEvent: OpenCodeEventHandler
onStatusChange?: EventStreamStatusHandler
onHealthChange?: (state: EventStreamHealthState) => void
onResync?: () => void
}): GlobalMonitorSubscription {
const id = this.addSubscriber(input.onEvent, input.onStatusChange, input.onHealthChange, input.directories, input.onResync)
subscribeGlobalMonitor(input: SubscriberInput): GlobalMonitorSubscription {
const id = this.addSubscriber(input)
return {
updateDirectories: (directories) => this.updateSubscriberDirectories(id, directories),
@@ -66,13 +70,8 @@ export class OpenCodeEventStream {
return this.buildHealth()
}
private addSubscriber(
onEvent: OpenCodeEventHandler,
onStatusChange?: EventStreamStatusHandler,
onHealthChange?: (state: EventStreamHealthState) => void,
directories: string[] = [],
onResync?: () => void,
): string {
private addSubscriber(input: SubscriberInput): string {
const { onEvent, onStatusChange, onHealthChange, directories, onResync, onDirectoriesSubscribed } = input
const id = `sub_${++this.subscriberIdCounter}`
const initialDirectories = new Set(directories.filter(Boolean))
@@ -96,6 +95,7 @@ export class OpenCodeEventStream {
onStatusChange,
onHealthChange,
onResync,
onDirectoriesSubscribed,
directories: initialDirectories,
})
@@ -430,7 +430,20 @@ export class OpenCodeEventStream {
if (!success) {
directories.forEach((directory) => this.pendingDirectories.add(directory))
this.reconnect()
return
}
this.notifyDirectoriesSubscribed(directories)
}
private notifyDirectoriesSubscribed(directories: string[]): void {
this.subscribers.forEach((subscriber) => {
try {
subscriber.onDirectoriesSubscribed?.(directories)
} catch {
void 0
}
})
}
private flushPendingDirectories(): void {