Repository navigation
fix(electron): fail startup loudly on port errors and validate tray config - #4299
Conversation
…onfig If the desktop app couldn't reserve a free port it quietly started the backend on 4200, where another GAIA or any other process may already be listening, so the window could talk to the wrong server. It now stops with the startup error dialog instead. The tray settings handler crashed on a null payload, wrote any key the renderer sent into ~/.gaia/tray-config.json, and handed non-booleans to the OS login-item API; it now accepts only the three known settings and requires booleans. Fixes amd#4234
Verdict: Approve with suggestionsTwo real fail-loudly gaps get closed here: the desktop app no longer quietly starts the backend on 4200 when it can't reserve a port (it now stops with the branded error dialog), and the tray settings handler no longer crashes on a null payload, writes arbitrary renderer keys to disk, or hands non-booleans to the OS "start at login" API. The change is well-tested and the error message tells the user what to check and where the log is. One thing worth fixing before merge: the new tray validation also rejects values it finds already on disk. If a config file written by the old, unvalidated handler holds a wrong-typed setting, every future save fails with an error the user can't act on — tray settings become permanently unsavable. The PR description says stale junk from the old behaviour gets cleaned up on the next save; that holds for unknown keys, not for wrong-typed known ones. Sanitizing when the file is read fixes it in a few lines. Smaller: a comment elsewhere in the app still documents the port fallback this PR just deleted, and the neighbouring "GAIA backend not found" branch in the same function still degrades quietly rather than failing loudly — out of scope for the title, but worth a follow-up. Real-world evidenceNo I also reproduced the stale-config failure above with a scratch Jest case (non-boolean 🔍 Technical details🟡 ImportantStale non-boolean in
Validate where the untrusted bytes enter — keep the IPC handler strict about caller input, and repair the file at load with a warning: (replaces the 🟢 MinorStale JSDoc still documents the removed fallback ( Adjacent quiet-degradation branch left in place ( Strengths
|
… registration (amd#4338) Several Electron IPC tests passed without ever calling the handler with bad input. They only checked that a channel was registered, or they mocked out the method under test. A broken check would still pass: the updater could accept a path-traversal release tag, or the agent manager could spawn a process for an unknown id, with no test failing. These tests now call each handler the way the renderer does, pass malformed input, and assert that the call is rejected and nothing else happens. The install progress window had no tests at all and now has coverage. This PR changes tests only. Temporarily loosening the updater's tag regex fails 7 of the new tests, and removing the agent-id and URL-encoding guards fails 11. Tray-manager `tray:set-config` validation is left to amd#4299 and amd#4330, which already add those tests. ## Test plan - [x] `cd tests/electron && npm ci && npx jest` (26 suites, 770 tests pass on Node 20) - [x] Weaken `TAG_RE` in `auto-updater.cjs` to `/^v\d+\.\d+\.\d+/`: 7 new tag tests fail - [x] Remove the agent-id guard and `encodeURIComponent` in `agent-process-manager.cjs`: 11 new IPC tests fail Part of amd#4258 Co-authored-by: Kalin Ovtcharov <[email protected]>
A tray-config.json written by the old unvalidated handler could hold a non-boolean setting. _loadConfig blind-merged it, and the new set-config validation re-reads stored values for keys the payload omits — so every later save threw and tray settings became permanently unsavable. The renderer's get-config -> set-config round-trip hit it too, because get-config handed the bad value straight back. _loadConfig now keeps only boolean values for known keys, falls back to the default for anything else with a warning, and ignores a config file that isn't an object at all. Validation stays strict for caller input.
|
Fixed the bricking case: a tray setting already stored with the wrong type no longer blocks every future save. The new validation was right for what the renderer sends, but the config file is a second, untrusted input. Loading now repairs instead of trusting: a known key keeps its value only if it's a boolean, anything else falls back to the default with a warning, and a config file that isn't an object at all is ignored. Validation stays strict for caller input — nothing about the IPC boundary was loosened. Also merged current 🔍 Technical details
Five tests added to After the fix: The one The two 🟢 nits from the review (the stale JSDoc in |
) **Stacked on amd#4299 — merge that first.** This branch includes amd#4299's commit, so the diff will shrink to one commit once it lands. Before: agent settings saved in the desktop app's config dialog looked saved but were gone after a restart. The settings handler dropped them, nothing loaded them back at startup, and a failed disk write still reported success. After: the settings file validates and stores per-agent settings, the agent store loads them on startup, and the dialog closes only once the save has landed. If the save fails, the dialog stays open and shows the error. Note: the agent manager panel that hosts this dialog isn't mounted in the app yet, so there's no clickable golden path today. The fix is verified at the IPC, store, and component level. ## Test plan - [x] `cd tests/electron && npx jest` — 25 suites / 721 tests pass. The new `agent config persistence` cases (save → new TrayManager reads the file → same config, merge by id, validation, write failure) fail 10/10 without the fix. - [x] `cd src/gaia/apps/webui && npx vitest run` — 52 files / 403 tests pass. The new `agentStore.config.test.ts` fails 3/3 without the fix. - [x] `npx tsc --noEmit` and `npx vite build` pass Fixes amd#4300 --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
Before: if the desktop app couldn't reserve a free port, it quietly started the backend on 4200. If another process already held 4200, the backend failed to bind and the window talked to whatever was listening there. After: startup stops and shows the existing fatal error dialog, which says what failed and where the log is. Separately, the tray settings handler used to crash on a null payload, write any key the renderer sent into
~/.gaia/tray-config.json, and pass non-booleans to the OS "start at login" API. It now accepts only the three real settings and rejects anything that isn't a boolean.Unknown keys are dropped rather than rejected. The renderer sends back whatever
tray:get-configreturned, so junk keys already on disk from the old behaviour get cleaned up on the next save instead of breaking it. No overlap with #4186, which touches a different function inmain.cjs.Test plan
origin/main(10 failed / 25 passed):cd tests/electron && npx jest main-startup-order.test.cjs tray-manager.test.cjscd tests/electron && npm test: 25 suites, 710 tests passnode --test tests/electron/test_port_manager.mjs tests/electron/test_loadapp_query.mjs: 25 passFixes #4234