Skip to content

fix(desktop): crash dialog restarts or quits, quit no longer hangs - #5537

Merged
kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:kalin/desktop-crash-quit-fixes
Oct 23, 2026
Merged

kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:kalin/desktop-crash-quit-fixes

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

When GAIA's background service crashed, the dialog's Quit only closed the dialog and left a dead window, and its log tail was full of colour-code junk. Quitting with nothing left to clean up could hang, and a failed install offered "Install uv" for failures that had nothing to do with uv. Now every crash-dialog choice ends somewhere (Restart GAIA, Save diagnostics, Quit), quit always exits, install-failure dialogs offer only actions that fit the failure, and the crash and Lemonade-choice dialogs open in front of GAIA's window instead of behind it. Exporting a file also opens a Save dialog titled "Save from GAIA" instead of one named after an internal blob: URL.

Crash dialog: Restart GAIA, Save diagnostics, Quit
Install failed: no uv button for a non-uv failure

Test plan

  • cd tests/electron && npx jest --ci: 1113 passed. The one failure is the ChatView size check on a CRLF checkout (101,751 bytes with LF; this PR doesn't touch ChatView).
  • Killed the backend in a running app: the dialog shows plain log lines; Restart GAIA relaunches a single app and Quit exits (Save diagnostics' write-then-ask-again loop is unit-tested).
  • Pointed the installer at a missing wheel: the failure dialog offers Retry / Manual install instructions / Copy log path / Open log file / Quit, with no uv button.
  • Quit after the backend is already gone (nothing to clean up): the process exits instead of hanging.
  • Linux AppImage: Restart GAIA relaunches from the AppImage file (unit-tested via relaunchOptions; not run on Linux).
🔍 Technical details
  • Quit hang: Electron drops an app.quit() issued in the same tick as the will-quit that started cleanup; the re-quit now waits one setImmediate.
  • The crash dialog moved to services/backend-crash-dialog.cjs so it can be tested without Electron; the log tail is the last 8 lines, ANSI stripped.
  • An AppImage relaunches with execPath: $APPIMAGE; its own mount is gone once the app exits.
  • "Install uv (auto)" shows only when the failing stage is ensure-uv.
  • The crash dialog takes parent: mainWindow (restored and focused first); with no live window it shows unowned. The will-download title handler is registered once on session.defaultSession, since createWindow reruns on every macOS reopen.

…nstall dialogs fit the failure

When GAIA's backend died, the crash dialog's "Quit" did nothing, left the app
running with no backend, and its log tail showed raw colour codes. Its
replacement offers Restart GAIA / Save diagnostics / Quit, and each one ends
in a restart or a quit.

- Quit after a backend crash used to hang for good: with nothing left to stop,
  cleanup resolved in the same tick as the prevented will-quit, and Electron
  dropped the re-quit. The re-quit now waits a task.
- The install-failure dialog offers "Install uv (auto)" only when uv is what
  failed; every other failure defaults to Retry.
- The "Lemonade Server found" question is modal to the progress window and
  brought to the front, so it can't open hidden while the install waits at 70%.
- A chat export's Save dialog is titled "Save from GAIA", not after a blob: URL.
- Restart after a crash relaunches the AppImage file itself; its temporary
  mount is gone once the app exits, so relaunching process.execPath would
  only quit.
- The crash dialog shows the last 8 log lines, so it fits on screen.
- "Install uv" is offered only for the ensure-uv stage, the one that exists.
@github-actions github-actions Bot added the tests Test changes label Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

Every button in the desktop crash dialog now does something: Restart GAIA, Save diagnostics, or Quit. Quit no longer hangs when there is nothing left to clean up. The install-failure dialog only offers "Install uv" when uv is what failed, and the Lemonade question opens in front of the progress window. The logic is right and each fix has a focused unit test. Nothing blocks the merge.

Two small things to look at:

  • The PR also renames the browser's Save dialog for exports, which the description doesn't mention. On macOS that handler is added again each time the window is reopened.
  • The crash dialog has no parent window, so it can still open behind other windows. That's the same problem this PR fixes for the Lemonade question.

Real-world evidence

N/A here: no evidence bundle was produced for this run. The verdict rests on reading the code and on the author's evidence. The PR description embeds screenshots of the new crash dialog and the install-failure dialog, and its test plan records manual runs of crash → Restart/Quit, a missing-wheel install failure, and quit with no backend left. The Linux AppImage relaunch is unit-tested only and is still unchecked in the test plan.

🔍 Technical details

Issues found

🟢 The will-download listener piles up on the shared session (main.cjs:595). createWindow() is called again from reopenWindow() (macOS dock/tray), and every call adds another listener to the default session. Each one sets the same options, so the result is still correct, but after about 10 reopens Node prints a MaxListeners warning. Either register it once in app.whenReady, or guard it:

  if (!mainWindow.webContents.session.listenerCount("will-download")) {
    mainWindow.webContents.session.on("will-download", (_event, item) => {
      item.setSaveDialogOptions({
        title: "Save from GAIA",
        defaultPath: path.join(app.getPath("downloads"), item.getFilename()),
      });
    });
  }

Also add a line about this change to the PR description, since it's a separate user-visible behaviour.

🟢 The crash dialog has no parent window (services/backend-crash-dialog.cjs:55). dialog.showMessageBox(opts) is called without an owner, so when GAIA isn't focused the dialog can open behind other windows. A parent dependency, with mainWindow passed from handleBackendCrash, would keep it in front, the same way chooseLemonadeInDialog now does.

Strengths

  • Pulling the crash dialog into services/backend-crash-dialog.cjs with injected dialog/app/env makes it testable without Electron. The tests cover all three buttons, the failed diagnostics write, ANSI stripping, and the AppImage relaunch path.
  • The quit-hang fix includes a test that models how Electron drops a re-quit in the same tick. The fake-timer tests were updated to advance the extra setImmediate instead of being loosened.
  • Choosing the failure-dialog action from an actions table instead of fixed button indexes keeps defaultId/cancelId correct when "Install uv" is left out. The new tests check both layouts.

The backend-crash dialog had no owner window, so it could open behind
other apps. It is now modal to the main window and brings it forward.
The Save-dialog title for exports is registered once on the default
session instead of on every window reopen, which piled up listeners on
macOS.
@kovtcharov

Copy link
Copy Markdown
Contributor Author

Both suggestions are in: the crash dialog now opens in front of GAIA's window, and the export Save-dialog title is set up once instead of on every window reopen. The description now mentions the Save-dialog title change. The red macOS unit-test job is a timing flake in an unrelated file-lock test, not this PR.

🔍 Technical details
  • showBackendCrashDialog takes parent. handleBackendCrash passes mainWindow. A live window is restored, shown and focused, and every box (the crash box and "Diagnostics saved") is modal to it. With no window, or a destroyed one, the dialog shows unowned. New tests in backend-crash-dialog.test.cjs cover both cases.
  • will-download moved out of createWindow into titleDownloadSaveDialogs(). It registers on session.defaultSession and is called once in whenReady. Source tests in main-dialog-owner.test.cjs pin one registration and the crash dialog's parent: mainWindow.
  • CI: test_file_lock.py::test_the_next_waiter_takes_the_lock_within_milliseconds failed with a median of 8.1 ms against a 5 ms wall-clock limit on the shared macOS runner. The same test failed the same way on kalin/awake-clock-s0ix and feat/eval-quota-resume. It passes locally, and this PR touches no Python. The new push re-runs CI.
  • Local: npx jest --ci gives 1113 passed. The one failure is the ChatView size check on a CRLF checkout (101,751 LF bytes, under 102,400). util/lint.py --black --isort is clean.

kovtcharov-amd pushed a commit that referenced this pull request Oct 23, 2026
…5610)

Four timing-sensitive unit tests failed 8 unrelated PRs this week
(#5537, #5539, #5562, #5563, #5564, #5565, #5566, #5568) and one of
main's last 11 completed runs. Each still guards the same bug, but no
longer races the clock on a busy runner. Every rewritten test was
checked by breaking the code: it fails on the real bug and passes 50/50
runs, including under full CPU load. The PR also keeps three tests out
of the developer's real `~/.gaia`.

## Test plan
- [x] `pytest tests/unit/mcp/client/test_stdio_hung_server.py
tests/unit/test_file_lock.py tests/unit/test_mcp_bridge_concurrency.py
tests/unit/chat/ui/test_agent_model_override.py
tests/integration/test_folder_indexing.py -n 4`: 316 passed, 3 skipped
- [x] The four de-flaked tests, run 50x each: 250/250 serial, and
250/250 under xdist (32 workers) with all 32 cores also running busy
loops. Main's versions in that same loaded run: redaction failed 10/50.
- [x] Each test fails when its bug is put back in the code (see details)
- [x] `tests/integration/test_folder_indexing.py -n 4`, 5 runs: all
pass. Main's version fails 7 to 9 tests per run.
- [x] Test 841 passes with `GAIA_HOME` set to a temp dir. Main's version
fails.
- [x] Electron `npx jest`: 1098 passed. The one failure,
`test_electron_chat_installer.js` (component size 103,725 > 102,400),
also fails on main and is unrelated.
- [ ] CI green on Linux, macOS and Windows unit lanes

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

**`test_redaction_stays_fast_on_dense_escapes`** (Linux, 2.01 to 2.03 s
against a 2 s limit)
- Cause: an absolute 2 s bound. Locally the worst text takes 0.19 s. On
a 4-worker, coverage-traced runner it took about 10x that.
- Fix: time one 1M-char text against eight 125K texts with the same
total length, on the same machine. Linear code scores about 1.0 and a
quadratic scan scores 8, so the test asserts < 3. It takes the best of
up to three paired runs, and uses the lower of the wall-clock and CPU
(`thread_time`) ratios. Contention inflates wall time, and Windows
samples CPU time on ticks. The test also fails if the 1M text takes more
than 15 s of CPU, which catches a per-position rescan: that is linear
but takes minutes.
- Break checks: a quadratic prefix copy in `_candidate_windows`
(`len(text[:start].rstrip("\\"))`) gives a ratio of 5.9x and the test
fails. Main's 2 s test passed that same regression locally (1.57 s). A
per-anchor rescan without merging takes 56 s and hits the 15 s ceiling.

**`test_children_of_an_exited_server_are_still_stopped`** (Linux)
- Cause: the test slept a fixed 2 s for the child watcher. The watcher
backs off (0.5, 1, 2, 4 s…), so on a slow start its next scan came after
the launcher had exited and the child was never recorded.
- Fix: poll until `child_pid in transport._children`, with a deadline of
3 × `_CHILD_SCAN_MAX_S`.
- Break checks: never recording children fails with "never recorded".
Clearing `_children` before stopping fails with "kept running". Delaying
the watcher's first scan by 2.5 s reproduces the CI failure on main's
test, and the new test passes.
- Note for the product side: a launcher that spawns a child and exits
inside a backoff window still orphans that child. Real `npx`/`uvx`
launchers outlive the window.

**`test_the_next_waiter_takes_the_lock_within_milliseconds`** (macOS,
median 6.5 to 8.1 ms against 5 ms)
- Cause: macOS stretches `sleep(0.001)` under load, and the 5 ms median
left no headroom.
- Fix: the test wraps `_poll_interval`, which records each interval and
signals the moment the waiter starts a poll's sleep. The lock is
released right then, so the whole interval stands between the waiter and
the lock.
- Assertions: every interval the front waiter asks for is ≤ 2 ms, and
the median hand-off is < 15 ms. A 20 ms poll always waits at least 20
ms, so it fails the median even with the bound widened.
- Break checks: `_NEXT_POLL_SECONDS = 0.02` or `0.1` fails the interval
assertion. Sleeping `_POLL_SECONDS` directly, so `_poll_interval` is
bypassed, fails the median (20.8 ms).

**`test_a_dropped_idle_connection_is_logged[True]`** (Linux)
- Cause: the test asserted that `"Traceback"` was absent from the stderr
captured by `capsys`. The traceback in that run came from a fake
Lemonade server that `test_lemonade_shared_server.py` left running on
the same xdist worker (`BrokenPipeError`).
- Fix: the `serve` fixture records the bridge server's own
`handle_error` calls, and the test asserts that list is empty.
socketserver calls `handle_error` before it closes the connection, so
the check doesn't race. A plugin that writes a traceback to stderr
during the test fails main's version and passes the new one.
- Break check: making `log_error` also call the base `log_error`, and
reverting `str(args[0])`, raises `TypeError` in the handler, and the
test fails.

**Isolation fixes**
- `test_folder_indexing.py`: `temp_folder` now lives in
`isolated_gaia_home`, a per-test fake home, so `ensure_within_home`
still admits it. Parallel workers no longer share or delete
`~/.gaia/test_temp`.
- `test_issue_841…`: the test now sets `GAIA_HOME` itself, so an
inherited value can't override the patched `Path.home`.
- `tests/electron/setup.js`: `os.homedir()` points at a per-file temp
dir. It is assigned rather than spied, so `jest.restoreAllMocks()` can't
undo it. Setting `HOME` would not work, because Jest's sandboxed
`process.env` never reaches `os.homedir()`.
- The "Ignoring invalid agents section in …\.gaia\tray-config.json" log
came from `crash-loop-notification.test.cjs`, which mocks `fs` with a
config the validator rejects. The real file was never read, but the path
now names the temp home.
</details>
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 23, 2026
Merged via the queue into amd:main with commit 27a8aa4 Oct 23, 2026
41 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/desktop-crash-quit-fixes branch October 23, 2026 07:16
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.

2 participants