Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Desktop: fix NVIDIA X11 WebKit fence exhaustion (#10214)
oobaboogad31d7f93cc6d
diff --git a/studio/src-tauri/src/linux_webkit.rs b/studio/src-tauri/src/linux_webkit.rsindex 93e6721c5e3..720f929306d 100644--- a/studio/src-tauri/src/linux_webkit.rs+++ b/studio/src-tauri/src/linux_webkit.rs@@ -36,6 +36,7 @@ const OPEN_KERNEL_MODULE_MARKER: &str = "Open Kernel Module";const DRM_CLASS_DIR: &str = "/sys/class/drm";const NVIDIA_REASON: &str = "NVIDIA driver loaded (no Wayland session)";+const NVIDIA_APPIMAGE_X11_REASON: &str = "NVIDIA driver loaded (AppImage on X11)";const NVIDIA_WAYLAND_REASON: &str = "NVIDIA driver loaded (Wayland session)";const NVIDIA_APPIMAGE_GLES_REASON: &str ="NVIDIA driver loaded; AppImage without a usable GLES library";@@ -49,10 +50,13 @@ const COMPOSITING_FORCED_REASON: &str = "compositing workaround requested by theenum RenderingWorkaround {ForceSharedMemory,/// Only for a host the probe confirmed is NVIDIA. On a patched library isNVIDIA()- /// returns before mode.add(SharedMemory) in 2.50.4 and 2.52.6, so FORCE_SHM alone is- /// never read there; FORCE_DMABUF stands that check down so selection reaches it.- /// Unpatched libraries ignore the variable.+ /// returns before mode.add(SharedMemory), so FORCE_DMABUF stands that check down and+ /// lets selection reach FORCE_SHM. Unpatched libraries ignore the variable.ForceSharedMemoryOnNvidia,+ /// NVIDIA X11 AppImage only: its accelerated path retains one sync-file descriptor+ /// per redraw. Keeps the two variables above so a library that ignores the compositing+ /// switch still lands on the shared-memory transport rather than the empty set.+ DisableCompositingOnNvidiaX11,DisableDmabuf,/// Not a transport at all. The others choose how buffers reach the compositor; this/// stops WebKit compositing on the GPU at all.@@ -64,6 +68,9 @@ impl RenderingWorkaround {match self {Self::ForceSharedMemory => &[FORCE_SHARED_MEMORY],Self::ForceSharedMemoryOnNvidia => &[FORCE_SHARED_MEMORY, FORCE_DMABUF],+ Self::DisableCompositingOnNvidiaX11 => {+ &[FORCE_SHARED_MEMORY, FORCE_DMABUF, DISABLE_COMPOSITING]+ }Self::DisableDmabuf => &[DISABLE_DMABUF],Self::DisableCompositing => &[DISABLE_COMPOSITING],}@@ -82,7 +89,7 @@ enum RenderingPlan {/// order, and the first backend whose display opens wins. '*' expands to the built-in/// order, which is wayland before x11 on Linux. Membership is not selection: `x11,wayland`/// runs on X11 whenever an X display opens, and on NVIDIA that decides between the-/// shared-memory switch and the empty transport set.+/// X11 compositing fallback and the empty transport set.////// A display cannot be opened here, so `wayland_open` is the socket probe below standing in/// for GDK's own opener. A named backend that cannot open is not the selection, it is@@ -168,6 +175,12 @@ fn rendering_plan(wayland_socket,x11_open,);+ let nvidia_x11_appimage = is_appimage+ && nvidia_driver_loaded+ && !force_dmabuf+ && !wayland_session+ && gles_usable+ && supports_force_shared_memory(webkit_version);// A freeze, not a transport failure, and none of the switches below reach it. The// WebKit web process stops executing about 45 seconds in and never resumes: every@@ -193,7 +206,12 @@ fn rendering_plan(} else {COMPOSITING_REASON};- return RenderingPlan::Apply(RenderingWorkaround::DisableCompositing, reason);+ let workaround = if requested("1") && nvidia_x11_appimage {+ RenderingWorkaround::DisableCompositingOnNvidiaX11+ } else {+ RenderingWorkaround::DisableCompositing+ };+ return RenderingPlan::Apply(workaround, reason);}// The DMA-BUF transport breaks on the proprietary driver on either display server, so@@ -204,12 +222,16 @@ fn rendering_plan(// here this covers hosts where that patch's GL_VENDOR probe disagrees with the module// probe, plus the GBM open and throwaway GL context isNVIDIA() does at startup.//- // The two switches are not interchangeable, so pick per failure mode, not per GPU:+ // The fallbacks are not interchangeable, so pick per failure mode, not per GPU:// Wayland DISABLE_DMABUF. The failure is the explicit-sync disconnect, and// FORCE_SHM routes every commit down the wl_shm path that trips it// (bug 315436). It is also the switch reported to fix Error 71.- // X11 FORCE_SHM. No explicit-sync protocol there, the failure is hardware- // DMA-BUF allocation, and shared memory fixes it without the empty set.+ // X11 FORCE_SHM. The AppImage also turns compositing off: its accelerated+ // path leaks a sync-file fd per redraw until WebKit hits its descriptor+ // limit. That switch clears the web preference too, so the null backing+ // store below is unreachable. The native library leaks the same way once+ // explicit sync is reachable; it is left alone here only because the+ // bundled runtime is the one we ship. See the note on the branch below.// The empty set is not just slower: DISABLE_DMABUF returns before the SharedMemory// add, so checkRequirements() is false, AcceleratedBackingStore::create() returns// nullptr, and webkitWebViewBaseEnterAcceleratedCompositingMode() dereferences it@@ -217,15 +239,19 @@ fn rendering_plan(// X11, on the same iGPU-presenting topology the probe below over-triggers on.//// That probe is module presence, not the GPU that will render, so a PRIME laptop on- // its iGPU takes a workaround it does not need. Deliberate: reading the rendering GPU- // needs a GL context and this runs before GTK init so that none exists. Those hosts- // opt out with WEBKIT_DISABLE_DMABUF_RENDERER=0.+ // its iGPU takes a workaround it does not need. The compositing rule accepts that+ // scope: a fence leak is terminal and this path already CPU-copies. Deliberate:+ // reading the rendering GPU needs a GL context and this runs before GTK init so that+ // none exists. Those hosts opt out with WEBKIT_DISABLE_DMABUF_RENDERER=0, or keep+ // compositing alone with UNSLOTH_WEBKIT_DISABLE_COMPOSITING=0.if nvidia_driver_loaded && !force_dmabuf {let missing_appimage_gles = is_appimage && !gles_usable;let reason = if missing_appimage_gles {NVIDIA_APPIMAGE_GLES_REASON} else if wayland_session {NVIDIA_WAYLAND_REASON+ } else if is_appimage {+ NVIDIA_APPIMAGE_X11_REASON} else {NVIDIA_REASON};@@ -236,8 +262,15 @@ fn rendering_plan(|| !supports_force_shared_memory(webkit_version){RenderingWorkaround::DisableDmabuf- } else {+ } else if !is_appimage || requested("0") {+ // Native packages keep compositing, and =0 puts an AppImage back here.+ // Not because they are unaffected: the host 2.52.6 library was measured+ // leaking the same fd per redraw once a render node makes explicit sync+ // reachable. Narrowing to the AppImage is a deliberate first step, since the+ // bundled runtime is ours to pin; native needs its own change.RenderingWorkaround::ForceSharedMemoryOnNvidia+ } else {+ RenderingWorkaround::DisableCompositingOnNvidiaX11};return RenderingPlan::Apply(workaround, reason);}@@ -591,9 +624,10 @@ mod tests {}#[test]- fn nvidia_on_x11_drops_to_shared_memory_rather_than_the_empty_transport_set() {- // No explicit-sync protocol to violate here, and DISABLE_DMABUF leaves the null- // backing store release builds dereference (block/buzz#3654).+ fn native_nvidia_x11_keeps_the_crash_safe_accelerated_transport() {+ // The native package keeps acceleration and only avoids the empty backing-store+ // set. That is scope, not health: the host library leaks the same way when+ // explicit sync is reachable, and covering it needs its own change.assert_eq!(plan_on_nvidia(&[]),RenderingPlan::Apply(@@ -604,12 +638,12 @@ mod tests {}#[test]- fn nvidia_under_an_explicit_x11_backend_still_applies() {+ fn nvidia_appimage_under_an_explicit_x11_backend_disables_compositing() {assert_eq!(- plan_on_nvidia(&[(GDK_BACKEND, "x11")]),+ plan_on_nvidia(&[(APPIMAGE, "/tmp/Unsloth.AppImage"), (GDK_BACKEND, "x11")]),RenderingPlan::Apply(- RenderingWorkaround::ForceSharedMemoryOnNvidia,- NVIDIA_REASON+ RenderingWorkaround::DisableCompositingOnNvidiaX11,+ NVIDIA_APPIMAGE_X11_REASON));}@@ -679,10 +713,10 @@ mod tests {fn a_zero_force_dmabuf_value_does_not_stand_the_workaround_down() {// The patch tests the first byte against '0', so "0" is not a request.assert_eq!(- plan_on_nvidia(&[(FORCE_DMABUF, "0")]),+ plan_on_nvidia(&[(APPIMAGE, "/tmp/Unsloth.AppImage"), (FORCE_DMABUF, "0")]),RenderingPlan::Apply(- RenderingWorkaround::ForceSharedMemoryOnNvidia,- NVIDIA_REASON+ RenderingWorkaround::DisableCompositingOnNvidiaX11,+ NVIDIA_APPIMAGE_X11_REASON));}@@ -804,6 +838,14 @@ mod tests {);}+ #[test]+ fn the_nvidia_shared_memory_plan_stands_down_the_distribution_patch() {+ assert_eq!(+ RenderingWorkaround::ForceSharedMemoryOnNvidia.variables(),+ &[FORCE_SHARED_MEMORY, FORCE_DMABUF]+ );+ }+#[test]fn a_named_wayland_that_cannot_open_falls_through_to_the_next_backend() {// GDK tries wayland first, its opener fails with no socket to connect to, and the@@ -840,13 +882,17 @@ mod tests {}#[test]- fn forcing_shared_memory_also_opts_out_of_the_distro_patch() {+ fn the_nvidia_x11_fallback_keeps_a_nonempty_transport() {// isNVIDIA() returns before mode.add(SharedMemory) on 2.50.4 and 2.52.6, so- // FORCE_SHM on its own is never read there and the set is empty regardless.+ // FORCE_SHM on its own is never read there and the set is empty regardless, so+ // both must survive beside the compositing switch a WebKit may ignore.assert_eq!(- RenderingWorkaround::ForceSharedMemoryOnNvidia.variables(),- &[FORCE_SHARED_MEMORY, FORCE_DMABUF]+ RenderingWorkaround::DisableCompositingOnNvidiaX11.variables(),+ &[FORCE_SHARED_MEMORY, FORCE_DMABUF, DISABLE_COMPOSITING]);+ assert!(!RenderingWorkaround::DisableCompositingOnNvidiaX11+ .variables()+ .contains(&DISABLE_DMABUF));assert_eq!(RenderingWorkaround::DisableDmabuf.variables(),&[DISABLE_DMABUF]@@ -855,18 +901,19 @@ mod tests {#[test]fn our_own_force_dmabuf_does_not_read_back_as_an_opt_out() {- // We set it as half of ForceSharedMemory; a relaunch must not see its own output- // as an operator standing the NVIDIA branch down.+ // Older launches set it beside FORCE_SHM; a relaunch must not see its own output+ // as an operator standing the NVIDIA branch down while migrating to the new plan.let claimed = [FORCE_SHARED_MEMORY, FORCE_DMABUF].join(",");assert_eq!(plan_on_nvidia(&[+ (APPIMAGE, "/tmp/Unsloth.AppImage"),(FORCE_SHARED_MEMORY, "1"),(FORCE_DMABUF, "1"),(APPLIED_WORKAROUND, &claimed),]),RenderingPlan::Apply(- RenderingWorkaround::ForceSharedMemoryOnNvidia,- NVIDIA_REASON+ RenderingWorkaround::DisableCompositingOnNvidiaX11,+ NVIDIA_APPIMAGE_X11_REASON));}@@ -1243,15 +1290,15 @@ mod tests {}#[test]- fn x11_never_takes_the_compositing_workaround() {- // The same hardware on X11 was measured healthy, and the freeze needs the Wayland- // path. An X11 session keeps the shared-memory switch it has today.- let x11: &[(&str, &str)] = &[(X11_DISPLAY, ":0")];+ fn nvidia_x11_appimage_takes_its_dedicated_compositing_fallback() {+ // Repeated redraws exhaust WebKit's descriptor limit, one retained sync file per+ // frame, and the nonempty transport stays as the fallback.+ let x11: &[(&str, &str)] = &[(APPIMAGE, "/tmp/Unsloth.AppImage"), (X11_DISPLAY, ":0")];assert_eq!(- plan_on_graphics(x11, true, true, true),+ plan_on_graphics(x11, true, false, false),RenderingPlan::Apply(- RenderingWorkaround::ForceSharedMemoryOnNvidia,- NVIDIA_REASON+ RenderingWorkaround::DisableCompositingOnNvidiaX11,+ NVIDIA_APPIMAGE_X11_REASON));}@@ -1276,6 +1323,33 @@ mod tests {plan_on_graphics(off, true, true, true),RenderingPlan::Apply(RenderingWorkaround::DisableDmabuf, NVIDIA_WAYLAND_REASON));++ let nvidia_x11_off: &[(&str, &str)] = &[+ (APPIMAGE, "/tmp/Unsloth.AppImage"),+ (DISABLE_COMPOSITING_SETTING, "0"),+ ];+ assert_eq!(+ plan_on_graphics(nvidia_x11_off, true, false, false),+ RenderingPlan::Apply(+ RenderingWorkaround::ForceSharedMemoryOnNvidia,+ NVIDIA_APPIMAGE_X11_REASON+ )+ );+ }++ #[test]+ fn forcing_the_nvidia_x11_appimage_workaround_keeps_its_transport_fallback() {+ let forced: &[(&str, &str)] = &[+ (APPIMAGE, "/tmp/Unsloth.AppImage"),+ (DISABLE_COMPOSITING_SETTING, "1"),+ ];+ assert_eq!(+ plan_on_graphics(forced, true, false, false),+ RenderingPlan::Apply(+ RenderingWorkaround::DisableCompositingOnNvidiaX11,+ COMPOSITING_FORCED_REASON+ )+ );}#[test]