Skip to content

The agent that grows with you

fix(desktop): renderer heap ceiling and desktop.electron_flags reach packaged launches (#77311)

teknium17d2d63470808
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 553d2492af3..9808fdd9048 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -392,6 +392,7 @@ import {
resolveRemoteRequestHeaders
} from './remote-ws-headers'
import { missingRendererAssets } from './renderer-bundle'
+import { planLaunchSwitches, readDesktopLaunchConfig } from './renderer-heap-flags'
import { loadRendererLoadErrorPage } from './renderer-load-error-page'
import { attachRendererConsoleCapture, formatRendererBoundaryReport } from './renderer-log'
import { fetchRosterSourceData } from './roster-source-fetch'
@@ -881,6 +882,32 @@ function resolveHermesHome() {
const HERMES_HOME = resolveHermesHome()
+// #77311: `desktop.electron_flags` and the renderer heap ceiling
+// (`desktop.renderer_max_old_space_mb`) used to reach Chromium only through
+// the `hermes desktop` launcher's argv, so a packaged app opened from its
+// Start-menu / .desktop entry ran with no `--js-flags` at all. Apply them here
+// from config.yaml, before `ready` — Chromium copies `js-flags` to renderer
+// processes only from the browser's pre-launch command line.
+{
+ let desktopLaunchYaml = ''
+
+ try {
+ desktopLaunchYaml = fs.readFileSync(path.join(HERMES_HOME, 'config.yaml'), 'utf8')
+ } catch {
+ void 0 // first run: no config yet → Chromium defaults
+ }
+
+ for (const planned of planLaunchSwitches(readDesktopLaunchConfig(desktopLaunchYaml), process.argv.slice(1))) {
+ if (planned.value === undefined) {
+ app.commandLine.appendSwitch(planned.name)
+ } else {
+ app.commandLine.appendSwitch(planned.name, planned.value)
+ }
+
+ console.log(`[hermes] desktop launch switch from config.yaml: --${planned.name}${planned.value === undefined ? '' : `=${planned.value}`}`)
+ }
+}
+
function pathWithHermesManagedNode(...entries) {
const managed = hermesManagedNodePathEntries(HERMES_HOME).filter(directoryExists)
diff --git a/apps/desktop/electron/renderer-heap-flags.test.ts b/apps/desktop/electron/renderer-heap-flags.test.ts
new file mode 100644
index 00000000000..21b75d61cf5
--- /dev/null
+++ b/apps/desktop/electron/renderer-heap-flags.test.ts
@@ -0,0 +1,41 @@
+// #77311: the renderer heap ceiling knob (`desktop.renderer_max_old_space_mb`)
+// and `desktop.electron_flags` must reach app.commandLine on packaged launches
+// that never go through the `hermes desktop` launcher.
+import { describe, expect, it } from 'vitest'
+
+import { planLaunchSwitches, readDesktopLaunchConfig } from './renderer-heap-flags'
+
+describe('renderer heap flags', () => {
+ it('reads both launch keys from config.yaml and plans a well-formed js-flags switch', () => {
+ const cfg = readDesktopLaunchConfig(
+ [
+ 'model:',
+ ' default: x',
+ 'desktop:',
+ ' font_family: ""',
+ ' electron_flags:',
+ ' - --ozone-platform=x11',
+ ' - "--js-flags=--expose-gc"',
+ ' renderer_max_old_space_mb: 2048 # ceiling',
+ 'terminal:',
+ ' electron_flags: [--not-desktop]'
+ ].join('\n')
+ )
+
+ expect(cfg).toEqual({ electronFlags: ['--ozone-platform=x11', '--js-flags=--expose-gc'], rendererMaxOldSpaceMb: 2048 })
+ expect(planLaunchSwitches(cfg)).toEqual([
+ { name: 'ozone-platform', value: 'x11' },
+ { name: 'js-flags', value: '--expose-gc --max-old-space-size=2048' }
+ ])
+ // Default 0 = Chromium's own heap limit, nothing applied.
+ expect(planLaunchSwitches(readDesktopLaunchConfig('desktop:\n renderer_max_old_space_mb: 0\n'))).toEqual([])
+ })
+
+ it('merges with a js-flags switch already on argv instead of overwriting it', () => {
+ const cfg = readDesktopLaunchConfig('desktop:\n electron_flags: [--disable-gpu]\n renderer_max_old_space_mb: 1536\n')
+ const planned = planLaunchSwitches(cfg, ['/app/hermes', '--js-flags=--expose-gc', '--disable-gpu'])
+
+ // --disable-gpu is already on the launcher's argv: not re-applied.
+ expect(planned).toEqual([{ name: 'js-flags', value: '--expose-gc --max-old-space-size=1536' }])
+ })
+})
diff --git a/apps/desktop/electron/renderer-heap-flags.ts b/apps/desktop/electron/renderer-heap-flags.ts
new file mode 100644
index 00000000000..ce70ba77626
--- /dev/null
+++ b/apps/desktop/electron/renderer-heap-flags.ts
@@ -0,0 +1,146 @@
+// Renderer heap ceiling + `desktop.electron_flags` for packaged launches (#77311).
+//
+// Chromium only forwards `--js-flags` to renderer processes when the BROWSER
+// process has the switch on its own command line before `ready`. The
+// `hermes desktop` launcher appends `desktop.electron_flags` to argv, but a
+// packaged app started from its Start-menu / .desktop entry never runs that
+// launcher, so the config key was dead there and the renderer had no heap
+// ceiling at all. This module is pure (no Electron import) so the switch
+// planning is vitest-able; main.ts applies the result via app.commandLine.
+
+export interface DesktopLaunchConfig {
+ electronFlags: string[]
+ rendererMaxOldSpaceMb: number
+}
+
+export interface PlannedSwitch {
+ name: string
+ value?: string
+}
+
+/**
+ * Read the two launch keys out of `config.yaml` text without a YAML parser
+ * (the main bundle ships none). Deliberately narrow: a top-level `desktop:`
+ * mapping with two-space-indented `electron_flags` (flow list, block list or
+ * one string) and `renderer_max_old_space_mb` (integer). Anything else keeps
+ * the defaults — a malformed config must never block the launch.
+ */
+export function readDesktopLaunchConfig(yamlText: string): DesktopLaunchConfig {
+ const out: DesktopLaunchConfig = { electronFlags: [], rendererMaxOldSpaceMb: 0 }
+ const lines = String(yamlText ?? '').split(/\r?\n/)
+ const start = lines.findIndex(line => /^desktop:\s*(#.*)?$/.test(line))
+
+ if (start < 0) {
+ return out
+ }
+
+ const unquote = (raw: string) => raw.trim().replace(/^(['"])(.*)\1$/, '$2')
+ const splitFlow = (raw: string) =>
+ raw
+ .slice(1, -1)
+ .split(',')
+ .map(unquote)
+ .filter(Boolean)
+
+ for (let i = start + 1; i < lines.length; i += 1) {
+ const line = lines[i]
+
+ if (/^\S/.test(line)) {
+ break // next top-level key
+ }
+
+ const keyed = /^ {2}([a-z_]+):\s*(.*?)\s*$/.exec(line)
+
+ if (!keyed) {
+ continue
+ }
+
+ const [, key, rawValue] = keyed
+ const value = rawValue.replace(/\s+#.*$/, '')
+
+ if (key === 'renderer_max_old_space_mb') {
+ const mb = Number.parseInt(unquote(value), 10)
+ out.rendererMaxOldSpaceMb = Number.isFinite(mb) && mb > 0 ? mb : 0
+ } else if (key === 'electron_flags') {
+ if (value.startsWith('[') && value.endsWith(']')) {
+ out.electronFlags = splitFlow(value)
+ } else if (value) {
+ out.electronFlags = unquote(value).split(/\s+/).filter(Boolean)
+ } else {
+ const items: string[] = []
+
+ for (let j = i + 1; j < lines.length; j += 1) {
+ const item = /^ {4}- (.*)$/.exec(lines[j])
+
+ if (!item) {
+ break
+ }
+
+ items.push(unquote(item[1]))
+ }
+
+ out.electronFlags = items.filter(Boolean)
+ }
+ }
+ }
+
+ return out
+}
+
+/**
+ * Plan the `app.commandLine.appendSwitch` calls for a launch.
+ *
+ * Every `--js-flags` source (an existing switch on `argv`, entries in
+ * `electron_flags`, and the typed `renderer_max_old_space_mb`) is MERGED into a
+ * single `js-flags` switch — appendSwitch replaces, so applying them one by
+ * one would silently drop all but the last. Other `--name[=value]` entries
+ * pass through as their own switches. Flags already present on `argv` are not
+ * re-applied (the `hermes desktop` launcher put them there).
+ */
+export function planLaunchSwitches(cfg: DesktopLaunchConfig, argv: readonly string[] = []): PlannedSwitch[] {
+ const jsFlagParts: string[] = []
+ const others: PlannedSwitch[] = []
+ const argvSwitches = new Set<string>()
+
+ const consider = (flag: string, fromArgv: boolean) => {
+ const match = /^--([^=\s]+)(?:=(.*))?$/.exec(flag.trim())
+
+ if (!match) {
+ return
+ }
+
+ const [, name, value] = match
+
+ if (name === 'js-flags') {
+ jsFlagParts.push(...String(value ?? '').split(/\s+/).filter(Boolean))
+
+ return
+ }
+
+ if (fromArgv) {
+ argvSwitches.add(name)
+ } else if (!argvSwitches.has(name)) {
+ others.push(value === undefined ? { name } : { name, value })
+ }
+ }
+
+ for (const arg of argv) {
+ consider(arg, true)
+ }
+
+ for (const flag of cfg.electronFlags) {
+ consider(flag, false)
+ }
+
+ if (cfg.rendererMaxOldSpaceMb > 0 && !jsFlagParts.some(part => part.startsWith('--max-old-space-size='))) {
+ jsFlagParts.push(`--max-old-space-size=${Math.floor(cfg.rendererMaxOldSpaceMb)}`)
+ }
+
+ const planned = [...others]
+
+ if (jsFlagParts.length > 0) {
+ planned.push({ name: 'js-flags', value: Array.from(new Set(jsFlagParts)).join(' ') })
+ }
+
+ return planned
+}
diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.py
index 9a7714c8878..2fad56b30c2 100644
--- a/hermes_cli/config_defaults.py
+++ b/hermes_cli/config_defaults.py
@@ -2502,6 +2502,10 @@ DEFAULT_CONFIG = {
# Extra Electron flags per launch, e.g. ["--ozone-platform=x11"] or GPU workarounds. List of
# strings; a single string is shell-split.
"electron_flags": [],
+ # V8 old-space ceiling (MB) for the renderer, applied as --js-flags=--max-old-space-size=N by
+ # the app itself (also for Start-menu / .desktop launches). 0 = Chromium's default limit.
+ # A ceiling turns a machine-wide freeze into a bounded renderer reload (#77311).
+ "renderer_max_old_space_mb": 0,
# Linux Ozone backend, bridged to ELECTRON_OZONE_PLATFORM_HINT (explicit env wins). auto =
# Chromium default; x11 = XWayland, for compositors that ignore always-on-top for Wayland
# clients (e.g. COSMIC) — also puts the HUD on the solid-window input path; wayland = force
diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md
index 408cd8e2ba2..d8af24a33fa 100644
--- a/website/docs/user-guide/desktop.md
+++ b/website/docs/user-guide/desktop.md
@@ -190,6 +190,18 @@ Under local WSLg, Hermes launches with `--ozone-platform=wayland` to avoid the X
When `hermes gui` runs inside WSL2 with `/dev/dxg` present and Mesa's `d3d12_dri.so` installed, the launcher sets `GALLIUM_DRIVER=d3d12` for Electron so rendering uses the Windows GPU instead of the llvmpipe software rasterizer; an explicit `GALLIUM_DRIVER`, `MESA_LOADER_DRIVER_OVERRIDE`, `LIBGL_ALWAYS_SOFTWARE`, or `LIBGL_DRIVERS_PATH` in your environment is left untouched (for example `GALLIUM_DRIVER=llvmpipe hermes gui` keeps software rendering).
+#### Launch flags and the renderer heap ceiling
+
+Two `desktop.*` keys reach Chromium at launch on every path — `hermes desktop`, the Start-menu shortcut and the Linux `.desktop` entry alike (the app reads them from `config.yaml` before its first window opens):
+
+```yaml
+desktop:
+ electron_flags: ["--ozone-platform=x11"] # extra Chromium switches; a single string is split on spaces
+ renderer_max_old_space_mb: 2048 # V8 heap ceiling for the chat renderer; 0 = Chromium default
+```
+
+`renderer_max_old_space_mb` is applied as `--js-flags=--max-old-space-size=N` and merged with any `--js-flags` you already pass, so neither overwrites the other. Set it when a very long, tool-heavy session drives the renderer past what the machine can spare: the renderer then hits its own limit and reloads (bounded to three reloads per minute) instead of freezing the whole machine.
+
### Settings & onboarding
Manage providers, models, tools, and credentials from a real UI instead of editing YAML. First-run onboarding gets you to your first message in seconds. The settings panes cover providers/keys, model selection, toolset configuration, MCP servers, the gateway, and session management.