The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): relaunch Linux with --no-sandbox on argv instead of a runtime switch
Teknium36d32082a63d
diff --git a/apps/desktop/electron/linux-sandbox-relaunch.test.ts b/apps/desktop/electron/linux-sandbox-relaunch.test.tsnew file mode 100644index 00000000000..3f0457af84c--- /dev/null+++ b/apps/desktop/electron/linux-sandbox-relaunch.test.ts@@ -0,0 +1,37 @@+import { describe, expect, it } from 'vitest'++import { linuxNoSandboxRelaunch } from './linux-sandbox-relaunch'++const argv = ['/opt/Hermes/hermes', '--ozone-platform=x11', 'hermes://session/abc']++describe('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 })++ 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 })+ ).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()+ // 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()+ })++ it('relaunches the AppImage itself rather than its vanishing mount', () => {+ const relaunch = linuxNoSandboxRelaunch({+ platform: 'linux',+ runtimeNoSandbox: true,+ argv: ['/tmp/.mount_HermesX/hermes'],+ env: { APPIMAGE: '/home/u/Apps/Hermes.AppImage' },+ launchedWithoutSandbox: false+ })++ expect(relaunch).toEqual({ args: ['--no-sandbox'], execPath: '/home/u/Apps/Hermes.AppImage' })+ })+})diff --git a/apps/desktop/electron/linux-sandbox-relaunch.ts b/apps/desktop/electron/linux-sandbox-relaunch.tsnew file mode 100644index 00000000000..346ce5349f3--- /dev/null+++ b/apps/desktop/electron/linux-sandbox-relaunch.ts@@ -0,0 +1,76 @@+// A runtime `--no-sandbox` is too late on Linux (#131055, #139542, #143569).+//+// Chromium forks its zygote into the sandbox (user-namespace or setuid lane)+// before any application JavaScript runs, so `app.commandLine.appendSwitch(+// 'no-sandbox')` from main.ts reaches only the renderers' own command lines.+// Those renderers are still forked from the sandboxed zygote, but believe they+// are unsandboxed: they skip the sandbox's shared-memory path, open /dev/shm+// (or $TMPDIR under --disable-dev-shm-usage) directly from inside the+// zygote's empty chroot, get ESRCH, and die with "Try 'sudo chmod 1777+// /dev/shm'" — a crash loop with no window, or an unbounded log storm when+// the directory is not /dev/shm (#144638).+//+// The flag is honored only when it is on the browser's launch command line+// (or ELECTRON_DISABLE_SANDBOX is set at launch), so a Linux launch that asks+// for it at runtime — the boot-abort ladder's sticky fallback, or+// `desktop.electron_flags` read from config.yaml by a launch that bypassed+// `hermes desktop` — restarts once with the flag on argv instead.++import { alreadyHasNoSandbox, buildNoSandboxRelaunchArgs } from './windows-sandbox-fallback'++export interface SandboxRelaunch {+ args: string[]+ execPath?: string+}++// Captured when this module is evaluated, before main.ts sets+// ELECTRON_DISABLE_SANDBOX for its children: only the launch-time state says+// whether Chromium actually started unsandboxed.+const LAUNCHED_WITHOUT_SANDBOX = alreadyHasNoSandbox(process.argv, process.env)++export function linuxNoSandboxRelaunch(options: {+ platform: NodeJS.Platform | string+ runtimeNoSandbox: boolean+ argv: readonly string[]+ env: NodeJS.ProcessEnv+ launchedWithoutSandbox?: boolean+}): SandboxRelaunch | null {+ const launchedWithoutSandbox = options.launchedWithoutSandbox ?? LAUNCHED_WITHOUT_SANDBOX++ if (options.platform !== 'linux' || !options.runtimeNoSandbox || launchedWithoutSandbox) {+ return null+ }++ const args = buildNoSandboxRelaunchArgs(options.argv.slice(1))++ // 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 }+}++interface RelaunchHost {+ commandLine: { hasSwitch(name: string): boolean }+ relaunch(options: SandboxRelaunch): void+ exit(code: number): void+}++// Call once, in the lock-owning instance, after every runtime switch source+// (sandbox ladder, config.yaml) has run and before `ready`.+export function relaunchIfNoSandboxCameTooLate(host: RelaunchHost): boolean {+ const relaunch = linuxNoSandboxRelaunch({+ platform: process.platform,+ runtimeNoSandbox: host.commandLine.hasSwitch('no-sandbox'),+ argv: process.argv,+ env: process.env+ })++ if (!relaunch) {+ return false+ }++ console.warn('[hermes] --no-sandbox requested after Chromium started; relaunching with it on the command line')+ host.relaunch(relaunch)+ host.exit(0)++ return true+}diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 2e9751d6827..9cba2f32f3b 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -344,6 +344,7 @@ import {import { notifyLauncherWindowRevealed } from './linux-launcher-ready'import { parseNvidiaDriverMajor, parseNvidiaDriverVersion } from './linux-nvidia-egl-fallback'import { createNvidiaEglRecovery } from './linux-nvidia-egl-recovery'+import { relaunchIfNoSandboxCameTooLate } from './linux-sandbox-relaunch'import { createLocalBackendLifecycle, waitForTeardown } from './local-backend-lifecycle'import { resolveIpcFileReadPath, resolveMediaStreamFile, resolvePreviewTargetPath } from './local-read-path'import { localSkinProfileKey, readLocalSkinPayload } from './local-skin'@@ -532,7 +533,7 @@ import {} from './remote-ws-headers'import { enableRendererAccessibility } from './renderer-accessibility'import { missingRendererAssets, presentRendererIndexes } from './renderer-bundle'-import { planLaunchSwitches, readDesktopLaunchConfig } from './renderer-heap-flags'+import { applyLaunchSwitches, readDesktopLaunchConfig } from './renderer-heap-flags'import { loadRendererLoadErrorPage } from './renderer-load-error-page'import { attachRendererConsoleCapture, formatRendererBoundaryReport } from './renderer-log'import { fetchRosterSourceData } from './roster-source-fetch'@@ -1278,17 +1279,12 @@ let desktopSshPathOverride = ''process.env.HERMES_DESKTOP_RENDERER_ACCESSIBILITY = '0'}- for (const planned of planLaunchSwitches(desktopLaunchConfig, process.argv.slice(1))) {- if (planned.value === undefined) {- app.commandLine.appendSwitch(planned.name)- } else {- app.commandLine.appendSwitch(planned.name, planned.value)- }+ applyLaunchSwitches(app.commandLine, desktopLaunchConfig, process.argv.slice(1))+}- console.log(- `[hermes] desktop launch switch from config.yaml: --${planned.name}${planned.value === undefined ? '' : `=${planned.value}`}`- )- }+// Linux: a runtime `--no-sandbox` kills renderers on /dev/shm (linux-sandbox-relaunch.ts).+if (isPrimaryInstance) {+ relaunchIfNoSandboxCameTooLate(app)}// ACTIVE_HERMES_ROOT — the canonical mutable Hermes install. Same pathdiff --git a/apps/desktop/electron/renderer-heap-flags.ts b/apps/desktop/electron/renderer-heap-flags.tsindex 85cbbbc57e4..81c62b78adf 100644--- a/apps/desktop/electron/renderer-heap-flags.ts+++ b/apps/desktop/electron/renderer-heap-flags.ts@@ -208,3 +208,22 @@ export function planLaunchSwitches(cfg: DesktopLaunchConfig, argv: readonly strireturn planned}++/** Apply {@link planLaunchSwitches} to the browser's command line, logging each switch. */+export function applyLaunchSwitches(+ commandLine: { appendSwitch(name: string, value?: string): void },+ cfg: DesktopLaunchConfig,+ argv: readonly string[]+): void {+ for (const planned of planLaunchSwitches(cfg, argv)) {+ if (planned.value === undefined) {+ commandLine.appendSwitch(planned.name)+ } else {+ commandLine.appendSwitch(planned.name, planned.value)+ }++ console.log(+ `[hermes] desktop launch switch from config.yaml: --${planned.name}${planned.value === undefined ? '' : `=${planned.value}`}`+ )+ }+}