Skip to content

The agent that grows with you

fix(desktop): include local sessions in remote aggregates

Mohamad Kanso46bcd9458f09
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index c13c3c40484..3022df021fe 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -445,6 +445,7 @@ import {
pathWithRemoteOwnerScope,
type RegistrySessionSource,
remoteProfileQueryScope,
+ shouldIncludeLocalRegistrySessionSource,
spliceRegistrySessionRows,
tagRegistrySessionResponse,
tagRemoteSessionRows
@@ -16830,7 +16831,10 @@ async function interceptSessionRequestForRemote(request, registryConnectionId =
if (method === 'GET' && pathname === '/api/profiles/sessions') {
const remoteProfiles = configuredRemoteProfileNames()
- const registrySources = await pooledRegistrySessionSources(Boolean(registryConnectionId))
+
+ const registrySources = await pooledRegistrySessionSources(
+ shouldIncludeLocalRegistrySessionSource(registryConnectionId, !globalRemoteActive())
+ )
if (remoteProfiles.length === 0 && registrySources.length === 0) {
return undefined // no remote profiles and no connected registry gateways → local fast path
@@ -16868,7 +16872,10 @@ async function interceptSessionRequestForRemote(request, registryConnectionId =
// remote correctness is preserved.
if (method === 'GET' && pathname === '/api/profiles/sessions/sidebar') {
const remoteProfiles = configuredRemoteProfileNames()
- const registrySources = await pooledRegistrySessionSources(Boolean(registryConnectionId))
+
+ const registrySources = await pooledRegistrySessionSources(
+ shouldIncludeLocalRegistrySessionSource(registryConnectionId, !globalRemoteActive())
+ )
if (remoteProfiles.length === 0 && registrySources.length === 0) {
return undefined // local fast path → batched endpoint's single DB open
diff --git a/apps/desktop/electron/profile-session-routing.test.ts b/apps/desktop/electron/profile-session-routing.test.ts
index 365f170693f..0a68f747c80 100644
--- a/apps/desktop/electron/profile-session-routing.test.ts
+++ b/apps/desktop/electron/profile-session-routing.test.ts
@@ -14,6 +14,7 @@ import {
mergeProfileSessionWindow,
pathWithRemoteOwnerScope,
remoteProfileQueryScope,
+ shouldIncludeLocalRegistrySessionSource,
spliceRegistrySessionRows,
tagRegistrySessionResponse,
tagRemoteSessionRows
@@ -67,6 +68,13 @@ test('pinned registry aggregation requires the selected profile backend for per-
assert.equal(hasPinnedRegistrySessionSource('gateway-remote', 'any-profile', sources), true)
})
+test('unscoped aggregates include local rows when the primary is remote', () => {
+ assert.equal(shouldIncludeLocalRegistrySessionSource(null, false), true)
+ assert.equal(shouldIncludeLocalRegistrySessionSource('server', false), true)
+ assert.equal(shouldIncludeLocalRegistrySessionSource('local', true), true)
+ assert.equal(shouldIncludeLocalRegistrySessionSource(null, true), false)
+})
+
test('remote sidebar slices all follow the selected profile', () => {
const slices = buildSidebarSessionSliceParams(
new URLSearchParams({
diff --git a/apps/desktop/electron/profile-session-routing.ts b/apps/desktop/electron/profile-session-routing.ts
index 54ebdad3b6b..803c97bd563 100644
--- a/apps/desktop/electron/profile-session-routing.ts
+++ b/apps/desktop/electron/profile-session-routing.ts
@@ -321,6 +321,14 @@ export function hasPinnedRegistrySessionSource(
return source.backends.some(({ profileLabel }) => (profileLabel || 'default') === selectedProfile)
}
+/** include the local registry source when the primary aggregate is remote */
+export function shouldIncludeLocalRegistrySessionSource(
+ connectionId: string | null | undefined,
+ baseCoversLocal = true
+): boolean {
+ return Boolean(String(connectionId ?? '').trim()) || !baseCoversLocal
+}
+
type GetJsonForDescriptor = (descriptor: unknown, path: string) => Promise<unknown>
/** Read one registry source without sending a page larger than the backend cap. */