The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep the short socket TMPDIR across the --no-sandbox relaunch
Teknium4453b34d6ab9
diff --git a/apps/desktop/electron/linux-sandbox-relaunch.test.ts b/apps/desktop/electron/linux-sandbox-relaunch.test.tsindex 3f0457af84c..cbb82e7e79c 100644--- a/apps/desktop/electron/linux-sandbox-relaunch.test.ts+++ b/apps/desktop/electron/linux-sandbox-relaunch.test.ts@@ -1,4 +1,4 @@-import { describe, expect, it } from 'vitest'+import { describe, expect, it, vi } from 'vitest'import { linuxNoSandboxRelaunch } from './linux-sandbox-relaunch'@@ -23,6 +23,48 @@ describe('Linux runtime --no-sandbox relaunch', () => {expect(linuxNoSandboxRelaunch({ platform: 'win32', runtimeNoSandbox: true, argv, env: {}, launchedWithoutSandbox: false })).toBeNull()})+ // The relaunch skips `hermes desktop`, so it must not inherit the long TMPDIR+ // main.ts restored after the lock: that path hangs requestSingleInstanceLock().+ it.skipIf(process.platform !== 'linux')('relaunches with the short socket TMPDIR the launcher chose', async () => {+ const saved = { ...process.env }+ const shortDir = '/run/user/1000/hermes-desktop'+ const longDir = `/home/u/.hermes/profiles/${'p'.repeat(80)}/cache/scratch`++ try {+ process.env.TMPDIR = shortDir+ process.env.HERMES_DESKTOP_TMPDIR = longDir+ delete process.env.ELECTRON_DISABLE_SANDBOX+ vi.resetModules()+ const { relaunchIfNoSandboxCameTooLate } = await import('./linux-sandbox-relaunch')++ // main.ts: the lock is held, the backend's directory comes back.+ process.env.TMPDIR = longDir+ delete process.env.HERMES_DESKTOP_TMPDIR++ let relaunchEnv: NodeJS.ProcessEnv = {}++ const relaunched = relaunchIfNoSandboxCameTooLate({+ commandLine: { hasSwitch: name => name === 'no-sandbox' },+ relaunch: () => {+ relaunchEnv = { ...process.env }+ },+ exit: () => undefined+ })++ expect(relaunched).toBe(true)+ expect(relaunchEnv.TMPDIR).toBe(shortDir)+ expect(relaunchEnv.HERMES_DESKTOP_TMPDIR).toBe(longDir)+ } finally {+ for (const key of Object.keys(process.env)) {+ if (!(key in saved)) {+ delete process.env[key]+ }+ }++ Object.assign(process.env, saved)+ }+ })+it('relaunches the AppImage itself rather than its vanishing mount', () => {const relaunch = linuxNoSandboxRelaunch({platform: 'linux',diff --git a/apps/desktop/electron/linux-sandbox-relaunch.ts b/apps/desktop/electron/linux-sandbox-relaunch.tsindex c27f4679f4c..9ec1b98cf66 100644--- a/apps/desktop/electron/linux-sandbox-relaunch.ts+++ b/apps/desktop/electron/linux-sandbox-relaunch.ts@@ -29,6 +29,26 @@ export interface SandboxRelaunch {// whether Chromium actually started unsandboxed.const LAUNCHED_WITHOUT_SANDBOX = alreadyHasNoSandbox(process.argv, process.env)+// `hermes desktop` shortens TMPDIR on Linux so the single-instance lock can+// bind its socket, parking the real one in HERMES_DESKTOP_TMPDIR; main.ts+// hands it back right after the lock. The relaunch does not go through the+// launcher again, so it must inherit the short launch pair, not the restored+// long TMPDIR that would hang its requestSingleInstanceLock().+const DESKTOP_TMPDIR_ENV = 'HERMES_DESKTOP_TMPDIR'++const LAUNCH_TMPDIR_PAIR = process.env[DESKTOP_TMPDIR_ENV]+ ? { socketTmpdir: process.env.TMPDIR, realTmpdir: process.env[DESKTOP_TMPDIR_ENV] }+ : null++export function restoreLaunchTmpdir(env: NodeJS.ProcessEnv, pair = LAUNCH_TMPDIR_PAIR): void {+ if (!pair) {+ return+ }++ env.TMPDIR = pair.socketTmpdir+ env[DESKTOP_TMPDIR_ENV] = pair.realTmpdir+}+export function linuxNoSandboxRelaunch(options: {platform: NodeJS.Platform | stringruntimeNoSandbox: boolean@@ -74,6 +94,7 @@ export function relaunchIfNoSandboxCameTooLate(host: RelaunchHost): boolean {// number would make the next process write its reveal byte into whatever// file reuses that descriptor.delete process.env[LAUNCHER_READY_FD_ENV]+ restoreLaunchTmpdir(process.env)host.relaunch(relaunch)host.exit(0)