fix(linux): install silent X error handler to fix BadWindow exit on Wayland
Summary
- Install a process-global
XSetErrorHandlerat the top oflib.rs::run()on Linux so non-fatal X protocol errors (e.g.BadWindowfromXConfigureWindowduring CEF window setup on XWayland) don't trigger Xlib's default-handlerexit(1). - Linux-only (
cfg(target_os = "linux")). macOS/Windows are no-ops.
Problem
On Wayland sessions (GNOME-Wayland, KDE-Wayland, Hyprland — anywhere XWayland is the X server), the CEF browser process issues multiple XConfigureWindow calls against windows the XWayland server hasn't fully realized yet. The X server responds with BadWindow and Xlib's default error handler reacts by calling exit(1) — killing the entire app between [app] RunEvent::Ready and the actual window paint. Users see no UI; the shell prompt comes back instantly.
Reproduces reliably on Ubuntu 26.04 GNOME-Wayland (verified) and matches the Arch+Hyprland traceback in #2001 item #2 (different compositor, same XWayland → Xlib-default-handler → exit code path). #2032 closed #2001 based only on the NSS fix and explicitly punted this as "separate display-side concerns — see issue follow-ups." This is that follow-up.
Solution
install_silent_x_error_handler() does a one-time FFI call to libX11's XSetErrorHandler with a no-op handler that logs each error via log::warn!("[x11] suppressed X protocol error: code=… request=… …") and returns 0. Called as the first line of pub fn run() so it's installed before any GTK/CEF init that might trigger an X call.
Safe because:
XSetErrorHandleris process-global; can be installed before any X display is opened.libX11is already a runtime dep of the OpenHuman binary (confirmed vialdd) so the FFI extern resolves at link time without a new crate.- GUI apps that drive complex window state (Chromium, Electron, CEF) all install their own X handlers for the same reason; the CEF browser process already does, but the parent Tauri host process keeps the default — which is where the kill comes from.
After this fix, smoke-test on Ubuntu 26.04 GNOME-Wayland (with the AppImage launch regressions from tinyhumansai/tauri-cef PR also applied so the binary actually starts at all) shows ~12 suppressed BadWindows during CEF window setup, the app survives, the window paints, and the user can interact normally.
Submission Checklist
- [ ] Tests added or updated — `N/A: FFI bootstrap with no behavior to assert beyond "process doesn't exit on X protocol errors". The patch is a one-line install + a logging-no-op handler; the only meaningful "test" is observing the suppressed-error log lines during a real Wayland launch, which can't be exercised in unit tests (no X server available).
- [ ] Diff coverage ≥ 80% —
N/A: same as above — the only changed lines are FFI declarations and alog::warn!in an Xlib-callback that runs only when the X server returns an error. The change is also gated behindcfg(target_os = "linux")and the coverage workflow doesn't currently run a Linux X11 session. - [ ] Coverage matrix updated —
N/A: behaviour-only change with no new feature row. - [ ] All affected feature IDs listed under Related —
N/A - [ ] No new external network dependencies introduced
- [ ] Manual smoke checklist updated —
N/A: Linux launch behavior, not a release-cut surface in the smoke checklist today. - [ ] Linked issue closed via
Closes #NNN— see Related below
Impact
- Linux runtime only. macOS/Windows no-op via
cfg. No new crate deps. - ~60 lines including doc/comments. The actual code is 1 FFI extern + 1 logging handler + 1
Onceinstall. - Closes the only remaining blocker for #2001 to be truly done end-to-end on Wayland-XWayland hosts.
Related
- Closes #2001 (item #2 — item #1 was closed by #2032)
- Refs #2032
AI Authored PR Metadata (required for Codex/Linear PRs)
Linear Issue
- Key: N/A
- URL: N/A
Commit & Branch
- Branch: fix/x11-silent-error-handler-2001-followup
- Commit SHA: see PR
Validation Run
- [x]
pnpm --filter openhuman-app format:check— passes locally - [ ]
pnpm typecheck— N/A: no TypeScript changes - [x] Focused tests: manual end-to-end smoke (Ubuntu 26.04 GNOME-Wayland) — app launches, BadWindows suppressed, window paints
- [x] Rust fmt/check (if changed):
cargo fmt --checkpasses - [x] Tauri fmt/check (if changed):
cargo fmt --checkonapp/src-tauri/Cargo.tomlpasses
Validation Blocked
command:git pushpre-push hook (pnpm lint:commands-tokens)error:lint:commands-tokens requires ripgrep(ripgrep not installed on the dev box used to push this)impact:pushed with--no-verifyper CLAUDE.md guidance ("If a pre-push hook fails on something unrelated to your changes … push with--no-verifyand call it out in the PR body"). The ripgrep dep is unrelated to this patch.
Behavior Changes
- Intended behavior change: prevent
exit(1)from Xlib's default error handler on Linux. - User-visible effect: the app no longer dies between
RunEvent::Readyand window paint on Wayland-XWayland.
Parity Contract
- Legacy behavior preserved: macOS/Windows are unchanged (
cfg(target_os = "linux")gate). The Linux change is a strict superset — errors that previously killed the process are now logged. - Guard/fallback/dispatch parity checks: N/A — no dispatch path changes.
Duplicate / Superseded PR Handling
- Duplicate PR(s): none
- Canonical PR: this one
- Resolution: N/A
Summary by CodeRabbit
- Bug Fixes
- Improved stability on Linux systems by preventing unexpected crashes from X11 protocol errors when running under Wayland environments.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d6591a95-03a9-4e07-be30-979f4643261b
📥 Commits
Reviewing files that changed from the base of the PR and between 70fdedcdd449dca38b20bf30f69ec3c53a2b1666 and 49de75a1c39cf6755c272dc979e0b3aecf8636e1.
📒 Files selected for processing (1)
app/src-tauri/src/lib.rs
📝 Walkthrough
Walkthrough
This PR adds a Linux-only X11 error handler that suppresses BadWindow errors triggered when CEF attempts to configure window properties under Wayland/XWayland, preventing process termination and logging errors instead. The handler is installed at process startup before any GTK or CEF code runs.
Changes
X11 Error Handler Setup
| Layer / File(s) | Summary |
|---|---|
X11 error handler implementation and registration app/src-tauri/src/lib.rs |
install_silent_x_error_handler uses unsafe X11 FFI to register a global error handler once via std::sync::Once that logs protocol errors instead of aborting. Called at the start of run() before CEF/GTK initialization. |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~8 minutes
Possibly related issues
#2001: Directly addresses theBadWindow (invalid Window parameter)X11 crash on Arch Linux/Hyprland by installing an error handler that suppresses fatal exit behavior when CEF tries to configure window state under Wayland/XWayland.
Possibly related PRs
- tinyhumansai/openhuman#1809: Both modify the Linux CEF startup path in
app/src-tauri/src/lib.rs; this PR adds X11 error suppression while the referenced PR adds--disable-gputo CEF arguments, both targeting CEF initialization robustness.
Poem
🐰 X11 errors tried to crash our dreams,
But now we catch them, silent streams—
Wayland's dance won't break the show,
BadWindow whispers, down below. ✨
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title accurately describes the main change: installing an X error handler to suppress BadWindow errors on Wayland. |
| Linked Issues check | ✅ Passed | The PR directly addresses the X11 BadWindow crash blocker from #2001 by installing an error handler to prevent application exit on BadWindow errors during window configuration. |
| Out of Scope Changes check | ✅ Passed | All changes are scoped to the X error handler installation in lib.rs and directly address the BadWindow issue; no unrelated modifications detected. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.