Skip to content

The agent that grows with you

fix(desktop): exact collection paths for profile tickets; retry a failed launcher-root probe

Teknium3d92e4a6b265
diff --git a/apps/desktop/electron/local-gateway.test.ts b/apps/desktop/electron/local-gateway.test.ts
index db5a1e0b543..b7e945e768d 100644
--- a/apps/desktop/electron/local-gateway.test.ts
+++ b/apps/desktop/electron/local-gateway.test.ts
@@ -474,6 +474,20 @@ test('every named Profiles-screen route mints for its profile; collection routes
expect(route('/api/profiles/sessions?profile=p2')).toBe(path.resolve('hermes-home', 'profiles', 'p2'))
})
+// A profile may be NAMED like a collection route: only the exact collection paths stay on their
+// selector, so `/api/profiles/projects/soul` still mints for the `projects` profile.
+test('a profile named like a collection route still gets its own ticket', () => {
+ const endpoint = { profile_id: path.resolve('hermes-home'), instance_id: 'i', authority_epoch: 1, runtime_protocol: 1, api_origin: 'http://127.0.0.1:1', capabilities: [], supervisor: 'none', control_home: null }
+ const route = (p: string) => routedGatewayEndpoint(endpoint, `http://127.0.0.1:1${p}`, endpoint.profile_id).profile_id
+
+ for (const name of ['projects', 'sessions', 'active', 'import']) {
+ expect(route(`/api/profiles/${name}/soul`)).toBe(path.resolve('hermes-home', 'profiles', name))
+ }
+
+ expect(route('/api/profiles/sessions/sidebar?recents_profile=p2')).toBe(path.resolve('hermes-home', 'profiles', 'p2'))
+ expect(route('/api/profiles/sessions/pull-requests?profile=p2')).toBe(path.resolve('hermes-home', 'profiles', 'p2'))
+})
+
// The batched sidebar names its owner in `recents_profile`; a grant for the window's own profile
// is refused there (profile_scope_mismatch) and the sidebar drops that profile's sessions.
test('a sidebar read mints for the profile its recents_profile names', () => {
diff --git a/apps/desktop/electron/local-gateway.ts b/apps/desktop/electron/local-gateway.ts
index cc4787be856..661dc8477ea 100644
--- a/apps/desktop/electron/local-gateway.ts
+++ b/apps/desktop/electron/local-gateway.ts
@@ -347,11 +347,11 @@ function shellQuote(file: string): string {
return `'${file.replace(/'/g, `'\\''`)}'`
}
-// These are collection routes beneath /api/profiles, not profile names. Keep this in step with
-// dashboard_auth.native_http._check_profile_scope: every other first path segment names the
-// profile whose native ticket must be minted.
+// Exact `/api/profiles/<suffix>` collection paths, mirroring the gateway's native-http scope check
+// (hermes_cli/dashboard_auth/native_http.py::_check_profile_scope). Matched on the whole suffix, so a
+// profile NAMED `projects` or `sessions` still gets its own ticket on `/api/profiles/projects/soul`.
const PROFILE_COLLECTION_ROUTES = new Set([
- 'active', 'import', 'projects', 'sessions'
+ 'active', 'import', 'projects/tree', 'sessions', 'sessions/pull-requests', 'sessions/sidebar'
])
/** The batched sidebar names its owner in `recents_profile`. A named profile route carries its
@@ -367,7 +367,7 @@ function scopedProfileOf(url: URL): null | string {
const suffix = pathname.startsWith(prefix) ? pathname.slice(prefix.length) : ''
const segment = suffix.split('/', 1)[0]
- if (segment && !PROFILE_COLLECTION_ROUTES.has(segment)) {
+ if (segment && !PROFILE_COLLECTION_ROUTES.has(suffix)) {
try {
return decodeURIComponent(segment)
} catch {
diff --git a/apps/desktop/electron/updater-process.test.ts b/apps/desktop/electron/updater-process.test.ts
index 7f6b3201a8b..8018b6c3405 100644
--- a/apps/desktop/electron/updater-process.test.ts
+++ b/apps/desktop/electron/updater-process.test.ts
@@ -10,6 +10,7 @@ import {
collectRelaunchArgs,
describeUpdaterHandoffFailure,
launcherInstallDirectory,
+ launcherInstallRoot,
MARKER_SELF_ADOPT_EPOCH_MS,
observeUpdaterHandoff,
resolvePosixScriptHandoff,
@@ -499,6 +500,20 @@ test.skipIf(process.platform === 'win32')('launcherInstallDirectory stays null w
}
})
+// A failed probe (timeout, a launcher mid-replacement) must not stick: the ticket resolver retries
+// after a failure, and a cached miss would keep the override rootless until Desktop restarts.
+test.skipIf(process.platform === 'win32')('launcherInstallRoot retries a failed probe and caches the root it then reports', async () => {
+ const dir = await realpathMkdtemp('launcher-root-')
+ const reported = await fs.realpath(await fs.mkdir(path.join(dir, 'hermes-agent')).then(() => path.join(dir, 'hermes-agent')))
+ const launcher = await writeLauncher(dir, 'exit 3')
+
+ assert.equal(launcherInstallRoot(launcher), undefined)
+ await writeLauncher(dir, `printf 'Hermes Agent v0.22.1\\nInstall directory: ${reported}\\n'`)
+ assert.equal(launcherInstallRoot(launcher), reported)
+ await writeLauncher(dir, 'exit 3')
+ assert.equal(launcherInstallRoot(launcher), reported)
+})
+
async function realpathMkdtemp(prefix: string): Promise<string> {
return fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), prefix)))
}
diff --git a/apps/desktop/electron/updater-process.ts b/apps/desktop/electron/updater-process.ts
index 83257f93bcd..a7f05cd0408 100644
--- a/apps/desktop/electron/updater-process.ts
+++ b/apps/desktop/electron/updater-process.ts
@@ -114,17 +114,22 @@ export function launcherTargetsInstallation(launcher: string, root: string): boo
// A launcher's install directory cannot move while this process lives, and the
// backend resolver runs once per surface (startup, TUI resume, pool backends),
-// so the HERMES_DESKTOP_HERMES rung probes each launcher path at most once.
-const launcherInstallRoots = new Map<string, string | undefined>()
+// so the HERMES_DESKTOP_HERMES rung memoizes each launcher's root. Only a root is
+// cached: a failed or timed-out probe is retried on the next call, matching the
+// ticket resolver's own retry after a failure.
+const launcherInstallRoots = new Map<string, string>()
/** The root a launcher reports, memoized: ticketRuntimeFor() mints gateway
* tickets from a command backend only when it names its installation root. */
export function launcherInstallRoot(launcher: string): string | undefined {
- if (!launcherInstallRoots.has(launcher)) {
- launcherInstallRoots.set(launcher, launcherInstallDirectory(launcher) ?? undefined)
- }
+ const cached = launcherInstallRoots.get(launcher)
+
+ if (cached !== undefined) {return cached}
+ const root = launcherInstallDirectory(launcher) ?? undefined
+
+ if (root !== undefined) {launcherInstallRoots.set(launcher, root)}
- return launcherInstallRoots.get(launcher)
+ return root
}
/** The real install directory a launcher's `--version` reports, or null. */