The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): scope Settings requests to the profile the page displays
Adam King5245b58763b1
diff --git a/apps/desktop/src/app/messaging/index.test.tsx b/apps/desktop/src/app/messaging/index.test.tsxindex d60fed80fd5..90caac9a1db 100644--- a/apps/desktop/src/app/messaging/index.test.tsx+++ b/apps/desktop/src/app/messaging/index.test.tsx@@ -116,7 +116,7 @@ async function renderMessaging() {}describe('MessagingView profile scope', () => {- it('follows the active profile instead of targeting primary when there is no override', async () => {+ it('names the active profile explicitly instead of sending an unscoped request', async () => {const { $settingsScopeOverride } = await import('@/store/settings-scope')$settingsScopeOverride.set(null)@@ -124,8 +124,11 @@ describe('MessagingView profile scope', () => {await renderMessaging()- await waitFor(() => expect(getMessagingPlatforms).toHaveBeenCalledWith(undefined))- expect(getPairing).toHaveBeenCalledWith(undefined)+ // #118432: the backend resolves an omitted profile against the home it was+ // LAUNCHED under, so "follow the active profile" has to be said out loud+ // rather than left to the ambient fallback.+ await waitFor(() => expect(getMessagingPlatforms).toHaveBeenCalledWith('default'))+ expect(getPairing).toHaveBeenCalledWith('default')})})@@ -182,7 +185,7 @@ describe('MessagingView pairing', () => {fireEvent.click(approve)})- await waitFor(() => expect(approvePairing).toHaveBeenCalledWith('teams', 'a1b2c3d4e5f60718', undefined))+ await waitFor(() => expect(approvePairing).toHaveBeenCalledWith('teams', 'a1b2c3d4e5f60718', 'default'))})it('restores the pending row when approval fails', async () => {diff --git a/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx b/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsxindex 11c86cb5acd..f93c63b51be 100644--- a/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx+++ b/apps/desktop/src/app/settings/custom-endpoints-settings.test.tsx@@ -107,7 +107,7 @@ describe('CustomEndpointsSettings', () => {expect(validateCustomEndpoint).toHaveBeenCalledWith(expect.objectContaining({ api_mode: 'codex_responses' }),- undefined+ 'default')expect(notify).toHaveBeenCalledWith({kind: 'success',@@ -122,7 +122,7 @@ describe('CustomEndpointsSettings', () => {]),models: ['gpt-5.6-sol', 'gpt-5.6-sol-high']}),- undefined+ 'default')})diff --git a/apps/desktop/src/app/settings/keys-settings.test.tsx b/apps/desktop/src/app/settings/keys-settings.test.tsxindex 4d3f4b0dc96..0cc54dad45c 100644--- a/apps/desktop/src/app/settings/keys-settings.test.tsx+++ b/apps/desktop/src/app/settings/keys-settings.test.tsx@@ -54,13 +54,16 @@ function DeepLinkButton({ target }: { target: string }) {}describe('KeysSettings', () => {- it('fetches env vars for the active profile (undefined, never null) when unscoped', async () => {+ it('fetches env vars for the displayed profile (the concrete key, never null) when unscoped', async () => {// #90549 class: getEnvVars(null) targets the primary profile's env store,// so a non-default profile's Keys page would read (and edit) the wrong- // profile. Unscoped must send undefined so the active profile applies.+ // profile. #118432: `undefined` is equally wrong — profileScoped() then+ // drops `?profile=` entirely and the backend falls back to the home it was+ // LAUNCHED under, which need not be the profile this page displays. Send+ // the concrete key the page names.await renderKeysSettings('tools')- await waitFor(() => expect(getEnvVars).toHaveBeenCalledWith(undefined))+ await waitFor(() => expect(getEnvVars).toHaveBeenCalledWith('default'))})it('lists tools and excludes settings / channel-managed credentials', async () => {diff --git a/apps/desktop/src/app/settings/providers-settings.test.tsx b/apps/desktop/src/app/settings/providers-settings.test.tsxindex f90e35d1097..12d30a190e6 100644--- a/apps/desktop/src/app/settings/providers-settings.test.tsx+++ b/apps/desktop/src/app/settings/providers-settings.test.tsx@@ -135,7 +135,9 @@ describe('ProvidersSettings', () => {fireEvent.click(screen.getByRole('button', { name: 'Save' }))await waitFor(() => expect(setEnvVar).toHaveBeenCalledWith('WIDGET_API_KEY', 'fixture-key', 'profile-b'))fireEvent.click(screen.getByRole('button', { name: 'profile-a' }))- await waitFor(() => expect(getEnvVars).toHaveBeenLastCalledWith(undefined))+ // Back onto the app's active profile: no override is stored, but the+ // request must still name it (#118432).+ await waitFor(() => expect(getEnvVars).toHaveBeenLastCalledWith('profile-a'))} finally {cleanup()$settingsScopeOverride.set(null)@@ -178,7 +180,7 @@ describe('ProvidersSettings', () => {fireEvent.click(screen.getByRole('button', { name: 'Disconnect' }))})- await waitFor(() => expect(disconnectOAuthProvider).toHaveBeenCalledWith('nous', undefined))+ await waitFor(() => expect(disconnectOAuthProvider).toHaveBeenCalledWith('nous', 'default'))expect(listOAuthProviders).toHaveBeenCalledTimes(2)})@@ -203,7 +205,7 @@ describe('ProvidersSettings', () => {fireEvent.click(await screen.findByText('Nous Portal'))})- expect(startManualProviderOAuth).toHaveBeenCalledWith('nous', undefined)+ expect(startManualProviderOAuth).toHaveBeenCalledWith('nous', 'default')expect(disconnectOAuthProvider).not.toHaveBeenCalled()})diff --git a/apps/desktop/src/store/settings-scope.test.ts b/apps/desktop/src/store/settings-scope.test.tsindex b8d3663085b..72682265d8e 100644--- a/apps/desktop/src/store/settings-scope.test.ts+++ b/apps/desktop/src/store/settings-scope.test.ts@@ -68,15 +68,44 @@ describe('settings scope store', () => {expect($settingsScopeProfile.get()).toBe('default')})- it('exposes a request-shaped scope: undefined (never null) without an override', () => {+ it('exposes a request-shaped scope: the concrete profile, never null', () => {// api/client.ts profileScoped() treats null as "target primary/default" —// the #90549 bug class. The request form must therefore never be null.- expect($settingsRequestProfile.get()).toBeUndefined()+ expect($settingsRequestProfile.get()).toBe('default')setSettingsScope('research')expect($settingsRequestProfile.get()).toBe('research')setSettingsScope('default')+ expect($settingsRequestProfile.get()).toBe('default')+ })++ it('names the profile the page displays even when that IS the active profile', () => {+ // #118432: the "Changes on this page apply to 'x'" note reads+ // $settingsScopeProfile, so the value handed to API helpers must carry the+ // SAME key. An `undefined` request scope makes profileScoped() omit+ // `?profile=` entirely, and the backend resolves an omitted profile to the+ // home it was LAUNCHED under — not the profile being edited. With a pooled+ // desktop backend (`hermes --profile a serve`, editing b) that mismatch+ // made every settings page read a's values and write them back to a, while+ // the note kept naming b.+ $activeGatewayProfile.set('nash')+ expect($settingsScopeProfile.get()).toBe('nash')+ expect($settingsRequestProfile.get()).toBe('nash')++ // Selecting the active profile stores no override — this is the exact case+ // that used to collapse the request scope to undefined.+ setSettingsScope('nash')+ expect($settingsScopeOverride.get()).toBeNull()+ expect($settingsRequestProfile.get()).toBe('nash')+ })++ it('leaves a custom HERMES_HOME on the ambient request path', () => {+ // `custom` names a home outside profiles/: there is no profile directory to+ // resolve, so the ambient path is the only correct answer.+ $activeGatewayProfile.set('custom')++ expect($settingsScopeProfile.get()).toBe('custom')expect($settingsRequestProfile.get()).toBeUndefined()})diff --git a/apps/desktop/src/store/settings-scope.ts b/apps/desktop/src/store/settings-scope.tsindex a4c878f1ad0..703228fed6f 100644--- a/apps/desktop/src/store/settings-scope.ts+++ b/apps/desktop/src/store/settings-scope.ts@@ -39,12 +39,22 @@ export const $settingsScopeEditsNonDefault = computed([$settingsScopeProfile, $p// Passing the raw override into an API helper therefore silently retargets// every read/write to the primary profile whenever no override is set — the// "model change reverts when I re-enter the tab" class of bug (#90549: the-// page WROTE the right profile but READ primary back). Always send this-// computed (or `override ?? undefined`) on requests; keep the raw override-// only for UI concerns (selector highlight, cache keys, remount keys).+// page WROTE the right profile but READ primary back).+//+// It must also never be `undefined` for a profile the pages actually display.+// `undefined` makes `profileScoped()` omit `?profile=` altogether, and the+// backend resolves an omitted profile to the home it was LAUNCHED with — not+// the profile this store says we are editing. Those differ the moment a pooled+// desktop backend serves a profile other than its launch home (`hermes+// --profile A serve`, editing B): every settings page then READ A's values and+// WROTE them back to A, while the "Changes on this page apply to 'B'" note —+// which reads the concrete $settingsScopeProfile — kept naming B (#118432).+// Send the concrete key the pages render. Only a name with no profile+// directory behind it (`custom`, a HERMES_HOME outside profiles/) stays+// `undefined`, where the ambient path is the only correct answer.export const $settingsRequestProfile = computed(- $settingsScopeOverride,- (override): string | undefined => override ?? undefined+ $settingsScopeProfile,+ (selected): string | undefined => (selected === 'custom' ? undefined : selected))// Select the profile the settings pages should edit. Picking the app's active