The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): prioritize scoped settings backend dials
KoNit-Kd6ff2777b74d
diff --git a/apps/desktop/electron/backend-dial-claim.test.ts b/apps/desktop/electron/backend-dial-claim.test.tsindex 30c7e8195c3..82694624abd 100644--- a/apps/desktop/electron/backend-dial-claim.test.ts+++ b/apps/desktop/electron/backend-dial-claim.test.ts@@ -135,7 +135,7 @@ describe('main.ts wiring for #90812', () => {it('routes the registry-scoped dial IPC through the claim keyed by backendScopeKey(connectionId, profile)', () => {const handlerStart = mainSource.indexOf("ipcMain.handle('hermes:connection:for', ")expect(handlerStart).toBeGreaterThan(-1)- const body = mainSource.slice(handlerStart, handlerStart + 1_200)+ const body = mainSource.slice(handlerStart, handlerStart + 1_600)expect(body).toContain('const scopeKey = backendScopeKey(id, profile)')expect(body).toContain('backendDialClaims.run(scopeKey, ')@@ -162,7 +162,7 @@ describe('main.ts wiring for #90812', () => {it('routes a terminal-pane backend resolve through the single-owner claim on both the registry and local branches', () => {const handlerStart = mainSource.indexOf('async function ensureTerminalBackend(webContentsId: number) {')expect(handlerStart).toBeGreaterThan(-1)- const body = mainSource.slice(handlerStart, handlerStart + 900)+ const body = mainSource.slice(handlerStart, handlerStart + 1_200)expect(body).toContain('backendDialClaims.run(backendScopeKey(windowRoute.connectionId, windowRoute.profile)')expect(body).toContain('ensureRegistryBackend(windowRoute.connectionId, windowRoute.profile)')@@ -195,9 +195,21 @@ describe('main.ts wiring for #90812', () => {it('routes every registry-scoped REST dispatch (hermes:api) through the single-owner claim', () => {const handlerStart = mainSource.indexOf('async function dispatchRegistryApiRequest(')expect(handlerStart).toBeGreaterThan(-1)- const body = mainSource.slice(handlerStart, handlerStart + 900)+ const body = mainSource.slice(handlerStart, handlerStart + 1_600)expect(body).toContain('backendDialClaims.run(backendScopeKey(registryConnectionId, routeProfile)')- expect(body).toContain('ensureRegistryBackend(registryConnectionId, routeProfile)')+ expect(body).toContain("ensureRegistryBackend(registryConnectionId, routeProfile, '', { spawnPriority })")+ })++ it('forwards foreground API intent through both local and registry backend resolution', () => {+ const registryStart = mainSource.indexOf('async function dispatchRegistryApiRequest(')+ const registryBody = mainSource.slice(registryStart, registryStart + 1_300)+ const apiStart = mainSource.indexOf('async function handleHermesApiRequest(request)')+ const apiBody = mainSource.slice(apiStart, apiStart + 3_500)++ expect(registryBody).toContain('const spawnPriority = spawnPriorityFrom(request?.priority)')+ expect(registryBody).toContain("ensureRegistryBackend(registryConnectionId, routeProfile, '', { spawnPriority })")+ expect(apiBody).toContain('const spawnPriority = spawnPriorityFrom(request?.priority)')+ expect(apiBody).toContain('ensureBackend(routeProfile, { passive: request?.passive, spawnPriority })')})})diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 28a7f367319..737fa37e504 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -16622,10 +16622,11 @@ async function dispatchRegistryApiRequest(// SSH tunnel / remote dashboard. A passive read never dials, so it stays// OUT of the claim: an interactive open coalescing onto an in-flight// passive read would otherwise inherit its "no warm backend" rejection.+ const spawnPriority = spawnPriorityFrom(request?.priority)const connection: any = request?.passive? await ensureRegistryBackend(registryConnectionId, routeProfile, '', { passive: true }): await backendDialClaims.run(backendScopeKey(registryConnectionId, routeProfile), () =>- ensureRegistryBackend(registryConnectionId, routeProfile)+ ensureRegistryBackend(registryConnectionId, routeProfile, '', { spawnPriority }))const requestPath = pathForRegistryBackendRequest(request.path, requestProfile, connection)@@ -16690,6 +16691,7 @@ async function handleHermesApiRequest(request) {const tornDownProfile = await prepareProfileDeleteRequest(request)const profile = request?.profile+ const spawnPriority = spawnPriorityFrom(request?.priority)// After tearing down a backend for profile deletion, route to the primary// backend instead of spawning a fresh pool backend. A freshly spawned// backend calls ensure_hermes_home() which recreates the profile directory,@@ -16711,7 +16713,7 @@ async function handleHermesApiRequest(request) {let responsetry {- const connection = await ensureBackend(routeProfile, { passive: request?.passive })+ const connection = await ensureBackend(routeProfile, { passive: request?.passive, spawnPriority })const timeoutMs = resolveTimeoutMs(request?.timeoutMs, DEFAULT_FETCH_TIMEOUT_MS)response = await fetchJsonForBackend(connection, apiRoute.requestPath, {diff --git a/apps/desktop/src/api/config.ts b/apps/desktop/src/api/config.tsindex 3de227d1b8f..e4d30979c97 100644--- a/apps/desktop/src/api/config.ts+++ b/apps/desktop/src/api/config.ts@@ -16,6 +16,13 @@ import type {import { capabilityScoped, hermesApi, type ProfileScope, profileScoped, STARTUP_REQUEST_TIMEOUT_MS } from './client'+// Settings' explicit "Applies to" selection is a visible user action. Only+// tag concrete profile scopes: ambient reads remain background so hydration+// and unrelated config consumers cannot consume foreground pool capacity.+function settingsScopePriority(profile?: ProfileScope): { priority?: 'foreground' } {+ return profile == null ? {} : { priority: 'foreground' }+}+export function getStatus(): Promise<StatusResponse> {return hermesApi<StatusResponse>({...profileScoped(),@@ -74,6 +81,7 @@ export function getHermesConfigRecord(): Promise<HermesConfigRecord> {return window.hermesDesktop.api<HermesConfigRecord>({...capabilityScoped(profile),+ ...settingsScopePriority(profile),path: includeDefaults ? '/api/config' : '/api/config?include_defaults=false'})}@@ -89,6 +97,7 @@ export function getHermesConfigDefaults(): Promise<HermesConfigRecord> {export function getHermesConfigSchema(profile?: null | string): Promise<ConfigSchemaResponse> {return hermesApi<ConfigSchemaResponse>({...profileScoped(profile),+ ...(profile == null ? {} : { priority: 'foreground' as const }),path: '/api/config/schema'})}@@ -100,6 +109,7 @@ export function saveHermesConfig(): Promise<{ ok: boolean }> {return hermesApi<{ ok: boolean }>({...profileScoped(profile),+ ...(profile == null ? {} : { priority: 'foreground' as const }),path: preserveLanguage ? '/api/config?preserve_language=true' : '/api/config',method: 'PUT',body: { config }@@ -112,6 +122,7 @@ export function saveHermesConfig(export function saveHermesConfigRecord(config: HermesConfigRecord, profile?: ProfileScope): Promise<{ ok: boolean }> {return window.hermesDesktop.api<{ ok: boolean }>({...capabilityScoped(profile),+ ...settingsScopePriority(profile),path: '/api/config',method: 'PUT',body: { config }@@ -121,6 +132,7 @@ export function saveHermesConfigRecord(config: HermesConfigRecord, profile?: Proexport function getEnvVars(profile?: null | string): Promise<Record<string, EnvVarInfo>> {return hermesApi<Record<string, EnvVarInfo>>({...profileScoped(profile),+ ...(profile == null ? {} : { priority: 'foreground' as const }),path: '/api/env'})}@@ -128,6 +140,7 @@ export function getEnvVars(profile?: null | string): Promise<Record<string, EnvVexport function setEnvVar(key: string, value: string, profile?: ProfileScope): Promise<{ ok: boolean }> {return window.hermesDesktop.api<{ ok: boolean }>({...capabilityScoped(profile),+ ...settingsScopePriority(profile),path: '/api/env',method: 'PUT',body: { key, value }@@ -137,6 +150,7 @@ export function setEnvVar(key: string, value: string, profile?: ProfileScope): Pexport function deleteEnvVar(key: string, profile?: ProfileScope): Promise<{ ok: boolean }> {return window.hermesDesktop.api<{ ok: boolean }>({...capabilityScoped(profile),+ ...settingsScopePriority(profile),path: '/api/env',method: 'DELETE',body: { key }@@ -146,6 +160,7 @@ export function deleteEnvVar(key: string, profile?: ProfileScope): Promise<{ ok:export function revealEnvVar(key: string, profile?: ProfileScope): Promise<{ key: string; value: string }> {return window.hermesDesktop.api<{ key: string; value: string }>({...capabilityScoped(profile),+ ...settingsScopePriority(profile),path: '/api/env/reveal',method: 'POST',body: { key }@@ -208,6 +223,7 @@ export function deleteCustomEndpoint(id: string): Promise<CustomEndpointsResponsexport function listOAuthProviders(profile?: null | string): Promise<OAuthProvidersResponse> {return hermesApi<OAuthProvidersResponse>({...profileScoped(profile),+ ...(profile == null ? {} : { priority: 'foreground' as const }),path: '/api/providers/oauth'})}@@ -218,6 +234,7 @@ export function disconnectOAuthProvider(): Promise<{ ok: boolean; provider: string }> {return hermesApi<{ ok: boolean; provider: string }>({...profileScoped(profile),+ ...(profile == null ? {} : { priority: 'foreground' as const }),path: `/api/providers/oauth/${encodeURIComponent(providerId)}`,method: 'DELETE'})@@ -226,6 +243,7 @@ export function disconnectOAuthProvider(export function startOAuthLogin(providerId: string, profile?: ProfileScope): Promise<OAuthStartResponse> {return window.hermesDesktop.api<OAuthStartResponse>({...capabilityScoped(profile),+ ...settingsScopePriority(profile),path: `/api/providers/oauth/${encodeURIComponent(providerId)}/start`,method: 'POST',body: {}@@ -240,6 +258,7 @@ export function submitOAuthCode(): Promise<OAuthSubmitResponse> {return hermesApi<OAuthSubmitResponse>({...profileScoped(profile),+ ...(profile == null ? {} : { priority: 'foreground' as const }),path: `/api/providers/oauth/${encodeURIComponent(providerId)}/submit`,method: 'POST',body: { session_id: sessionId, code }@@ -253,6 +272,7 @@ export function pollOAuthSession(): Promise<OAuthPollResponse> {return window.hermesDesktop.api<OAuthPollResponse>({...capabilityScoped(profile),+ ...settingsScopePriority(profile),path: `/api/providers/oauth/${encodeURIComponent(providerId)}/poll/${encodeURIComponent(sessionId)}`})}@@ -260,6 +280,7 @@ export function pollOAuthSession(export function cancelOAuthSession(sessionId: string, profile?: null | string): Promise<{ ok: boolean }> {return hermesApi<{ ok: boolean }>({...profileScoped(profile),+ ...(profile == null ? {} : { priority: 'foreground' as const }),path: `/api/providers/oauth/sessions/${encodeURIComponent(sessionId)}`,method: 'DELETE'})diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.tsindex bc55bd91088..6a2e0d04c30 100644--- a/apps/desktop/src/global.d.ts+++ b/apps/desktop/src/global.d.ts@@ -1299,6 +1299,10 @@ export interface HermesApiRequest {// fails fast without spawning a child or consuming a pool slot, so background// tile reconciles cannot starve interactive opens.passive?: boolean+ // An interactive Settings scope selection may cold-start a profile backend.+ // Keep that intent separate from passive hydration so the pool can reserve a+ // slot for the user's visible request.+ priority?: 'foreground'}export interface HermesPreviewTarget {diff --git a/apps/desktop/src/hermes-capability-scope.test.ts b/apps/desktop/src/hermes-capability-scope.test.tsindex b50e8236a81..e0a3718fc82 100644--- a/apps/desktop/src/hermes-capability-scope.test.ts+++ b/apps/desktop/src/hermes-capability-scope.test.ts@@ -38,7 +38,7 @@ describe('capability helpers are connection-scoped', () => {delete (window as { hermesDesktop?: unknown }).hermesDesktop})- const last = () => api.mock.calls.at(-1)?.[0] as { connectionId?: string; profile?: string }+ const last = () => api.mock.calls.at(-1)?.[0] as { connectionId?: string; profile?: string; priority?: string }it('omits both scopes when none are active (single-source users unaffected)', () => {void getSkills()@@ -74,6 +74,18 @@ describe('capability helpers are connection-scoped', () => {expect(last().connectionId).toBe('gw-tailscale')})+ it('marks an explicitly scoped Settings config read as foreground', () => {+ getHermesConfigRecord('coder')++ expect(last()).toMatchObject({ profile: 'coder', priority: 'foreground' })+ })++ it('keeps ambient config reads unprioritized for background hydration', () => {+ getHermesConfigRecord()++ expect(last()).not.toHaveProperty('priority')+ })+it('object scopes pin every read and write to the named connection', () => {void getSkills({ connectionId: 'homelab', profile: 'inbox-bot' })void getToolsets({ connectionId: 'homelab', profile: 'inbox-bot' })