Skip to content

fix(webui): persist agent settings across desktop app restarts - #4330

Merged
kovtcharov-amd merged 5 commits into
amd:mainfrom
kovtcharov:claude/electron-agent-config-persist
Sep 26, 2026
Merged

kovtcharov-amd merged 5 commits into
amd:mainfrom
kovtcharov:claude/electron-agent-config-persist

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Stacked on #4299 — merge that first. This branch includes #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

  • 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.
  • 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.
  • npx tsc --noEmit and npx vite build pass

Fixes #4300

Kalin Ovtcharov added 2 commits September 24, 2026 22:50
…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
Agent settings saved from the desktop app's config dialog now survive a
restart. The settings handler only stored the tray section, so the agents
section was dropped, and nothing loaded agent settings back at startup.

- tray:set-config validates and stores an `agents` section (merged by agent
  id, unknown keys dropped); a bad payload writes nothing.
- A failed write now rejects instead of logging and reporting success, and
  the in-memory config only changes once the file is written.
- The agent store loads saved settings when the agent manager mounts, and
  the dialog closes only after the save lands, showing the error otherwise.

Fixes amd#4300
@github-actions github-actions Bot added the tests Test changes label Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This fixes a real, user-visible bug the right way: agent settings now actually reach the desktop app's settings file, get loaded back at startup, and the dialog stays open with a visible error when the write fails instead of pretending it worked. The port-failure and tray-payload hardening that rides along is the same spirit — fail loudly rather than quietly substitute a default.

One thing worth fixing before merge: the settings file loader is strict on the way in but silent on the way out. If the agents section is ever unreadable — hand-edited, or written by a future version that adds a required field — the app throws that away along with the user's tray preferences, resets everything to defaults with only a console warning, and the next save overwrites the file. A user who never touched agent settings loses "start minimized" and "start on login". The fix is to reject only the bad section and keep the rest, and to say so loudly.

Smaller items (details below): a couple of now-unused store actions that would silently reintroduce the old non-persisting behaviour if someone reached for them, an error banner shared with the agent list that can show a stale unrelated message when the dialog opens, and one settings key the type system advertises but the settings handler quietly drops.

Real-world evidence

No evidence-bundle.md was produced for this PR, so this verdict rests on static review plus the author's stated test runs. The PR description marks the UI golden path N/A with a reason — the agent manager panel that hosts this dialog isn't mounted in the app yet, so there's nothing clickable to screenshot — and reports the Electron (721 tests), vitest (403 tests), tsc --noEmit and vite build runs green, with the new cases failing 13/13 without the fix. That's the right substitute for an unmounted surface, and the new tests do assert the thing that was broken (write → fresh manager → read back). I could not re-run them here: this lane has no node_modules installed for src/gaia/apps/webui or tests/electron, so I did not verify the numbers myself. When the panel does get mounted, the screenshot evidence is still owed.

🔍 Technical details

Issues

🟡 A single bad agents entry silently resets every setting (src/gaia/apps/webui/services/tray-manager.cjs:277)

validateAgents now runs inside the existing try in _loadConfig, so a TypeError from one malformed agent entry lands in the catch at :280 and the method returns { ...DEFAULT_CONFIG } — discarding tray.minimizeToTray, startMinimized and startOnLogin too. The very next tray:set-config persists those defaults over the file, so the loss is permanent. The most likely trigger isn't corruption but version skew: the validator requires autoStart, restartOnCrash and logLevel on every entry, so the next release that adds a fourth required field makes every existing settings file unloadable. Scope the failure to the section that failed, and log it at error level rather than console.warn:

  _loadConfig() {
    let loaded = null;
    try {
      if (fs.existsSync(CONFIG_PATH)) {
        loaded = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf8"));
      }
    } catch (err) {
      console.warn("[tray] Could not load tray config:", err.message);
    }
    if (!isPlainObject(loaded)) return { ...DEFAULT_CONFIG, agents: {} };

    let agents = {};
    try {
      agents = validateAgents(loaded.agents ?? {}, CONFIG_PATH);
    } catch (err) {
      console.error(
        `[tray] Ignoring invalid agents section in ${CONFIG_PATH}: ${err.message}`
      );
    }
    return {
      ...DEFAULT_CONFIG,
      ...loaded,
      tray: { ...DEFAULT_CONFIG.tray, ...(loaded.tray || {}) },
      agents,
    };
  }

