Skip to content

The agent that grows with you

fix(desktop): keep "All profiles" across a boot-time source restore

sryimnoob6737076f9a96
diff --git a/apps/desktop/src/store/connections.test.ts b/apps/desktop/src/store/connections.test.ts
index cb9ec749f5d..aeef63ba90f 100644
--- a/apps/desktop/src/store/connections.test.ts
+++ b/apps/desktop/src/store/connections.test.ts
@@ -977,6 +977,20 @@ describe('selectConnection', () => {
expect($showAllProfiles.get()).toBe(false)
})
+ it('a boot-time restore of the last-used source leaves "All profiles" on', async () => {
+ list.mockResolvedValueOnce({ ...registry, lastUsed: 'homelab', launchMode: 'last-used' })
+ // Main opens the local backend before the registry settles, so a source is
+ // already published when the restore runs. The old null-id inference read
+ // that as a user-initiated switch and collapsed the browse view on restart.
+ $connection.set({ connectionId: 'local', mode: 'local' })
+ $showAllProfiles.set(true)
+
+ await initializeConnectionsRegistry()
+
+ expect(ensureGatewayAgent).toHaveBeenCalledWith('homelab', 'default', expect.anything())
+ expect($showAllProfiles.get()).toBe(true)
+ })
+
it('restores the last-used profile on switch-back even when the primary local descriptor is profile-less', async () => {
// The pair is remembered while the primary local descriptor is honest
// about its profile (boot publication).
diff --git a/apps/desktop/src/store/connections.ts b/apps/desktop/src/store/connections.ts
index b771e5a8a8e..26201d2530b 100644
--- a/apps/desktop/src/store/connections.ts
+++ b/apps/desktop/src/store/connections.ts
@@ -289,7 +289,7 @@ export async function initializeConnectionsRegistry(): Promise<DesktopConnection
}
if (registry.connections.some(connection => connection.id === connectionId)) {
- await selectConnection(connectionId, { profile: defaultRoute.profile })
+ await selectConnection(connectionId, { profile: defaultRoute.profile, restore: true })
}
return $connectionsRegistry.get() ?? registry
@@ -323,7 +323,7 @@ export async function initializeConnectionsRegistry(): Promise<DesktopConnection
if ($activeConnectionId.get() === preferredId) {
await rememberConnection(preferredId)
} else {
- await selectConnection(preferredId)
+ await selectConnection(preferredId, { restore: true })
}
return $connectionsRegistry.get() ?? registry
@@ -358,6 +358,13 @@ export interface SelectConnectionOptions {
/** Land on this profile of the target source instead of the one last used
* there. The fleet profile rail passes the exact square the user clicked. */
profile?: null | string
+ /** This call restores the source the window launched on; it is not a switch
+ * the user asked for, so the persisted "All profiles" browse mode must be
+ * left alone. The boot path passes it explicitly: the old inference
+ * (`$activeConnectionId` still null) only held while nothing had published a
+ * source yet, so a second restore pass — the normal case, because main opens
+ * the local backend before the registry settles — read as user-initiated. */
+ restore?: boolean
}
export async function selectConnection(connectionId: string, options: SelectConnectionOptions = {}): Promise<void> {
@@ -371,8 +378,10 @@ export async function selectConnection(connectionId: string, options: SelectConn
// A user-initiated source switch collapses "All profiles" browse mode: the
// picker is a concrete-source action. The silent boot-time restore (below,
// from initializeConnectionsRegistry) is not — it must leave the persisted
- // browse-mode preference alone so it survives restart (#93197).
- const restoreOnBoot = pendingTarget === null && $activeConnectionId.get() === null
+ // browse-mode preference alone so it survives restart (#93197). The caller
+ // that knows it is restoring says so; the null-id inference stays as the
+ // fallback for the first pass, when no source has been published yet.
+ const restoreOnBoot = options.restore === true || (pendingTarget === null && $activeConnectionId.get() === null)
const currentConnectionId = $activeConnectionId.get()
const currentProfile = normalizeProfileKey($activeGatewayProfile.get())
@@ -418,7 +427,13 @@ export async function selectConnection(connectionId: string, options: SelectConn
}
if (pendingTarget === null && currentConnectionId === connectionId && currentProfile === targetProfile) {
- $showAllProfiles.set(false)
+ // The pair is already live, so nothing was switched — this branch is only
+ // reached with `switching` true because "All profiles" is on. Collapsing the
+ // browse view here is what dropped the user back to a single profile.
+ if (!restoreOnBoot) {
+ $showAllProfiles.set(false)
+ }
+
rehomeNewChatDraft(targetProfile)
await rememberConnection(connectionId)