Skip to content

The agent that grows with you

fix(desktop): legacy remote session writes keep their mutation identity query

Tekniumd1a1c2e51373
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 3c40a50777c..24244a37d7c 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -468,8 +468,8 @@ import {
isAllProfilesAggregateRequest,
isAllProfilesSessionListRequest,
isRemoteSessionRequestPath,
- pathWithRemoteOwnerScope,
type RegistrySessionSource,
+ remoteOwnerRoutePath,
remoteProfileQueryScope,
settleRemoteProfileSessions,
shouldIncludeLocalRegistrySessionSource,
@@ -16084,7 +16084,6 @@ async function interceptSessionRequestForRemote(request, registryConnectionId =
// against paginating remote backends).
const passthroughParams = new URLSearchParams(searchParams)
passthroughParams.delete('profile')
- const passthroughQuery = passthroughParams.toString()
if (profileHasRemoteOverride(profile)) {
// #64999: the override's remote can be a multi-profile backend — an
@@ -16096,11 +16095,10 @@ async function interceptSessionRequestForRemote(request, registryConnectionId =
remoteProfileQueryScope(profile, profileSshOverride(readDesktopConnectionConfig(), profile)?.remoteProfile) ||
profile
+ const ownerPath = remoteOwnerRoutePath(pathname, searchParams, ownerScope)
+
if (method === 'GET') {
- return fetchJsonForProfile(
- profile,
- pathWithRemoteOwnerScope(passthroughQuery ? `${pathname}?${passthroughQuery}` : pathname, ownerScope)
- )
+ return fetchJsonForProfile(profile, ownerPath)
}
const body = request.body && typeof request.body === 'object' ? { ...request.body } : request.body
@@ -16109,7 +16107,8 @@ async function interceptSessionRequestForRemote(request, registryConnectionId =
;(body as Record<string, unknown>).profile = ownerScope
}
- return requestJsonForProfile(profile, pathname, method, body)
+ // A DELETE's mutation identity is query-only; a bare pathname 409s on the remote.
+ return requestJsonForProfile(profile, ownerPath, method, body)
}
if (globalRemoteActive()) {
diff --git a/apps/desktop/electron/profile-session-routing.test.ts b/apps/desktop/electron/profile-session-routing.test.ts
index 311a24bf658..18660ad2496 100644
--- a/apps/desktop/electron/profile-session-routing.test.ts
+++ b/apps/desktop/electron/profile-session-routing.test.ts
@@ -17,6 +17,7 @@ import {
isRemoteSessionRequestPath,
mergeProfileSessionWindow,
pathWithRemoteOwnerScope,
+ remoteOwnerRoutePath,
remoteProfileQueryScope,
settleRemoteProfileSessions,
shouldIncludeLocalRegistrySessionSource,
@@ -36,6 +37,20 @@ test('remote session routing includes the mutation snapshot and session reads, n
assert.equal(isRemoteSessionRequestPath('/api/sessions/stored-session/mutation-snapshot/extra'), false)
})
+test('legacy remote owner route keeps the mutation identity query for the paired DELETE', () => {
+ const deletePath = '/api/sessions/s1?profile=alpha&request_id=r1&expected_revision=4&expected_generation=2'
+ const { pathname, searchParams } = new URL(deletePath, 'http://x')
+ const routed = new URL(remoteOwnerRoutePath(pathname, searchParams, 'alpha'), 'http://x')
+ assert.equal(routed.pathname, '/api/sessions/s1')
+ assert.equal(routed.searchParams.get('request_id'), 'r1')
+ assert.equal(routed.searchParams.get('expected_revision'), '4')
+ assert.equal(routed.searchParams.get('expected_generation'), '2')
+ assert.equal(routed.searchParams.get('profile'), 'alpha')
+ const snapshot = new URL('/api/sessions/s1/mutation-snapshot?profile=alpha', 'http://x')
+ assert.equal(remoteOwnerRoutePath(snapshot.pathname, snapshot.searchParams, 'alpha'), '/api/sessions/s1/mutation-snapshot?profile=alpha')
+ assert.equal(remoteOwnerRoutePath(snapshot.pathname, snapshot.searchParams, ''), '/api/sessions/s1/mutation-snapshot')
+})
+
test('all-profiles session routing is limited to read-only list endpoints', () => {
assert.equal(isAllProfilesSessionListRequest('GET', '/api/profiles/sessions?profile=all'), true)
assert.equal(isAllProfilesSessionListRequest('GET', '/api/profiles/sessions/sidebar?recents_profile=all'), true)
diff --git a/apps/desktop/electron/profile-session-routing.ts b/apps/desktop/electron/profile-session-routing.ts
index 0756a3daca4..2e52d887fc0 100644
--- a/apps/desktop/electron/profile-session-routing.ts
+++ b/apps/desktop/electron/profile-session-routing.ts
@@ -642,6 +642,17 @@ export function pathWithRemoteOwnerScope(path: string, scope: string): string {
return `${url.pathname}${url.search}${url.hash}`
}
+/** The legacy per-profile remote route for one session request: every non-profile query
+ * param survives (pagination on reads; a DELETE's request_id/expected_revision/
+ * expected_generation live only in the query) and the owner scope replaces ?profile=. */
+export function remoteOwnerRoutePath(pathname: string, searchParams: URLSearchParams, ownerScope: string): string {
+ const params = new URLSearchParams(searchParams)
+ params.delete('profile')
+ const query = params.toString()
+
+ return pathWithRemoteOwnerScope(query ? `${pathname}?${query}` : pathname, ownerScope)
+}
+
export async function fetchRemoteProfileSessions(
profile: string,
searchParams: URLSearchParams,