Skip to content

The agent that grows with you

fix(desktop): scope per-session remote reads so resume opens the owning state.db (#64999)

Hermes Agentffa40b07f020
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 0f5f9d277df..458fb226f23 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -423,9 +423,12 @@ import {
fetchRemoteProfileSessions,
findRemoteOwnerProfileForSession,
mergeProfileSessionWindow,
+ pathWithRemoteOwnerScope,
type RegistrySessionSource,
+ remoteProfileQueryScope,
spliceRegistrySessionRows,
- tagRegistrySessionResponse
+ tagRegistrySessionResponse,
+ tagRemoteSessionRows
} from './profile-session-routing'
import { createQuickEntryShortcut, quickEntryWindowBounds, sanitizeQuickEntrySettings } from './quick-entry'
import { createQuitFinalization } from './quit-finalization'
@@ -16614,14 +16617,26 @@ async function interceptSessionRequestForRemote(request) {
const passthroughQuery = passthroughParams.toString()
if (profileHasRemoteOverride(profile)) {
+ // #64999: the override's remote can be a multi-profile backend — an
+ // unscoped read opens its launch-profile state.db, so a resume 4007s
+ // even though the row exists under its real owner. Scope the read the
+ // same way the list fetch does; a legacy single-profile scope ('')
+ // keeps the path bare.
+ const ownerScope =
+ remoteProfileQueryScope(profile, profileSshOverride(readDesktopConnectionConfig(), profile)?.remoteProfile) ||
+ profile
+
if (method === 'GET') {
- return fetchJsonForProfile(profile, passthroughQuery ? `${pathname}?${passthroughQuery}` : pathname)
+ return fetchJsonForProfile(
+ profile,
+ pathWithRemoteOwnerScope(passthroughQuery ? `${pathname}?${passthroughQuery}` : pathname, ownerScope)
+ )
}
const body = request.body && typeof request.body === 'object' ? { ...request.body } : request.body
- if (body) {
- delete body.profile
+ if (body && ownerScope) {
+ ;(body as Record<string, unknown>).profile = ownerScope
}
return requestJsonForProfile(profile, pathname, method, body)
@@ -16649,17 +16664,17 @@ async function interceptSessionRequestForRemote(request) {
const rowsOf = data => (Array.isArray(data?.sessions) ? data.sessions : [])
-// A remote profile's session list, read from its remote host and tagged with the
-// desktop-facing profile name (the remote's /api/sessions doesn't know it).
+// A remote profile's session list. The fetch itself is profile-scoped
+// (fetchRemoteProfileSessions, #64999); the remote's own stamps carry the
+// authoritative identity — never relabel rows with the Desktop scope name.
async function remoteSessionList(profile, searchParams) {
- const data = await fetchRemoteProfileSessions(profile, searchParams, fetchJsonForProfile)
-
- for (const s of rowsOf(data)) {
- s.profile = profile
- s.is_default_profile = false
- }
+ const sshOverride = profileSshOverride(readDesktopConnectionConfig(), profile)
+ const data = await fetchRemoteProfileSessions(profile, searchParams, fetchJsonForProfile, {
+ remoteProfileAlias: sshOverride?.remoteProfile
+ })
+ const rows = tagRemoteSessionRows(rowsOf(data), remoteProfileQueryScope(profile, sshOverride?.remoteProfile) || profile)
- return { ...(data as any), sessions: rowsOf(data) }
+ return { ...(data as any), sessions: rows }
}
// #85834: find which remote profile owns a session id when the caller gave no