The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(webapp): re-read the inventory before refusing a dial to an uncached profile
unsupportedpastels5a57936c53fa
diff --git a/apps/desktop/src/lib/browser-connection.ts b/apps/desktop/src/lib/browser-connection.tsindex 99b111f3ef1..e41c6befd83 100644--- a/apps/desktop/src/lib/browser-connection.ts+++ b/apps/desktop/src/lib/browser-connection.ts@@ -105,7 +105,29 @@ export function createBrowserConnectionBridge({ api, bootstrap }: BrowserConnect// The gateway's own profile, or another one it serves: the only profiles this tab's socket reaches.const reachesSocket = (profile?: null | string) => !ridesWithProfile(profile) || served.serves(profile)+ const getProfiles = async () => {+ const result = await api<{ profiles?: { name?: string }[] }>({ path: '/api/profiles' })++ return [...new Set((result.profiles || []).map(profile => String(profile.name || '').trim()).filter(Boolean))]+ }++ // Every installed profile, with the served set brought up to date for that list.+ const installedProfiles = async () => {+ const profiles = await getProfiles()+ await served.refresh(profiles)++ return profiles+ }+const getGatewayWsUrl = async (profile?: null | string) => {+ // A profile created since the last inventory read is missing from the cached set, though the+ // multiplexer adopted it before its create returned: read the inventory once before refusing.+ // An unchanged list within the set's TTL re-reads only `/api/profiles`; a failed read refuses on+ // the set already cached, as before.+ if (!reachesSocket(profile)) {+ await installedProfiles().catch(() => undefined)+ }+// Its ticket would mint, then the gateway would close the dial (4403) without a reason to show.if (!reachesSocket(profile)) {throw new UnservedProfileError((profile ?? '').trim())@@ -129,20 +151,6 @@ export function createBrowserConnectionBridge({ api, bootstrap }: BrowserConnect}}- const getProfiles = async () => {- const result = await api<{ profiles?: { name?: string }[] }>({ path: '/api/profiles' })-- return [...new Set((result.profiles || []).map(profile => String(profile.name || '').trim()).filter(Boolean))]- }-- // Every installed profile, with the served set brought up to date for that list.- const installedProfiles = async () => {- const profiles = await getProfiles()- await served.refresh(profiles)-- return profiles- }-return {getAgentRoster: async () => {const profiles = await installedProfiles()diff --git a/apps/desktop/src/lib/browser-desktop-bridge-served-profiles.test.ts b/apps/desktop/src/lib/browser-desktop-bridge-served-profiles.test.tsindex a08d41c2789..22653d88ad9 100644--- a/apps/desktop/src/lib/browser-desktop-bridge-served-profiles.test.ts+++ b/apps/desktop/src/lib/browser-desktop-bridge-served-profiles.test.ts@@ -140,6 +140,28 @@ describe('profiles the serving gateway does not serve', () => {await expect(desktop.getGatewayWsUrl('research')).resolves.toMatchObject({ ok: true })expect(callsTo(fetchMock, '/api/webapp/socket-ticket')).toBe(2)})++ it('opens a profile created since the last inventory read, and still refuses one that stays unserved', async () => {+ const gateway: Gateway = { profiles: ['default', 'solo'], status: reports(['default']) }+ const fetchMock = stubGateway(gateway)+ const desktop = installServedBridge()+ const statusReads = () => callsTo(fetchMock, '/api/status')+ await desktop.getProfileRoutes?.(['solo'])+ expect(statusReads()).toBe(1)++ // A picker creates the profile and selects it before any inventory read: the multiplexer+ // already serves it, but the cached set predates it.+ gateway.profiles = [...gateway.profiles, 'fresh']+ gateway.status = reports(['default', 'fresh'])+ await expect(desktop.getGatewayWsUrl('fresh')).resolves.toMatchObject({ ok: true })+ expect(statusReads()).toBe(2)++ // The installed list is unchanged since that read, so a refusal costs no further status read.+ await expect(desktop.getGatewayWsUrl('solo')).rejects.toThrow('does not serve profile "solo"')+ await expect(desktop.getGatewayWsUrl('solo')).rejects.toThrow('does not serve profile "solo"')+ expect(statusReads()).toBe(2)+ expect(callsTo(fetchMock, '/api/webapp/socket-ticket')).toBe(1)+ })})describe('the served set read', () => {