Skip to content

Desktop: Add GPU rendering setting with a Linux launch-crash fallback - #15482

Merged
Etherll merged 12 commits into
unslothai:mainfrom
Etherll:fix/inline-gpu-rendering-setting-65ad4a5b2ad1
Oct 30, 2026
Merged

Etherll merged 12 commits into
unslothai:mainfrom
Etherll:fix/inline-gpu-rendering-setting-65ad4a5b2ad1

Conversation

@Etherll

@Etherll Etherll commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a GPU rendering setting (Auto / On / Off) to Settings > Appearance in the desktop app. On Linux, Auto now takes the GPU path on NVIDIA Wayland with WebKitGTK 2.54 or newer, where it previously always forced DisableDmabuf. On one such host (KDE at 1.25 scale, system WebKitGTK 2.54.2) the web process main thread averaged 54% CPU (92% peak) on the CPU path and 6% (15% peak) on the GPU path. The bundled 2.50.4 showed no GPU benefit, so Auto leaves versions below 2.54 unchanged.

WebKit bug 280210 reports "Error 71 (Protocol error) dispatching to Wayland display" at launch on 2.54.0 and 2.54.1 with KWin and NVIDIA 615.71. To keep that safe, a GPU launch on Wayland now starts under a small in-app supervisor; other launches are not supervised. If the child reports Error 71 before the window is ready, the supervisor respawns once on the CPU path and writes a gpu-rendering-unsafe-v1 flag. The flag is keyed by WebKit version, NVIDIA driver line and session type, so a driver or WebKit update retries the GPU path. The UI offers "Try GPU again" to clear it.

Other behavior:

  • On forces the GPU path. Off uses the CPU path on Linux: WEBKIT_DISABLE_DMABUF_RENDERER=1 on Wayland, and shared memory plus compositing off on X11, where disabling DMA-BUF can leave no transport. On Windows it adds --disable-gpu to the main window and browser-panel pages while keeping wry's default browser arguments.
  • On macOS the setting is fixed to On with a note, since WKWebView has no public API to disable GPU rendering.
  • Environment overrides such as WEBKIT_DISABLE_DMABUF_RENDERER outrank the setting and are named in the UI.
  • WEBKIT_FORCE_DMABUF_RENDERER=1 on Wayland is now preserved for all vendors. Before, the generic Wayland branch overrode it with DisableDmabuf or ForceSharedMemory.
  • Applying a change relaunches the app through the existing quit confirmations instead of skipping them.
  • Adds the setting to settings search and to all 14 locales (13 are machine-written translations).
  • studio-tauri-smoke.yml gets Windows --disable-gpu launch and Linux Error 71 fallback steps.

Testing

  • cargo test --no-fail-fast in studio/src-tauri: 806 passed, 2 failed. The two failures are debian_update tests that need dpkg, and they fail the same way on unchanged main.
  • Frontend: focused node --test (21 passed), npm test (14087 passed), npm run typecheck, and i18n:check:strict all pass.
  • On a real KDE Wayland NVIDIA host with an isolated session and stub backend: Auto ran GPU supervised and cleaned up on SIGTERM. With the UNSLOTH_TEST_GPU_ERROR71=1 hook (debug builds only, which goes through the real GDK log handler), Error 71 produced the flag and a CPU child. A stored flag was honored, Off ran unsupervised on the CPU, and a second instance exited 0.
  • Not yet run: the Windows and macOS code paths and the new CI steps (fork CI pending). The "Restart now" and "Try GPU again" buttons were not clicked on a real desktop. A real Error 71 from bug 280210 was not reproduced, only simulated.

…crash fallback

Adds a "GPU rendering" setting under Settings > Appearance on every desktop OS. It is read
before the webview starts and applies after a restart, which the row offers through the
normal quit confirmations.

