From 9c32ba2038dcd2ae3e588fd0d54fd0340ed99441 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Fri, 9 Oct 2026 11:43:48 -0400 Subject: [PATCH] fix(models): reload the model catalog on reconnect and broadcast its events Model pickers without a location, such as the goal auditor and walkthrough model settings, could stay stuck on an empty model list. OpenCode's model and provider catalog events were only delivered to clients subscribed to the originating directory, and the provider catalog was not reloaded on a browser stream reconnect or upstream resync, so a list cached empty while OpenCode was loading or restarting never refreshed. Route model.updated, provider.updated and integration.updated through the resolved-event broadcast like the command, agent and skill catalogs, and reload the provider catalog on reconnect and resync alongside them. --- backend/src/services/sse-aggregator.ts | 2 +- backend/test/services/sse-aggregator.test.ts | 2 +- frontend/src/contexts/EventContext.test.tsx | 2 ++ frontend/src/contexts/EventContext.tsx | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/src/services/sse-aggregator.ts b/backend/src/services/sse-aggregator.ts index 2aa2d9aa..00f733a1 100644 --- a/backend/src/services/sse-aggregator.ts +++ b/backend/src/services/sse-aggregator.ts @@ -34,7 +34,7 @@ type ReplayEventType = 'permission.asked' | 'form.created' | 'session.status' const { RECONNECT_DELAY_MS, MAX_RECONNECT_DELAY_MS } = DEFAULTS.SSE const MULTILINE_PATTERN = /[\r\n]/ -const LOCATION_CATALOG_EVENT_TYPES = new Set(['command.updated', 'agent.updated', 'skill.updated']) +const LOCATION_CATALOG_EVENT_TYPES = new Set(['command.updated', 'agent.updated', 'skill.updated', 'model.updated', 'provider.updated', 'integration.updated']) function serializeEnvelope(directory: string | null, payloadJson: string): string { return '{"directory":' + JSON.stringify(directory) + ',"payload":' + payloadJson + '}' diff --git a/backend/test/services/sse-aggregator.test.ts b/backend/test/services/sse-aggregator.test.ts index f4545f41..dfbf1c06 100644 --- a/backend/test/services/sse-aggregator.test.ts +++ b/backend/test/services/sse-aggregator.test.ts @@ -805,7 +805,7 @@ describe('SSEAggregator location-scoped catalog event broadcast', () => { sseAggregator.setScheduledSessionsResolver(() => []) }) - it.each(['command.updated', 'agent.updated', 'skill.updated'])( + it.each(['command.updated', 'agent.updated', 'skill.updated', 'model.updated', 'provider.updated', 'integration.updated'])( 'broadcasts a location-scoped %s catalog event to every client without leaking other location-scoped events', (type) => { const subscribed = createCapturingClient() diff --git a/frontend/src/contexts/EventContext.test.tsx b/frontend/src/contexts/EventContext.test.tsx index 31218351..3ebf199d 100644 --- a/frontend/src/contexts/EventContext.test.tsx +++ b/frontend/src/contexts/EventContext.test.tsx @@ -856,6 +856,7 @@ describe('EventProvider permissions and forms', () => { expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'commands'] }) expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'agents'] }) expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'skills'] }) + expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'providers'] }) }) }) @@ -880,6 +881,7 @@ describe('EventProvider permissions and forms', () => { expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'commands'] }) expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'agents'] }) expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'skills'] }) + expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'providers'] }) }) }) diff --git a/frontend/src/contexts/EventContext.tsx b/frontend/src/contexts/EventContext.tsx index cd8fd19c..ad23bbc3 100644 --- a/frontend/src/contexts/EventContext.tsx +++ b/frontend/src/contexts/EventContext.tsx @@ -33,6 +33,7 @@ const LOCATION_CATALOG_QUERY_KEYS = [ ['opencode', 'commands'], ['opencode', 'agents'], ['opencode', 'skills'], + ['opencode', 'providers'], ] as const type PermissionsBySession = Record