The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): the --no-sandbox relaunch restarts Hermes, not an AppImage it inherited APPIMAGE from
Teknium1887a5015b36
diff --git a/apps/desktop/electron/linux-sandbox-relaunch.test.ts b/apps/desktop/electron/linux-sandbox-relaunch.test.tsindex cbb82e7e79c..04fd3f0f628 100644--- a/apps/desktop/electron/linux-sandbox-relaunch.test.ts+++ b/apps/desktop/electron/linux-sandbox-relaunch.test.ts@@ -6,21 +6,51 @@ const argv = ['/opt/Hermes/hermes', '--ozone-platform=x11', 'hermes://session/abdescribe('Linux runtime --no-sandbox relaunch', () => {it('moves a runtime-only --no-sandbox onto argv exactly once', () => {- const relaunch = linuxNoSandboxRelaunch({ platform: 'linux', runtimeNoSandbox: true, argv, env: {}, launchedWithoutSandbox: false })+ const relaunch = linuxNoSandboxRelaunch({+ platform: 'linux',+ runtimeNoSandbox: true,+ argv,+ env: {},+ launchedWithoutSandbox: false+ })expect(relaunch).toEqual({ args: ['--ozone-platform=x11', 'hermes://session/abc', '--no-sandbox'] })// The relaunched process started unsandboxed, so it never restarts again.expect(- linuxNoSandboxRelaunch({ platform: 'linux', runtimeNoSandbox: true, argv: ['/opt/Hermes/hermes', ...relaunch!.args], env: {}, launchedWithoutSandbox: true })+ linuxNoSandboxRelaunch({+ platform: 'linux',+ runtimeNoSandbox: true,+ argv: ['/opt/Hermes/hermes', ...relaunch!.args],+ env: {},+ launchedWithoutSandbox: true+ })).toBeNull()})it('leaves sandboxed launches, launch-time opt-outs and other platforms alone', () => {- expect(linuxNoSandboxRelaunch({ platform: 'linux', runtimeNoSandbox: false, argv, env: {}, launchedWithoutSandbox: false })).toBeNull()- expect(linuxNoSandboxRelaunch({ platform: 'linux', runtimeNoSandbox: true, argv, env: {}, launchedWithoutSandbox: true })).toBeNull()+ expect(+ linuxNoSandboxRelaunch({+ platform: 'linux',+ runtimeNoSandbox: false,+ argv,+ env: {},+ launchedWithoutSandbox: false+ })+ ).toBeNull()+ expect(+ linuxNoSandboxRelaunch({ platform: 'linux', runtimeNoSandbox: true, argv, env: {}, launchedWithoutSandbox: true })+ ).toBeNull()// Windows reads the switch per child launch, so its runtime fallback works in place.- expect(linuxNoSandboxRelaunch({ platform: 'win32', runtimeNoSandbox: true, argv, env: {}, launchedWithoutSandbox: false })).toBeNull()+ expect(+ linuxNoSandboxRelaunch({+ platform: 'win32',+ runtimeNoSandbox: true,+ argv,+ env: {},+ launchedWithoutSandbox: false+ })+ ).toBeNull()})// The relaunch skips `hermes desktop`, so it must not inherit the long TMPDIR@@ -70,10 +100,32 @@ describe('Linux runtime --no-sandbox relaunch', () => {platform: 'linux',runtimeNoSandbox: true,argv: ['/tmp/.mount_HermesX/hermes'],- env: { APPIMAGE: '/home/u/Apps/Hermes.AppImage' },+ execPath: '/tmp/.mount_HermesX/hermes',+ env: { APPIMAGE: '/home/u/Apps/Hermes.AppImage', APPDIR: '/tmp/.mount_HermesX' },launchedWithoutSandbox: false})expect(relaunch).toEqual({ args: ['--no-sandbox'], execPath: '/home/u/Apps/Hermes.AppImage' })})++ // AppImage apps (terminals, IDEs) export APPIMAGE/APPDIR to everything they+ // start; Hermes launched from one must relaunch itself, not that app.+ it('relaunches this executable when APPIMAGE was inherited from another AppImage', () => {+ for (const env of [+ { APPIMAGE: '/home/u/Apps/Terminal.AppImage' },+ { APPIMAGE: '/home/u/Apps/Terminal.AppImage', APPDIR: '/tmp/.mount_TermY' },+ { APPIMAGE: '/home/u/Apps/Terminal.AppImage', APPDIR: '/opt/Herm' }+ ]) {+ expect(+ linuxNoSandboxRelaunch({+ platform: 'linux',+ runtimeNoSandbox: true,+ argv,+ execPath: '/opt/Hermes/hermes',+ env,+ launchedWithoutSandbox: false+ })+ ).toEqual({ args: ['--ozone-platform=x11', 'hermes://session/abc', '--no-sandbox'] })+ }+ })})diff --git a/apps/desktop/electron/linux-sandbox-relaunch.ts b/apps/desktop/electron/linux-sandbox-relaunch.tsindex 9ec1b98cf66..5df546a672b 100644--- a/apps/desktop/electron/linux-sandbox-relaunch.ts+++ b/apps/desktop/electron/linux-sandbox-relaunch.ts@@ -17,6 +17,7 @@// `hermes desktop` — restarts once with the flag on argv instead.import { LAUNCHER_READY_FD_ENV } from './linux-launcher-ready'+import { relaunchExecPath } from './relaunch-target'import { alreadyHasNoSandbox, buildNoSandboxRelaunchArgs } from './windows-sandbox-fallback'export interface SandboxRelaunch {@@ -54,6 +55,7 @@ export function linuxNoSandboxRelaunch(options: {runtimeNoSandbox: booleanargv: readonly string[]env: NodeJS.ProcessEnv+ execPath?: stringlaunchedWithoutSandbox?: boolean}): SandboxRelaunch | null {const launchedWithoutSandbox = options.launchedWithoutSandbox ?? LAUNCHED_WITHOUT_SANDBOX@@ -63,10 +65,9 @@ export function linuxNoSandboxRelaunch(options: {}const args = buildNoSandboxRelaunchArgs(options.argv.slice(1))+ const execPath = relaunchExecPath(options.execPath ?? process.execPath, options.env)- // An AppImage's execPath lives in a FUSE mount that disappears with this- // process; relaunch the image itself.- return options.env.APPIMAGE ? { args, execPath: options.env.APPIMAGE } : { args }+ return execPath ? { args, execPath } : { args }}interface RelaunchHost {diff --git a/apps/desktop/electron/relaunch-target.ts b/apps/desktop/electron/relaunch-target.tsnew file mode 100644index 00000000000..446e84e6321--- /dev/null+++ b/apps/desktop/electron/relaunch-target.ts@@ -0,0 +1,27 @@+import path from 'node:path'++/**+ * The executable that starts this app again, or undefined for Electron's+ * default (process.execPath).+ *+ * A real AppImage runs from a FUSE mount (APPDIR) that disappears when this+ * process exits, so it relaunches the image file ($APPIMAGE) instead. The+ * AppImage runtime exports APPIMAGE/APPDIR to every descendant, though: Hermes+ * started from a terminal or IDE AppImage inherits that app's pair, and+ * relaunching it would start the other app while Hermes never comes back. The+ * pair is ours only when this executable lives inside APPDIR.+ */+export function relaunchExecPath(+ execPath: string = process.execPath,+ env: NodeJS.ProcessEnv = process.env+): string | undefined {+ const { APPDIR: appDir, APPIMAGE: appImage } = env++ if (!appImage || !appDir) {+ return undefined+ }++ const inside = path.relative(path.resolve(appDir), path.resolve(execPath))++ return inside && !inside.startsWith('..') && !path.isAbsolute(inside) ? appImage : undefined+}