Linux: Auto keeps today's plan except on NVIDIA Wayland with WebKitGTK 2.54+, where it keeps
WebKit's GPU (DMA-BUF) path. WebKit bug 280210 still kills some of those hosts at launch with
Wayland Error 71, so a GPU launch on Wayland runs under a small in-binary supervisor: when the
app exits with Error 71 before its window is ready, the supervisor records a per-host flag
(WebKit version, NVIDIA driver, session type) and relaunches once on the CPU path. Later
launches read the flag until the host changes or the user picks a setting again. On forces
the GPU path; Off takes the CPU path (DISABLE_DMABUF on Wayland, SHM plus compositing off on
X11, where DISABLE_DMABUF can leave no transport). Operator WEBKIT_* variables still win, and
WEBKIT_FORCE_DMABUF_RENDERER=1 is no longer overridden by the generic Wayland branch.

Windows: Off starts WebView2 with --disable-gpu (keeping wry's default flags) for the main
window and browser pages. macOS: WKWebView has no public switch, so the setting shows fixed On.

CI: the Linux smoke job launches with Off and with a simulated Error 71; the Windows job
builds and checks the WebView2 command line for Off and Auto.
…pervisor signal gaps

- An operator WEBKIT_FORCE_DMABUF_RENDERER on Wayland keeps the DMA-BUF renderer but now runs
  under the startup supervisor, and a crash recorded for the host sends it to the CPU path.
  Before, it got neither the old shared-memory workaround nor a crash fallback.
- The supervisor watches SIGTERM, SIGINT, SIGQUIT and SIGHUP before it starts the first child.
  A request that arrives while no child runs (before the first spawn, or between a crashed GPU
  child and the CPU relaunch) now stops the next spawn instead of being lost.
- The child reports when its window is first shown, so a CPU relaunch after that drops a login
  start's --hidden instead of putting the window back in the tray.
- The supervisor parent logs a stale crash flag it cleared; the child never sees it.
- Add the SPDX header to linux_gpu_supervisor.rs.
…aunch decides to show

A --hidden start that consumes the in-app relaunch marker shows its window at once. Error 71
strikes at the window's first frame, before the frontend's shown report, so the CPU relaunch
kept --hidden and came back to the tray. The child now tells the supervisor when it decides to
show.
Etherll added a commit to Etherll/unsloth that referenced this pull request Oct 27, 2026
@Etherll

Etherll commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

Settings > Appearance now has a GPU rendering control (Auto, On, Off). A change applies after a restart, and the row offers Restart now. On Linux, Auto keeps WebKit's GPU (DMA-BUF) path on NVIDIA Wayland when WebKitGTK is 2.54 or newer and behaves as before everywhere else. Off uses the CPU path, and On forces the GPU path. On Windows, Off starts WebView2 with --disable-gpu. macOS has no supported switch, so the row shows On there.

What changed

  • NVIDIA Wayland always rendered on the CPU, which was slow at fractional scales. Auto now keeps the GPU path on WebKitGTK 2.54+. On a KDE host at 1.25 scale the web process main thread dropped from 54% average CPU (92% peak) to 6% (15% peak).
  • WebKit bug 280210 can still crash that path at launch with Wayland Error 71. A crash before the window is ready now relaunches once on the CPU path and remembers it for that host (WebKit version, NVIDIA driver and session type) until the host changes or the setting is picked again. WEBKIT_FORCE_DMABUF_RENDERER=1 is no longer overridden on Wayland, and it gets the same fallback.
  • A stop request that arrived before the app started, or during the CPU relaunch, was lost. It now stops the launch. A window the user had already opened no longer comes back hidden after the fallback.

GPU rendering setting, before and after

Before: 388e0adc. After: 755d3e32, with Auto and then On selected.

Tested on KDE Plasma Wayland with NVIDIA 615.78.08 and WebKitGTK 2.54.2: Auto loads the NVIDIA EGL driver in the web process, and a simulated Error 71 (a debug-only hook through the real GDK log handler) produced one CPU relaunch, after which the next launch went straight to the CPU path. 810 of 812 Rust tests pass; the two debian_update failures need dpkg and fail the same way on the base commit. Frontend tests, typecheck and the i18n parity check pass.

A real bug 280210 crash did not reproduce on this host. Fork CI on 755d3e32 passed the Linux, Windows and macOS desktop jobs, including the Windows check that Off starts WebView2 with --disable-gpu. Three Python suites failed there too, and they fail the same way without this change. The 13 non-English strings could use a native speaker's review.

danielhanchen added a commit that referenced this pull request Oct 27, 2026
…s group (#15500)

## Problem

`Repo tests (CPU, studio)` fails on main since #15467, so every PR based
on it inherits two failures (#15482 today):

```
tests/studio/test_settings_compact_overflow_contract.py::test_settings_monitor_link_can_shrink
E   assert '<SettingsSection title={t("settings.resources.liveMonitor.apiTitle")}>' in '...'
tests/studio/test_usage_examples_model_source_contract.py::test_auto_switch_section_sits_below_the_monitor_link
E   ValueError: substring not found
```

Bisected locally: both pass at 9fb0221~1 and fail from 9fb0221
(#15467) onwards.

## Product or test

The tests. #15467 reorganised the API page on purpose:

- `MonitorLink` takes `hideHeading`. Its `SettingsSection` keeps the
same title, now with a second prop on its own line.
- The API tab renders `<MonitorLink hideHeading={true} />` inside a new
titled `<SettingsSection title="Access & monitoring">`.
- The usage examples now render inside `ApiExamplesPanel`.

Both tests matched the old spellings: the one-line `<SettingsSection
title={...}>`, the bare `<MonitorLink />` and `<UsageExamples`. The
invariants they guard still hold on main:

- the monitor never lands as a bare card among other sections
- the examples come before the monitor link, which comes before
auto-switch

## Fix

- `test_settings_monitor_link_can_shrink`:
- checks that `MonitorLink` renders its own `SettingsSection` titled
`settings.resources.liveMonitor.apiTitle`, whatever other props it takes
- new: wherever a settings page renders `<MonitorLink hideHeading ...>`,
it must sit inside an open, titled `SettingsSection`
- `test_auto_switch_section_sits_below_the_monitor_link`: same order
(`UsageExamples` or `ApiExamplesPanel`, then `MonitorLink`, then
`ModelAutoSwitchSection`), matched by tag name instead of exact
spelling.

## Verification

- Both files: 22 passed (2 failed on main).
- Sabotage on main's sources, one at a time, each fails:
- `<MonitorLink hideHeading={true} />` moved out of its
`SettingsSection`
  - `<ModelAutoSwitchSection />` removed
  - the monitor section title changed
- ruff format and check are clean.
@Etherll
Etherll marked this pull request as ready for review October 27, 2026 15:06
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-27T15:06:39.535187Z
We couldn’t complete this review. Comment @codex review to try again.
755d3e3 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@oobabooga

Copy link
Copy Markdown
Member

Reached Codex review convergence at oobabooga#432.

Isolate the app process group so PID and process-group signals are forwarded without duplicate delivery. Arm SIGTERM on parent death, preserve graceful backend cleanup, and cover real PID/group delivery and SIGKILL in subprocess tests. Use GTK structured_standard logging in the injected startup-error test.
Use the existing one-shot control reader when the supervisor disappears. Linux parent-death signals can be delivered more than once as a multithreaded parent is reaped; EOF avoids treating that as a repeated termination request.
Linux reports ECONNRESET when the supervisor closes its socket with unread window-status messages. Treat terminal control read errors like EOF, while retaining Interrupted retries and one-shot cleanup. Reproduce the real GUI status traffic in the SIGKILL regression.
Keep the second native termination signal as force-exit even when graceful cleanup began via supervisor control. Ignore a control close after native shutdown starts, and count interrupt requests toward parent SIGTERM escalation.
A repeated termination request explicitly abandons graceful cleanup. Use _exit so C/GTK/driver exit handlers cannot wait on locks held by the cleanup thread.
wasimysaid added a commit to Etherll/unsloth that referenced this pull request Oct 29, 2026
Bring in structured GTK Error 71 fallback, portable supervisor helpers, PID/group termination handling, and WebKit/NVIDIA safety gates from unslothai#15482. Preserve CPU painting status alongside the old-driver warning and verify image-shadow selection across the NVIDIA X11 driver gate.
@Etherll
Etherll merged commit 7af6ba3 into unslothai:main Oct 30, 2026
59 of 63 checks passed
shimmyshimmer pushed a commit that referenced this pull request Oct 30, 2026
#15503)

## Summary

The AppImage bundles WebKitGTK 2.50.4 from its Ubuntu 22.04 build base.
That version saturates the web process at fractional Wayland scales.
WebKitGTK 2.54 does not, but no distribution package of it builds on a
base that keeps the glibc 2.35 floor.

AppRun now probes the host. It runs an unbundled, byte-identical copy of
the executable (`usr/bin/host/unsloth-studio`, whose `$ORIGIN/../lib`
reaches nothing) with `--unsloth-webkit-probe` under a 5 s timeout. The
copy only loads if every linked host library and symbol resolves (the
binary is `BIND_NOW`). It also dlopens the tray library `setup_tray`
needs and prints the WebKitGTK version that loaded.

- If that version is 2.54 or newer, AppRun undoes the gtk/gstreamer hook
exports that pin GTK, GIO, GSettings and GStreamer to the bundle, and
execs the host copy, so the whole stack comes from the host.
- Otherwise it keeps the current bundled launch.
- `UNSLOTH_APPIMAGE_WEBKIT=auto|host|bundled` overrides the choice.
- The chosen mode is logged by AppRun and the app, shown in diagnostics,
and a host-mode AppImage gets the native rendering plan in
`linux_webkit.rs`.

The finalizer adds the host copy. The verifier checks it whenever a
launcher refers to it, so the already shipped release still verifies.
The clean-machine AppImage CI asserts the mode and the mapped libraries,
with new Fedora 44 and Debian 13 lanes (expect host) and an Ubuntu 24.04
lane (WebKitGTK 2.52.6, bundled unless forced).

Draft #15482 (GPU rendering setting) also touches `linux_webkit.rs`, so
whichever lands second will need a rebase.

## Testing

Run locally:

- `cargo test` in `studio/src-tauri`: 775 of 777 pass. The 2 failures
are `debian_update` dpkg tests that also fail on `main`.
- Probe on a host: prints `webkit=2.54.2` in 72 ms.
- 65 Python tests: AppRun mode matrix under dash and bash, an A/B
against the `main` AppRun (bundled mode differs only by
`UNSLOTH_APPIMAGE_WEBKIT_MODE=bundled` and one stderr line), verifier
and finalizer fixtures, and contract tests.

Not run yet:

- Building the AppImage (fork CI).
- The new Fedora 44, Debian 13 and Ubuntu 24.04 lanes.
- The built AppImage on a host at fractional scale.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: oobabooga <[email protected]>
Co-authored-by: Etherl <[email protected]>
danielhanchen added a commit that referenced this pull request Nov 3, 2026
…16535)

## Summary

`Tauri Linux debug build` fails intermittently on unrelated PRs in
`linux_gpu_supervisor::tests::pid_and_group_signals_reach_the_child_once`,
added in #15482. It hit #16524 today and `fix/opt-in-startup-warmup`
yesterday, 2 of about 41 completed runs since Nov 1, with the same panic
both times:

```
thread 'linux_gpu_supervisor::tests::pid_and_group_signals_reach_the_child_once' panicked at src/linux_gpu_supervisor.rs:1194:37:
index out of bounds: the len is 0 but the index is 0
```

**Cause.** The child writes its PIDs to `ready` with `std::fs::write`,
which creates the file and then writes to it. The parent polls with
`read_to_string`, and as soon as the read succeeds it parses the IDs. If
the poll lands between the create and the write, the parent reads an
empty string and indexes an empty list. The second panic in the log
(`NotFound` at line 1125) follows from the first: the parent's tempdir
is gone by the time the child writes `cleaned`. The parent polls
`cleaned` the same way, so that check has the same race.

The supervisor code under test is fine. Only the test's handshake was
racy.

## Change

`studio/src-tauri/src/linux_gpu_supervisor.rs`, test module only: a
small `publish` helper writes to `<name>.tmp` and renames it into place,
so the parent sees either no file or the whole contents. Both `ready`
and `cleaned` go through it. The signals, timeouts and assertions are
unchanged.

## Testing

- `cargo test --locked linux_gpu_supervisor`: 20 passed.
- Sabotage: I put a 100 ms sleep between the create and the write in the
original `std::fs::write` of `ready`. The test then fails with exactly
the CI panic above (`the len is 0 but the index is 0`).
- With this change and the same 100 ms sleep between writing `ready.tmp`
and the rename, the test passes 3 of 3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants