Skip to content

The agent that grows with you

fix(desktop): keep provider readiness on the profile REST setup writes

teknium1db20d39df580
diff --git a/apps/desktop/src/components/onboarding/index.tsx b/apps/desktop/src/components/onboarding/index.tsx
index 5008872b652..b53bcd83e0c 100644
--- a/apps/desktop/src/components/onboarding/index.tsx
+++ b/apps/desktop/src/components/onboarding/index.tsx
@@ -64,7 +64,7 @@ export {
} from './providers'
import { $gateway, activeGatewayConnectionId } from '@/store/gateway'
-import { requestOnboardingGateway } from '@/store/onboarding-scope'
+import { captureOnboardingScope, requestOnboardingGateway } from '@/store/onboarding-scope'
interface DesktopOnboardingOverlayProps {
enabled: boolean
@@ -215,7 +215,7 @@ export function DesktopOnboardingOverlay({
const connectionId = activeGatewayConnectionId()
const scope = useMemo(
- () => onboarding.targetScope ?? { connectionId, profile },
+ () => onboarding.targetScope ?? captureOnboardingScope({ connectionId, profile }),
[onboarding.targetScope, profile, connectionId]
)
diff --git a/apps/desktop/src/store/onboarding-owner.test.ts b/apps/desktop/src/store/onboarding-owner.test.ts
index 015f1501572..55e7bb15ae7 100644
--- a/apps/desktop/src/store/onboarding-owner.test.ts
+++ b/apps/desktop/src/store/onboarding-owner.test.ts
@@ -1,6 +1,7 @@
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
import { setApiRequestConnection, setApiRequestProfile } from '@/api/client'
+import { setEnvVar } from '@/api/config'
import type { HermesApiRequest } from '@/global'
import { makeOAuthProvider } from '@/test/oauth-provider'
@@ -15,7 +16,14 @@ import {
startProviderOAuth,
submitOnboardingCode
} from './onboarding'
-import { captureOnboardingScope } from './onboarding-scope'
+import { captureOnboardingScope, requestOnboardingGateway } from './onboarding-scope'
+
+const gatewayMocks = vi.hoisted(() => ({ requestGatewayForAgent: vi.fn(async () => ({ ok: true })) }))
+
+vi.mock('@/store/gateway', async importOriginal => ({
+ ...(await importOriginal<Record<string, unknown>>()),
+ requestGatewayForAgent: gatewayMocks.requestGatewayForAgent
+}))
const owner = { connectionId: 'athena', profile: 'leverage-ai' }
const requests: HermesApiRequest[] = []
@@ -175,9 +183,36 @@ it('preserves explicit local and untagged legacy routes instead of filling ambie
connectionId: 'local',
profile: 'default'
})
- expect(captureOnboardingScope({ profile: 'legacy' })).toEqual({ profile: 'legacy' })
+ expect(captureOnboardingScope({ profile: 'legacy' })).toEqual({ connectionId: null, profile: 'legacy' })
setApiRequestConnection(null)
const legacy = captureOnboardingScope('legacy')
setApiRequestConnection('athena')
expect(legacy).toEqual({ connectionId: null, profile: 'legacy' })
})
+
+// A setup owner without a profile writes REST settings to the backend's launch
+// home (no ?profile=). Readiness on a shared backend must target that same home,
+// not a hard-coded `default` profile that may be a different one.
+it('keeps readiness on the same profile as REST writes when the owner has none', async () => {
+ const getConnectionFor = vi.fn(async () => ({ sharedRemote: true }))
+ Object.assign(window.hermesDesktop, { getConnection: vi.fn(), getConnectionFor })
+ setApiRequestProfile(null)
+ const scope = captureOnboardingScope()
+
+ expect(scope).toEqual({ connectionId: 'athena', profile: null })
+ expect(captureOnboardingScope({ connectionId: 'athena', profile: ' ' })).toEqual(scope)
+
+ await setEnvVar('OPENAI_API_KEY', 'fixture', scope)
+ expect(requests.at(-1)).toMatchObject({ connectionId: 'athena' })
+ expect(requests.at(-1)).not.toHaveProperty('profile')
+
+ await requestOnboardingGateway(scope, 'setup.runtime_check', { provider: 'custom' })
+ expect(gatewayMocks.requestGatewayForAgent).toHaveBeenLastCalledWith('athena', 'default', 'setup.runtime_check', {
+ provider: 'custom'
+ })
+
+ await requestOnboardingGateway(owner, 'setup.runtime_check', {})
+ expect(gatewayMocks.requestGatewayForAgent).toHaveBeenLastCalledWith('athena', 'leverage-ai', 'setup.runtime_check', {
+ profile: 'leverage-ai'
+ })
+})
diff --git a/apps/desktop/src/store/onboarding-scope.ts b/apps/desktop/src/store/onboarding-scope.ts
index f73dafa4ad1..7004c18d1f0 100644
--- a/apps/desktop/src/store/onboarding-scope.ts
+++ b/apps/desktop/src/store/onboarding-scope.ts
@@ -8,16 +8,16 @@ export interface OnboardingScope {
}
/** Capture both halves once. An absent connection keeps legacy per-profile
- * routing; it must not acquire a different ambient registry owner later. */
+ * routing; it must not acquire a different ambient registry owner later.
+ * A blank profile is normalized to null: REST writes then carry no profile
+ * (the backend's launch home), and readiness must omit it the same way. */
export function captureOnboardingScope(scope?: ProfileScope): OnboardingScope {
- if (scope && typeof scope === 'object') {
- return { ...scope }
- }
+ const captured =
+ scope && typeof scope === 'object'
+ ? scope
+ : { connectionId: getApiRequestConnection(), profile: scope === undefined ? getApiRequestProfile() : scope }
- return {
- connectionId: getApiRequestConnection(),
- profile: scope === undefined ? getApiRequestProfile() : scope
- }
+ return { connectionId: captured.connectionId ?? null, profile: captured.profile?.trim() || null }
}
/** Desktop profile keys can be SSH aliases. Only shared descriptors interpret
@@ -27,6 +27,7 @@ export async function requestOnboardingGateway<T>(
method: string,
params: Record<string, unknown> = {}
): Promise<T> {
+ // `default` is only the Desktop routing key for the launch home here.
const profile = scope.profile || 'default'
const desktop = window.hermesDesktop
@@ -46,8 +47,8 @@ export async function requestOnboardingGateway<T>(
delete routedParams.profile
- if (connection.sharedPrimary || connection.sharedRemote) {
- routedParams.profile = profile
+ if (scope.profile && (connection.sharedPrimary || connection.sharedRemote)) {
+ routedParams.profile = scope.profile
}
return requestGatewayForAgent<T>(scope.connectionId ?? null, profile, method, routedParams)