Skip to content

The agent that grows with you

fix(desktop): route session reads through primary backend

fangliquanflqad6fdd4f1c5e
diff --git a/apps/desktop/electron/connection-config.test.ts b/apps/desktop/electron/connection-config.test.ts
index 6493a99636f..0ea6aeb958d 100644
--- a/apps/desktop/electron/connection-config.test.ts
+++ b/apps/desktop/electron/connection-config.test.ts
@@ -405,6 +405,30 @@ const ROUTES = [
},
expected: { backend: 'primary', descriptorProfile: 'coder', scopePath: true }
},
+ {
+ name: 'a read-only local session request reuses the primary backend',
+ profile: 'coder',
+ opts: {
+ primaryProfile: 'default',
+ globalRemote: false,
+ profileRemoteOverride: false,
+ requestMethod: 'GET',
+ requestPath: '/api/sessions/session-1/messages?limit=20'
+ },
+ expected: { backend: 'primary', descriptorProfile: 'coder', scopePath: true }
+ },
+ {
+ name: 'a local session write keeps its pooled backend',
+ profile: 'coder',
+ opts: {
+ primaryProfile: 'default',
+ globalRemote: false,
+ profileRemoteOverride: false,
+ requestMethod: 'PATCH',
+ requestPath: '/api/sessions/session-1'
+ },
+ expected: { backend: 'pool', descriptorProfile: null, scopePath: false }
+ },
{
name: 'a profile-management request uses the primary without a query scope',
profile: 'coder',
@@ -696,6 +720,20 @@ test('resolveProfileApiRequest keeps eligible local REST on the primary backend'
)
})
+test('resolveProfileApiRequest scopes read-only session probes without spawning a profile backend', () => {
+ assert.deepEqual(
+ resolveProfileApiRequest('iris', '/api/sessions/stored-session?include_compacted=true', {
+ globalRemote: false,
+ profileRemoteOverride: false,
+ requestMethod: 'GET'
+ }),
+ {
+ backendProfile: null,
+ requestPath: '/api/sessions/stored-session?include_compacted=true&profile=iris'
+ }
+ )
+})
+
test('resolveProfileApiRequest keeps unscoped destructive routes on the profile backend', () => {
for (const [method, path] of [
['POST', '/api/memory/reset'],
diff --git a/apps/desktop/electron/connection-config.ts b/apps/desktop/electron/connection-config.ts
index 226c4d3e6e9..8526a5350dc 100644
--- a/apps/desktop/electron/connection-config.ts
+++ b/apps/desktop/electron/connection-config.ts
@@ -647,6 +647,14 @@ function localPrimaryRequestScope(opts: ProfileRouteOptions): boolean | null {
return true
}
+ // Session reads already accept `profile` and open that profile's state.db
+ // read-only. Keep ownership probes and transcript reads on the shared primary
+ // instead of spawning one local backend per profile. Writes remain pooled so
+ // their process-level profile scope and side effects are unchanged.
+ if (method === 'GET' && (pathname === '/api/sessions' || pathname.startsWith('/api/sessions/'))) {
+ return true
+ }
+
// Every current /api/tools handler accepts `profile`; every /api/profiles
// handler either aggregates profiles or names its target in the path/body.
// These are the only whole families safe to route through the primary.