Skip to content

Desktop: extend the NVIDIA X11 WebKit fence fix to native packages - #10964

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
oobabooga:worktree-fix-native-nvidia-x11-compositing
Sep 15, 2026
Merged

danielhanchen merged 3 commits into
unslothai:mainfrom
oobabooga:worktree-fix-native-nvidia-x11-compositing

Conversation

@oobabooga

Copy link
Copy Markdown
Member

Native Linux packages on NVIDIA X11 can leak WebKit sync_file descriptors until the web process reaches its file descriptor limit, leaving the window blank or frozen (#10795). #10214 applied a compositing-off fallback to the AppImage; this extends the same fallback to native packages.

Closes #10795.

Change

Native NVIDIA X11 launches on WebKitGTK 2.44 or newer now set:

  • WEBKIT_DMABUF_RENDERER_FORCE_SHM=1
  • WEBKIT_FORCE_DMABUF_RENDERER=1
  • WEBKIT_DISABLE_COMPOSITING_MODE=1

The first two variables preserve a nonempty shared-memory transport while compositing is disabled. Using WEBKIT_DISABLE_DMABUF_RENDERER=1 instead can leave Debian and Ubuntu's patched WebKit without a backing-store transport and trigger block/buzz#3654.

Operator-set WebKit variables still take precedence. UNSLOTH_WEBKIT_DISABLE_COMPOSITING=0 restores the previous transport-only behavior.

Verification

  • All 539 studio/src-tauri Rust tests passed. The 53 focused linux_webkit tests also passed after the final cleanup.
  • An exhaustive comparison over 2,949,120 rendering-plan inputs changed only native NVIDIA X11 cases. AppImage and non-NVIDIA behavior was unchanged.
  • On an RTX 3090 with driver 610.43.02, the branch launched with 0 sync_file descriptors instead of 5 to 6. The opt-out restored the previous descriptor behavior.
  • With a fault injector that deliberately retained every sync_file descriptor, main and the opt-out reached the 1,024 descriptor limit and failed with Creating pipes for GWakeup: Too many open files. The compositing-off branch remained at 36 descriptors with no sync_file entries.

The natural leak did not reproduce on driver 610.43.02. The known reports used the 580 driver branch, so the fault-injection result validates that this change avoids the fence-producing path, not that it reproduces the original driver behavior.

Affected-host test

The exact fallback can be tested on the current .deb without a new build. Remove any existing WEBKIT_DISABLE_DMABUF_RENDERER=1 override, then run:

env WEBKIT_DMABUF_RENDERER_FORCE_SHM=1 WEBKIT_FORCE_DMABUF_RENDERER=1 WEBKIT_DISABLE_COMPOSITING_MODE=1 /usr/bin/unsloth-studio

On an affected system, the WebKitWebProcess sync_file count should stay at 0 while the UI is used.

Scope

Wayland, non-NVIDIA hosts, and WebKitGTK older than 2.44 are unchanged. All matching NVIDIA X11 systems take the fallback, including unaffected systems and PRIME setups where the NVIDIA module is loaded but an iGPU renders the desktop. Compositing-off performance can vary by workload; UNSLOTH_WEBKIT_DISABLE_COMPOSITING=0 is the opt-out.

…TING

Native NVIDIA X11 now defaults to compositing off, which makes this setting the
only way back to the accelerated path for a host the module probe over-matches,
such as a PRIME laptop presenting on its iGPU.

It was an exact byte match on "0", so UNSLOTH_WEBKIT_DISABLE_COMPOSITING=false
did nothing. That used to be harmless, because the native default was the
transport-only fallback the opt-out selects anyway. It is not harmless now: the
value silently leaves the host on the fallback it was trying to leave.

Read it as a tri-state instead, trimmed and case folded, so 0/false/no/off turn
the workaround off and 1/true/yes/on turn it on. Anything else is still not an
instruction and the rule decides.

Verified with an exhaustive replay of rendering_plan against origin/main over
770,703,360 environment and host combinations: with a value main already
understood (unset, "0", "1") the only behaviour that moves is still native
NVIDIA X11, and every other difference comes from a spelling main could not
parse.
@danielhanchen

Copy link
Copy Markdown
Member

Went through this one carefully and simulated it rather than eyeballing it. Summary: the logic is correct, the scope claim holds, and I could not find anything it breaks. I pushed one small fix to the branch.

Before and after

Before, on a native package (.deb, .rpm, tarball) with the NVIDIA module loaded and no Wayland session, Studio set WEBKIT_DMABUF_RENDERER_FORCE_SHM=1 and WEBKIT_FORCE_DMABUF_RENDERER=1 and left accelerated compositing on. The DMA-BUF renderer therefore stayed live, which is the path that retains a sync_file fence per redraw in #10795. Only the AppImage got the compositing-off fallback from #10214.

After, the same host also gets WEBKIT_DISABLE_COMPOSITING_MODE=1. With compositing off, WebKit never builds an accelerated backing store, so the fence-producing path is not reached at all. The two transport variables stay so a library that ignores the compositing switch still lands on shared memory rather than the empty set.

It is a real issue, not a fake one. #10795 has fd timelines, the nv_drm ... invalid sync FD: -24 kernel messages, and a clean A/B table, and the row in rendering_plan that produced "no workaround at all" for X11 NVIDIA is exactly the reporter's configuration.

What I verified

WEBKIT_DISABLE_COMPOSITING_MODE is read in WebPreferences::platformInitializeStore (WebKit bug 154147) and is presence-only, so any value disables compositing. That matches the comment on the const, and it is why UNSLOTH_WEBKIT_DISABLE_COMPOSITING has to be a separate setting. It is still honoured on 2.44 through 2.53.x. The supported replacement is the per-view hardware acceleration policy API, so the failure mode if a future WebKitGTK drops the variable is that we fall back to today's behaviour, not something worse.

Windows and macOS cannot be affected. mod linux_webkit and its call site in main.rs are both #[cfg(target_os = "linux")], and webkit2gtk-sys is under [target.'cfg(target_os = "linux")'.dependencies]. I built a crate that mirrors that gating with a deliberately Linux-only body and checked it against x86_64-pc-windows-msvc, aarch64-apple-darwin, x86_64-apple-darwin, x86_64-unknown-linux-gnu and aarch64-unknown-linux-gnu. All five compile. The desktop webview is WebKitGTK only on Linux, WebView2 on Windows and WKWebView on macOS, and none of these variables reach those.

WSL2 is unaffected for a different reason: there is no nvidia.ko there, the GPU arrives through dxgkrnl, so /proc/driver/nvidia/version does not exist and nvidia_driver_loaded() is false.

Simulations

I replayed rendering_plan and configure_renderer from origin/main and from this branch side by side.

Suite Checks Result
Host matrix, [Windows, macOS, WSL2, Linux] x [NVIDIA proprietary, NVIDIA open, NVIDIA+Intel PRIME, NVIDIA+AMD, nouveau, AMD, Intel, CPU only] x [X11, Wayland, XWayland, dead Wayland socket, headless] x [deb, rpm, tarball, AppImage] x 6 WebKitGTK versions 3,840 profiles 1 transition, native NVIDIA non-Wayland only
Exhaustive environment x host replay 770,703,360 only native NVIDIA X11 on 2.44+ moves
Upgrade, downgrade and relaunch chains 61,440 fixed point by the 2nd launch, no variable leaks
Probe functions against synthetic and real sysfs, a live Xvfb server and live unix sockets 47 pass
Real configure_renderer() on a real NVIDIA host under a real X server 4 pass

Specifically on the things that worried me:

  • Old installs and updating. Tauri's process::restart does not env_clear, so I ran base -> head, head -> base, head -> head and longer alternating chains from every profile. An in place upgrade lands exactly where a clean install of this branch lands, a downgrade lands exactly where a machine that never saw this branch lands, and after every chain the set of WEBKIT_ variables present equals the claim in UNSLOTH_WEBKIT_RENDERER_WORKAROUND. Nothing is stranded.
  • Operator overrides. WEBKIT_DISABLE_DMABUF_RENDERER=1, WEBKIT_DMABUF_RENDERER_FORCE_SHM=1 and WEBKIT_DISABLE_COMPOSITING_MODE=1 set by hand still short circuit to PreserveEnvironment untouched, on every profile. The .desktop workaround in [Unsloth Bug] X11 + NVIDIA: WebKitWebProcess leaks DMA-BUF sync_file fds until EMFILE — blank/frozen window (looks like a hang) #10795 keeps working after the update.
  • The empty transport set. On no native NVIDIA X11 profile does this branch select DisableDmabuf, so the WEBKIT_DISABLE_DMABUF_RENDERER crashes WebKitGTK on NVIDIA instead of falling back to shared memory block/buzz#3654 null backing store is not reachable there.
  • The UI. There is no WebGL anywhere in studio/frontend, only 2D canvas, which does not need accelerated compositing. <video> in the video feature falls back to CPU compositing, so the cost here is performance on those hosts, not breakage. That is the same trade the AppImage already ships.

The one fix I pushed

UNSLOTH_WEBKIT_DISABLE_COMPOSITING matched "0" byte for byte, so =false, =no, =off and = 0 did nothing. That used to be harmless, because on a native package the default already was the transport-only plan the opt-out selects. It stops being harmless here: this setting becomes the only way back to accelerated compositing for a host the module probe over-matches, and a PRIME laptop that writes false silently stays on the fallback it was trying to leave.

297bf35 reads it as a tri-state, trimmed and case folded, so 0/false/no/off turn it off and 1/true/yes/on turn it on. Anything else is still not an instruction. I re-ran the full exhaustive replay after the change: with any value main already understood, the only behaviour that moves is still native NVIDIA X11, so the fix does not widen the blast radius.

Tests are at 54 passing in linux_webkit, the file is rustfmt clean, and clippy reports only the two warnings that were already there.

Before merging

The one thing none of this can establish is that the chosen combination fixes the actual driver. The A/B table in #10795 shows WEBKIT_DMABUF_RENDERER_FORCE_SHM=1 WEBKIT_FORCE_DMABUF_RENDERER=1 not helping and WEBKIT_DISABLE_DMABUF_RENDERER=1 fixing it, and the evidence here for adding the compositing switch on top is a fault injector on a driver that does not reproduce the leak. The mechanism is sound, but it is worth one confirmation.

@Kalrkloss could you run this on your existing .deb? No new build needed. Remove any WEBKIT_DISABLE_DMABUF_RENDERER=1 you added, then:

env WEBKIT_DMABUF_RENDERER_FORCE_SHM=1 WEBKIT_FORCE_DMABUF_RENDERER=1 WEBKIT_DISABLE_COMPOSITING_MODE=1 /usr/bin/unsloth-studio

If ls /proc/<WebKitWebProcess>/fd | grep -c sync_file stays at 0 while you use the UI, this is good to merge.

Two notes for later, neither blocking and neither introduced here. RENDERER_OVERRIDE_VARS in studio/scripts/unsloth_freeze_report.py does not list WEBKIT_DISABLE_COMPOSITING_MODE even though the app reads it as an override; it is only cleared today because it happens to appear in CANDIDATES. And once this lands, the WEBKIT_DISABLE_COMPOSITING_MODE=1 rung of the freeze report loses most of its diagnostic value on native NVIDIA X11, since the control run already has compositing off.

The two red CPU jobs are unrelated to this PR: a skip guard assertion about test_stopping_criteria_device.py and an Ascend NPU name formatting assertion. Nothing here touches Python.

Comment-only. Drops the lines that restate the code next to them (the variant
doc that repeats variables(), the opt-out arm that repeats the variant name,
the test line that repeats its own assertion) and collapses the rest, keeping
every citation and every reason a reader would otherwise have to rediscover.

23 comment lines added by this PR down to 9. Verified comment-only by stripping
Rust comments from both revisions and comparing the remaining code, which is
byte identical at 32704 chars.
@danielhanchen

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 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 ✅ Completed 2026-09-15T10:04:09.725394Z 7a6f594 Manual request
ℹ️ 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.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 7a6f594397

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit b944ebf into unslothai:main Sep 15, 2026
26 of 28 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…nslothai#10964)

* Desktop: extend the NVIDIA X11 WebKit fence fix to native packages

* Studio: accept the usual spellings for UNSLOTH_WEBKIT_DISABLE_COMPOSITING

Native NVIDIA X11 now defaults to compositing off, which makes this setting the
only way back to the accelerated path for a host the module probe over-matches,
such as a PRIME laptop presenting on its iGPU.

It was an exact byte match on "0", so UNSLOTH_WEBKIT_DISABLE_COMPOSITING=false
did nothing. That used to be harmless, because the native default was the
transport-only fallback the opt-out selects anyway. It is not harmless now: the
value silently leaves the host on the fallback it was trying to leave.

Read it as a tri-state instead, trimmed and case folded, so 0/false/no/off turn
the workaround off and 1/true/yes/on turn it on. Anything else is still not an
instruction and the rule decides.

Verified with an exhaustive replay of rendering_plan against origin/main over
770,703,360 environment and host combinations: with a value main already
understood (unset, "0", "1") the only behaviour that moves is still native
NVIDIA X11, and every other difference comes from a spelling main could not
parse.

* Studio: tighten the comments this PR adds

Comment-only. Drops the lines that restate the code next to them (the variant
doc that repeats variables(), the opt-out arm that repeats the variant name,
the test line that repeats its own assertion) and collapses the rest, keeping
every citation and every reason a reader would otherwise have to rediscover.

23 comment lines added by this PR down to 9. Verified comment-only by stripping
Rust comments from both revisions and comparing the remaining code, which is
byte identical at 32704 chars.

---------

Co-authored-by: danielhanchen <[email protected]>
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 1, 2026
…) (unslothai#16322)

Fixes unslothai#16318. Same cause as the flicker in unslothai#16028.

On NVIDIA X11 the app turns WebKit compositing off below driver 610,
which avoids the 580 driver's `sync_file` leak (unslothai#10795). The plan it
uses (`WEBKIT_DMABUF_RENDERER_FORCE_SHM` +
`WEBKIT_FORCE_DMABUF_RENDERER` + `WEBKIT_DISABLE_COMPOSITING_MODE`)
works up to WebKitGTK 2.52, but on 2.54 the window stops presenting what
WebKit draws. The report's video alternates between the UI and a blank
off-white window 82 times in 11 seconds.
`WEBKIT_DISABLE_COMPOSITING_MODE=1` alone is enough to trigger it on
2.54 with NVIDIA's libraries; with Mesa it renders.

Who gets it: NVIDIA X11 hosts below driver 610 with a system WebKitGTK
2.54 (Debian 13, Fedora 43/44, Arch). Deb users there have had it since
their distribution moved to 2.54. AppImage users there got it in
v0.1.913, when the AppImage started running on the host's WebKitGTK 2.54
(unslothai#15503); v0.1.912's bundled 2.50.4 renders. The "Off" setting, "On"
below driver 610 and `UNSLOTH_WEBKIT_DISABLE_COMPOSITING=1` all reached
the same plan, so none of them helped.

## Fix

Every NVIDIA X11 path that turns compositing off now turns the DMA-BUF
renderer off instead on WebKitGTK 2.54 and newer: Auto below driver 610,
Off, On below 610, and `UNSLOTH_WEBKIT_DISABLE_COMPOSITING=1`. This is
the `WEBKIT_DISABLE_DMABUF_RENDERER=1` workaround the report confirmed.
Below 2.54 those paths keep the shared-memory plan, which renders there
and is what unslothai#10964 chose because disabling DMA-BUF could leave Debian
and Ubuntu's patched WebKit without a transport. Wayland, non-NVIDIA
hosts and NVIDIA X11 at driver 610 or newer are unchanged.

## A/B results

v0.1.912 and v0.1.913 release builds, and this branch before and after
the follow-up commit, built with the Linux x64 steps of
`release-desktop.yml`, ran in Debian 13, Fedora 44 and Ubuntu 24.04
containers with NVIDIA's userspace on an Xvfb display, with a fake
driver 595 version file for the below-610 paths. Without a compositor,
the broken presentation shows as a window that stays blank rather than
flickering.

| WebKitGTK | Auto, driver 595 | On, driver 595 | Off |
`UNSLOTH_WEBKIT_DISABLE_COMPOSITING=1` |
| --- | --- | --- | --- | --- |
| 2.54.0 (Debian 13), v0.1.913 | Blank | Blank | Blank | Blank |
| 2.54.0 (Debian 13), this PR | Renders | Renders | Renders | Renders |
| 2.54.2 (Fedora 44), this PR | Renders | Renders | Renders | Renders |
| 2.52.6 (Ubuntu 24.04), this PR | Renders, unchanged plan | Renders,
unchanged plan | Renders, unchanged plan | Renders, unchanged plan |
| 2.50.4 (bundled), this PR | Renders, unchanged plan | Renders,
unchanged plan | Renders, unchanged plan | Renders, unchanged plan |

The first commit alone left On below 610 and
`UNSLOTH_WEBKIT_DISABLE_COMPOSITING=1` blank on 2.54.0 and 2.54.2. The
v0.1.912 deb is blank on Debian 13's 2.54.0 as well.

Disabling DMA-BUF also stays clear of the 580 leak. On a GeForce MX150
with driver 580.178.04, the same continuous-scroll workload grew the web
process to 367 `sync_file` descriptors in about 2 minutes with
compositing on, and stayed at 0 for 5 minutes with
`WEBKIT_DISABLE_DMABUF_RENDERER=1`, at 59 fps.

## Validation

- **Rust tests:** all 837 `studio/src-tauri` binary tests pass,
including a new case for each of the four paths on 2.50.4, 2.52.6,
2.54.0 and 2.54.2.
- **Builds:** `verify-complete-appimage.sh` passed on both A/B builds.
- **Not tested:** the flicker itself on an NVIDIA X server below driver
610 with WebKitGTK 2.54 (the test machine has driver 615), and Debian or
Ubuntu's NVIDIA DMA-BUF patch on real NVIDIA hardware with WebKitGTK
2.52 or older.

---------

Co-authored-by: oobabooga <[email protected]>
Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Unsloth Bug] X11 + NVIDIA: WebKitWebProcess leaks DMA-BUF sync_file fds until EMFILE — blank/frozen window (looks like a hang)

2 participants