Worth a test alongside the existing agents cases: a file with one invalid entry keeps tray.minimizeToTray: false.

🟢 setConfig / setConfigs are now dead and bypass persistence (src/gaia/apps/webui/src/stores/agentStore.ts:158, :163). With the dialog moved to saveConfig, nothing calls them — but they remain on the public store interface as the in-memory-only write that caused #4300. Either delete them or leave a one-line comment pointing callers at saveConfig.

🟢 The dialog's error banner shows unrelated errors (src/gaia/apps/webui/src/components/AgentConfigDialog.tsx:206). lastError is shared with AgentManager, which sets it on start/stop failures (AgentManager.tsx:153 renders the same class). Open the config dialog after a failed startAgent and the stale message appears as a save error; conversely a failed save leaves the text on the manager banner after the dialog closes. saveConfig clears it on entry, so the narrow fix is clearing it on mount too:

  useEffect(() => {
    useAgentStore.setState({ lastError: null });
  }, []);

🟢 showNotificationBadge is typed but silently dropped (src/gaia/apps/webui/src/types/agent.ts:166). TrayConfigUpdate lets a caller send it, but the handler now whitelists Object.keys(DEFAULT_CONFIG.tray) (tray-manager.cjs:321), which doesn't include it — so it type-checks and vanishes. Nothing sends it today; remove it from the type, or add it to DEFAULT_CONFIG.tray.

🟢 loadConfigs trusts persisted.agents to exist (agentStore.ts:169). The bundled main process always supplies it, so this is defensive only, but set({ configs: persisted.agents ?? {} }) keeps a undefined from turning every later configs[agentId] read into a crash.

Strengths

  • The tests assert the behaviour that was actually broken, not the implementation: write via IPC → construct a fresh TrayManager → read the file back. That's the restart the bug report described, and the merge-by-id and write-failure cases cover the two ways the old code went wrong.
  • saveConfig returning a boolean the dialog awaits is the right shape — closing on a resolved persist rather than optimistically, so a failed write can't masquerade as a save.
  • The startBackend change and the tray:set-config whitelist both replace a quiet default with an actionable error naming the cause, the user action, and the log path — exactly the fail-loudly rule in CLAUDE.md.

pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Sep 25, 2026
… 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]>
The agents validator ran inside the try that guards reading the settings
file, so a single malformed agent entry threw all the way out and the loader
returned bare defaults -- discarding minimize-to-tray, start-minimized and
start-on-login along with it. The next save wrote those defaults back, so a
user who never opened agent settings lost their tray preferences for good.
Version skew was the likely trigger: the validator requires every key it
knows about on every entry, so adding a required field would make existing
settings files unloadable.

Validation is now scoped to the section that failed. A bad agents section is
dropped with an error naming the file and the reason; tray settings survive.
A non-object tray section falls back the same way without touching agents.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Fixed the settings-reset bug from the review: one malformed agent entry no longer wipes the user's tray preferences. Validation is now scoped to the section that failed, so a bad agents section is dropped with an error naming the file and the reason while minimize-to-tray, start-minimized and start-on-login survive.

Still stacked — #4299 has not merged. It is open with no merge commit, so the branch still carries its commit and the diff will only shrink once it lands.

🔍 Technical details

validateAgents ran inside the try guarding the file read, so its TypeError hit the same catch and _loadConfig returned { ...DEFAULT_CONFIG }. The next tray:set-config persisted those defaults, making the loss permanent. Version skew was the more likely trigger than corruption — the validator requires every key it knows about on every entry, so a future release adding a required field would make every existing settings file unloadable.

_loadConfig now parses first, then validates agents in its own try, logging at console.error with the path and reason. A non-object tray section falls back through isPlainObject the same way instead of being spread (a string would have spread character-by-character). The no-file and non-object-file paths return fresh tray/agents objects rather than aliasing DEFAULT_CONFIG's.

Two tests in tests/electron/tray-manager.test.cjs, both failing without the fix:

  • a malformed agents section on disk keeps the tray settings — asserts minimizeToTray: false and startMinimized: true survive, agents is {}, and the error is logged.
  • a non-object tray section falls back without losing agents — the mirror case.

Tests: cd tests/electron && npx jest → 26 suites, 794 passed, 1 skipped (post-merge with main, 64 commits, no conflicts). I could not run vitest — src/gaia/apps/webui/node_modules is not installed in this lane, so the agentStore.config.test.ts numbers in the test plan are unverified here.

