Skip to content

The agent that grows with you

fix(desktop): say when the launch-config reader ignored a desktop block, and pair space-separated argv switches (#77311)

teknium15dd70d7cb656
diff --git a/apps/desktop/electron/renderer-heap-flags.test.ts b/apps/desktop/electron/renderer-heap-flags.test.ts
index 21b75d61cf5..0193181a72d 100644
--- a/apps/desktop/electron/renderer-heap-flags.test.ts
+++ b/apps/desktop/electron/renderer-heap-flags.test.ts
@@ -1,7 +1,7 @@
// #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 { describe, expect, it, vi } from 'vitest'
import { planLaunchSwitches, readDesktopLaunchConfig } from './renderer-heap-flags'
@@ -37,5 +37,29 @@ describe('renderer heap flags', () => {
// --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' }])
+
+ // Space-separated is the same switch: the argv value must reach the merge
+ // (and win the ceiling) rather than being scanned as a switch of its own.
+ expect(planLaunchSwitches(cfg, ['/app/hermes', '--js-flags', '--max-old-space-size=4096'])).toEqual([
+ { name: 'disable-gpu' },
+ { name: 'js-flags', value: '--max-old-space-size=4096' }
+ ])
+ })
+
+ it('warns once when a desktop block names the keys in an indentation it cannot read', () => {
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
+
+ // Valid YAML, unsupported subset (four-space keys / two-space list items).
+ expect(readDesktopLaunchConfig('desktop:\n renderer_max_old_space_mb: 2048\n')).toEqual({
+ electronFlags: [],
+ rendererMaxOldSpaceMb: 0
+ })
+ expect(warn).toHaveBeenCalledTimes(1)
+
+ // A desktop block that never mentions them is not a misconfiguration.
+ readDesktopLaunchConfig('desktop:\n font_family: ""\n')
+ expect(warn).toHaveBeenCalledTimes(1)
+
+ warn.mockRestore()
})
})
diff --git a/apps/desktop/electron/renderer-heap-flags.ts b/apps/desktop/electron/renderer-heap-flags.ts
index ce70ba77626..d499297f5f1 100644
--- a/apps/desktop/electron/renderer-heap-flags.ts
+++ b/apps/desktop/electron/renderer-heap-flags.ts
@@ -21,9 +21,13 @@ export interface PlannedSwitch {
/**
* 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.
+ * mapping with two-space-indented `electron_flags` (flow list, block list with
+ * four-space `- ` items, or one string) and `renderer_max_old_space_mb`
+ * (integer). Anything else keeps the defaults — a malformed config must never
+ * block the launch — but a `desktop:` block that clearly MEANT to set one of
+ * them and produced nothing warns once, because the failure is otherwise
+ * invisible (the app just launches with no heap ceiling). The supported shape
+ * is documented in `website/docs/user-guide/desktop.md`.
*/
export function readDesktopLaunchConfig(yamlText: string): DesktopLaunchConfig {
const out: DesktopLaunchConfig = { electronFlags: [], rendererMaxOldSpaceMb: 0 }
@@ -35,6 +39,9 @@ export function readDesktopLaunchConfig(yamlText: string): DesktopLaunchConfig {
}
const unquote = (raw: string) => raw.trim().replace(/^(['"])(.*)\1$/, '$2')
+
+ const blockLines: string[] = []
+
const splitFlow = (raw: string) =>
raw
.slice(1, -1)
@@ -49,6 +56,8 @@ export function readDesktopLaunchConfig(yamlText: string): DesktopLaunchConfig {
break // next top-level key
}
+ blockLines.push(line)
+
const keyed = /^ {2}([a-z_]+):\s*(.*?)\s*$/.exec(line)
if (!keyed) {
@@ -84,6 +93,23 @@ export function readDesktopLaunchConfig(yamlText: string): DesktopLaunchConfig {
}
}
+ if (out.electronFlags.length === 0 && out.rendererMaxOldSpaceMb === 0) {
+ // The parser is a deliberate subset, so a valid-YAML-but-unsupported shape
+ // (any indentation other than two-space keys / four-space `- ` items)
+ // yields nothing at all. Silence there reads as "the knob does not work";
+ // one line naming the supported shape is the difference between a five
+ // minute fix and a bug report.
+ const meantToSet = blockLines.some(line => /(electron_flags|renderer_max_old_space_mb)\s*:/.test(line))
+
+ if (meantToSet) {
+ console.warn(
+ '[hermes] config.yaml: desktop.electron_flags / desktop.renderer_max_old_space_mb were ignored — ' +
+ 'the launch reader supports only two-space-indented keys under a top-level `desktop:` with ' +
+ 'four-space `- ` list items (see the Desktop docs). Launching with Chromium defaults.'
+ )
+ }
+ }
+
return out
}
@@ -124,7 +150,25 @@ export function planLaunchSwitches(cfg: DesktopLaunchConfig, argv: readonly stri
}
}
- for (const arg of argv) {
+ for (let i = 0; i < argv.length; i += 1) {
+ const arg = String(argv[i] ?? '').trim()
+ const next = i + 1 < argv.length ? String(argv[i + 1] ?? '').trim() : ''
+ // `--name value` is as valid on a command line as `--name=value`. Scanning
+ // the two tokens independently dropped the value: `--js-flags
+ // --max-old-space-size=4096` registered a bare `js-flags` with no parts
+ // and a bogus `max-old-space-size` switch, so the config's ceiling
+ // replaced the launcher's instead of merging with it. `--js-flags` always
+ // takes a value (its own value is dash-prefixed), any other switch pairs
+ // only with a non-flag token.
+ const bareName = /^--([^=\s]+)$/.exec(arg)?.[1]
+
+ if (bareName && next && (bareName === 'js-flags' || !next.startsWith('-'))) {
+ consider(`${arg}=${next}`, true)
+ i += 1
+
+ continue
+ }
+
consider(arg, true)
}
diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md
index d8af24a33fa..216a9d3f47c 100644
--- a/website/docs/user-guide/desktop.md
+++ b/website/docs/user-guide/desktop.md
@@ -202,6 +202,17 @@ desktop:
`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.
+Both keys must be written exactly as shown — two spaces of indentation under a top-level `desktop:` key, and four spaces before the `-` of a block list:
+
+```yaml
+desktop:
+ electron_flags:
+ - "--ozone-platform=x11"
+ - "--js-flags=--expose-gc"
+```
+
+The pre-window reader is a small YAML subset, not the full parser the rest of Hermes uses, because it has to run before the app loads anything. Other indentations are valid YAML but are ignored here; when that happens the app logs `desktop.electron_flags / desktop.renderer_max_old_space_mb were ignored` at startup and launches with Chromium's defaults.
+
### 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.