Not addressed, all 🟢 from the review: the dead setConfig/setConfigs store actions, the lastError banner shared with AgentManager, showNotificationBadge being typed but dropped, and loadConfigs trusting persisted.agents.

# Conflicts:
#	src/gaia/apps/webui/services/tray-manager.cjs
#	tests/electron/tray-manager.test.cjs
kovtcharov-amd pushed a commit to kovtcharov/gaia that referenced this pull request Sep 26, 2026
…imports (amd#4360)

About 6,700 lines of code had no caller. One file couldn't even be
imported, yet CLAUDE.md still listed it as "Shell integration". The dead
code kept stale behaviour looking alive, like `rag/demo.py` printing
`gaia rag` commands that don't exist, and it cost reviewers time. This
PR deletes six of the items from amd#4243. It also adds a test that imports
every module under `src/gaia`, so an unimportable file now fails CI
instead of lingering. The test fails on current `main`: it flags
`shell/prompt.py` and the three uncollected mic scripts.

Left for a maintainer decision:
- `src/gaia/eval/model_comparison.py`: it has no caller, but amd#3741
merged it yesterday as a library building block, with CLI wiring planned
as a follow-up.
- `governance/`, `talk/app.py` (amd#4333) and the webui AgentManager panel
(amd#4330) were excluded.

`docs/plans/cpp-framework-parity.md` still calls the C++ plan resolver
dead code to resolve. I left it alone because amd#3812 deletes that file.

<details>
<summary>🔍 Technical details</summary>

- Deleted: `src/gaia/shell/`, `rag/demo.py`, `rag/app.py` + `rag_main`
export, `audio/tests/*.py`, `eval/longthread_quality.py` + its test and
fixture, `hub/agents/email/node/`, `Agent::resolvePlanParameters` (+
decl, + now-unused `<regex>` include).
- Two `rag_app` tests in `test_rag_index_status.py` went with
`rag/app.py`. The chat/talk/file-monitor index-status tests stay.
- `thread_fold` keeps its own coverage in
`hub/agents/email/python/tests/test_thread_fold*.py`.
- The import test's allowlist is keyed on the *missing package* (`mcp`,
`reportlab`), not the module. An allowlisted module still fails if it
breaks another way, and a second test checks each allowlisted package is
an optional extra in `setup.py`, not a base dependency. Loose `.py`
files outside a package are loaded by path, so broken relative imports
fail too.
- A CI-equivalent venv (`.[api]` + the unit job's test deps) flags only
`mcp` and `reportlab` today, and the sweep takes ~7 s cold. No module
does an unguarded platform-only import at top level, so the Windows
smoke lane should match. That lane is not verified locally.
- No open PR modifies a deleted file. amd#4260 edits the chat agent's
`app.py`, not `src/gaia/rag/app.py`.
</details>

## Test plan

- [x] `pytest tests/unit/test_import_all_modules.py`: fails on
`origin/main` (shell/prompt.py + 3 mic scripts). It also fails with
prompt_toolkit installed (broken relative import) and with an
`__init__.py` added (`gaia.shell.commands` missing). Passes on this
branch in both the full dev venv and a `.[api]`-only venv.
- [x] `pytest tests/unit/test_rag_index_status.py
tests/unit/test_packaging.py tests/unit/test_model_comparison.py
tests/unit/email tests/unit/rag tests/test_rag.py`: 296 passed, 9
skipped
- [x] `pytest tests/unit` (`.[api]` venv): 14422 passed. The 23 failures
(`test_cli_smoke`, `test_uninstall_command`, `test_lemonade_asr`) also
fail on `origin/main` in the same env.
- [x] C++: `cmake -S cpp -G Ninja && cmake --build` builds clean, and
`tests_mock` passes 1002/1002
- [x] black, isort, pylint (CI flags) on the changed Python files
- [ ] Windows and macOS unit smoke lanes pass (CI)

Part of amd#4243

Co-authored-by: Kalin Ovtcharov <[email protected]>
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 26, 2026
Merged via the queue into amd:main with commit b989d3f Sep 26, 2026
47 of 49 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the claude/electron-agent-config-persist branch September 26, 2026 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(webui): agent settings saved in the desktop app are lost on restart

2 participants