Skip to content

Desktop: fix NVIDIA X11 WebKit fence exhaustion - #10214

Merged
oobabooga merged 6 commits into
unslothai:mainfrom
oobabooga:fix/studio-nvidia-x11-sync-fd-leak
Sep 8, 2026
Merged

oobabooga merged 6 commits into
unslothai:mainfrom
oobabooga:fix/studio-nvidia-x11-sync-fd-leak

Conversation

@oobabooga

@oobabooga oobabooga commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Summary

The complete Linux AppImage can become progressively laggy on NVIDIA X11 because its bundled WebKitGTK 2.50.4 retains one sync_file descriptor per redraw. This disables accelerated WebKit compositing only for NVIDIA X11 AppImages while preserving the existing shared-memory transport. Native packages, Wayland, and non-NVIDIA systems are unchanged.

Problem

Scrolling steadily grows the WebKit descriptor table until rendering, mouse movement, and clicks become severely delayed. The Studio backend remains healthy. The failure is in the NVIDIA X11 accelerated-compositing path.

The native WebKitGTK 2.52.6 library initially looked unaffected, but that was a property of the test environment rather than of the library. WebKit only exports a per-frame fence when the web process reaches an EGL display advertising EGL_ANDROID_native_fence_sync, which in turn needs /dev/dri render-node access. Re-measured with that access, the host 2.52.6 library reached 1023 descriptors with 949 retained sync files, the same as the bundled 2.50.4. Native packages on NVIDIA X11 are therefore affected too; this change deliberately covers the AppImage first, because the bundled runtime is the one we pin, and leaves native to its own change.

Simply switching to WEBKIT_DISABLE_DMABUF_RENDERER is unsafe. On the patched WebKit shipped by Debian and Ubuntu, it can leave the renderer transport set empty. AcceleratedBackingStore::create() then returns null, leading to the release-build crash reported in block/buzz#3654.

Change

When Studio detects an AppImage, a loaded NVIDIA driver, and X11, it now sets:

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

WEBKIT_DISABLE_COMPOSITING_MODE is the fix for the descriptor leak. WebKitGTK 2.50.4 reads it directly and disables accelerated compositing before the unsafe backing-store path can be entered.

The first two variables retain Studio's existing nonempty shared-memory transport as a compatibility fallback if another WebKit build ignores the compositing switch. This preserves the protection against block/buzz#3654. Other Tauri applications use the same compositing switch during Linux startup, including Kanri and Maestro.

UNSLOTH_WEBKIT_DISABLE_COMPOSITING=0 restores the previous NVIDIA X11 AppImage path if the automatic rule over-triggers. =1 can force the workaround for diagnosis outside the automatic rule. Explicit operator WebKit variables remain authoritative.

Verification

Tested live on X11 with the proprietary NVIDIA 580.173.02 driver:

  • Before the fix, repeated redraws added one sync_file descriptor at a time until input became unusably slow.
  • A patched debug build stayed at 36 to 38 descriptors with zero sync_file descriptors after 1,200 synthetic wheel events.
  • A release AppImage built in Ubuntu 22.04 Docker with the repository's official workflow passed the complete-runtime verifier and opened to a healthy, fully rendered chat screen. Studio stayed at 59 descriptors and WebKit at 174, both with zero sync_file descriptors.
  • Native WebKitGTK 2.52.6 remained accelerated and did not reproduce the growth without render-node access. With that access it reached 1023 descriptors and 949 retained sync files, so it is affected as well and is out of scope here rather than healthy.
  • All 516 studio/src-tauri Rust tests passed, including the AppImage-only rule, explicit X11 selection, forced-setting parity, operator opt-out, inherited workaround migration, and nonempty transport invariant.
  • git diff --check passed.

Cost on hosts that take the workaround without needing it

A host that cannot reach explicit sync cannot leak, but still takes the workaround. Measured on an NVIDIA X11 4K desktop against the bundled 2.50.4, comparing the previous transport-only plan with this one:

  • Plain scrolling improves: median input latency 11 to 12 ms drops to 3 to 4 ms, frame times hold at 60 fps, and web-process memory falls about 40%.
  • Blur-heavy content regresses: median input-to-pixel rises from 23 ms to 33 ms and web-process CPU rises from about 66% to about 104% of one core.

The frontend uses backdrop-blur-[1px] and [2px] on dialog overlays plus two static blur(10px) rules, so the exposure is limited. UNSLOTH_WEBKIT_DISABLE_COMPOSITING=0 restores compositing for anyone it costs more than it helps.

Where the defect actually is

The leak is WebKit's, not the driver's. On this hardware eglDestroySync releases the kernel sync file correctly, and creating an EGL_SYNC_NATIVE_FENCE_ANDROID fence, duplicating it with eglDupNativeFenceFDANDROID, closing the duplicate and destroying the sync leaks nothing over 300 iterations. Skipping only the close on the duplicate reproduces the observed signature exactly, one retained sync file per iteration. So the growth requires the exported descriptor to be dropped by the application, which is WebKit's descriptor in WebKit's process. This change remains a packaging workaround and does not repair that.

Scope

This is a packaging-specific compatibility fallback, not a fix for fence ownership in WebKitGTK or the NVIDIA driver. It trades accelerated WebKit compositing for stable input and rendering only on NVIDIA X11 AppImages.

The pre-GTK probe detects a loaded NVIDIA module, not the GPU that will render, so a PRIME laptop presenting through its iGPU can also match. Those hosts already used the shared-memory transport; the =0 setting restores compositing if needed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 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-08T14:22:46.103592Z fab4553 New commits
ℹ️ 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

Copy link
Copy Markdown
Member

Checked this against the NVIDIA X11 branch in studio/src-tauri/src/linux_webkit.rs and the plan does now reach the compositing switch instead of the transport alone. Since the module probe also matches PRIME laptops presenting through the iGPU, could you confirm what those hosts lose in rendering smoothness with compositing off before I review, and drop the unrelated formatting change in studio/backend/tests/test_anthropic_messages.py?

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 792ddbb195

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

&& !force_dmabuf
&& !wayland_session
&& gles_usable
&& supports_force_shared_memory(webkit_version);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Limit the fallback to affected WebKit versions

When Ubuntu 22.04 advances to a WebKit release without the fence leak, newly built AppImages will still disable accelerated compositing because this predicate accepts every runtime from 2.44 onward. The release job installs libwebkit2gtk-4.1-dev without a version pin (.github/workflows/release-desktop.yml:559-577), and the nearby comment already identifies 2.52.6 as releasing the temporary fences, so this will silently penalize future packaged runtimes. Gate the workaround on the affected WebKit range or otherwise tie it to the bundled version.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The predicate is not wider than the affected set today: jammy's libwebkit2gtk-4.1 is 2.50.4-0ubuntu0.22.04.1, which is exactly the version measured leaking, so every AppImage the release job can build right now bundles an affected runtime.

There is also no version boundary to gate on. I diffed the fence path between the webkitgtk-2.50.4 and webkitgtk-2.52.6 tags: Source/WebKit/UIProcess/glib/FenceMonitor.cpp is identical apart from the WTFMove to WTF::move rename, AcceleratedBackingStore::frame's m_fenceMonitor.addFileDescriptor call is unchanged, and the export side in AcceleratedSurface::RenderTargetShareableBuffer is unchanged too. So 2.52.6 is not a WebKit-side fix for this, and "the affected WebKit range" has no endpoint that can be written down. A guessed ceiling that is too low reintroduces a terminal failure, while one that is too high costs accelerated compositing on a path that already ran the CPU-copying shared-memory transport.

If jammy does move the bundled library, that is a build input we can re-measure at that point, and UNSLOTH_WEBKIT_DISABLE_COMPOSITING=0 restores compositing per host in the meantime.

@oobabooga

Copy link
Copy Markdown
Member Author

Measured it on an NVIDIA X11 host (RTX 6000 Ada, driver 580.173.02, GTK3 libwebkit2gtk-4.1 2.52.6, 1280x800 view). A small GtkWindow plus WebKitWebView harness, requestAnimationFrame intervals over 10s after a 2s warmup, web-process CPU read from /proc/<pid>/stat. A is today's AppImage NVIDIA X11 path (WEBKIT_DMABUF_RENDERER_FORCE_SHM=1 plus WEBKIT_FORCE_DMABUF_RENDERER=1, and webkit_settings_get_hardware_acceleration_policy reads ALWAYS). B is A plus WEBKIT_DISABLE_COMPOSITING_MODE=1, where the policy reads NEVER.

page A fps / web CPU B fps / web CPU
chat-like: 800-row scrolling list plus 24 transform and opacity layers 60.0 / 5.8s 60.2 / 7.5s
dialog overlay as Studio uses it: full-viewport 2px backdrop-filter, static content behind, spinner above 60.0 / 4.8s 79.9 / 2.1s
same overlay, content animating behind it 60.0 / 5.9s 60.0 / 7.5s
ten 420px filter: blur(40px) layers plus a 900x520 backdrop-filter card, all animating at once 59.6 / 3.8s 18.6 / 9.1s

So it is not a general smoothness loss. Scrolling, transforms, opacity and dialog backdrops stay pinned at vsync and cost roughly 30% more web-process CPU; the dialog case is actually cheaper without compositing because the backdrop stops being re-uploaded. The one case that falls off a cliff is several large blurred layers animating simultaneously, and the frontend does not do that: its blurs are backdrop-blur-[1px] and [2px] on dialog overlays plus two static blur(10px) rules.

One thing that came out of this and is worth knowing for the PRIME case specifically. WEBKIT_FORCE_DMABUF_RENDERER does not exist in upstream WebKit (0 hits in AcceleratedBackingStore.cpp at the webkitgtk-2.52.6 tag, which reads only WEBKIT_DISABLE_DMABUF_RENDERER, WEBKIT_DMABUF_RENDERER_BUFFER_FORMAT and WEBKIT_DMABUF_RENDERER_FORCE_SHM), but the string is in the Ubuntu library, so that build carries disable-nvidia-dmabuf.patch. With no variables set at all, the patched library reports NEVER on this host: it already turns accelerated compositing off whenever it thinks the GPU is NVIDIA. Studio's WEBKIT_FORCE_DMABUF_RENDERER is what turns it back on. A PRIME laptop the module probe over-matches therefore ends up on the library's own NVIDIA default rather than below it, and UNSLOTH_WEBKIT_DISABLE_COMPOSITING=0 still restores compositing per host.

On the second point, the studio/backend/tests/test_anthropic_messages.py change is already out. It came from the pre-commit.ci commit 66f85cd, and the main merge in 792ddbb resolved it away, so git diff origin/main HEAD on the branch now lists only studio/src-tauri/src/linux_webkit.rs.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@oobabooga
oobabooga merged commit d31d7f9 into unslothai:main Sep 8, 2026
6 of 36 checks passed
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 2026
…othai#18267)

Fixes unslothai#18259

## Problem

On Linux hosts where WebKit does not composite (NVIDIA on X11 with a
driver below 610, the GPU rendering Off setting, hosts with no usable
GPU path), wheel scrolling in the chat stalls and then jumps. The
reporter is on NVIDIA 595.99.02 on X11, where Desktop keeps compositing
off because older drivers leak a file descriptor per frame (unslothai#10214,
unslothai#10795, unslothai#15546).

Without compositing WebKit also turns threaded scrolling off
(`webkit_settings_set_hardware_acceleration_policy(NEVER)` clears
`ThreadedScrollingEnabled`), so its smooth scrolling animation runs on
the web process main thread. Each animation step is a full CPU repaint.
When a repaint takes around 100 ms, the time based animation shows
nothing for a few frames and then lands far ahead, which matches the
report: "when I start to scroll, there's a delay where nothing happens
at all, and then it suddenly jumps forward a huge amount".

## Fix

When the main webview is created on Linux, Desktop reads WebKit's own
answer (`hardware_acceleration_policy() == Never`, which WebKitGTK
derives from whether compositing is enabled, 2.50 and 2.54 alike) plus
`WEBKIT_DISABLE_COMPOSITING_MODE` (on 2.54 the policy stays `Always`
when only compositing is off). If WebKit is not compositing, smooth
scrolling is turned off, so each wheel notch is applied on the next
paint instead of being animated across several slow ones. Composited
hosts keep smooth scrolling unchanged.

No setting, UI or rendering plan changes. The value is set per launch
from that launch's state, so it is idempotent and a driver upgrade to
610+ brings smooth scrolling back on its own.

## Measurements

### The real Desktop binary

Debug builds of this branch and of its merge base (`efe3797`), built
with `--no-default-features` so the window loads a local chat-like page
(60 messages, code blocks, blurred header and composer). Ran under Xvfb
at `GDK_SCALE=2` with a 1400x900 window. The host has the NVIDIA 590
kernel module and WebKitGTK 2.50.4 (the version Mint 22.3 ships), so the
app chose the reporter's plan by itself: `NVIDIA driver loaded (no
Wayland session); set WEBKIT_DMABUF_RENDERER_FORCE_SHM=1
WEBKIT_FORCE_DMABUF_RENDERER=1 WEBKIT_DISABLE_COMPOSITING_MODE=1`. Real
X11 wheel clicks via XTest, base and head alternated ABBA, 4 runs each.
"Reach" is the time from a wheel click until the page has scrolled that
click's distance.

| Plan | Wheel input | Base reach median (per run) | Head reach median
(per run) | Largest jump base / head |
| --- | --- | --- | --- | --- |
| NVIDIA X11 below 610, compositing off (the report) | 20 clicks, 50 ms
apart | 546, 538, 551, 529 ms | 36, 42, 46, 34 ms | 537 to 699 px / 186
px |
| same | 8 clicks, 200 ms apart | 150, 117, 129, 131 ms | 0 ms (each
click lands on the next paint) | 90 px / 93 px |
| `UNSLOTH_WEBKIT_DISABLE_COMPOSITING=0`, compositing on (software GL),
2 runs each | 20 clicks, 50 ms apart | 192, 196 ms | 203, 193 ms | 140
to 186 px / 171 to 199 px |

The last row is the control: when WebKit composites, head keeps smooth
scrolling and matches base.

### NVIDIA GPU VM (Colab L4)

Same driver and page, both trees built on the VM: NVIDIA L4, driver
580.82.07 (the leaking branch), WebKitGTK 2.52.6, Xvfb. The app read the
real driver and picked its NVIDIA X11 below-610 plan by itself. 3 runs
per plan and tree.

| Plan | Base reach median (per run) | Head reach median (per run) |
Largest jump base / head |
| --- | --- | --- | --- |
| Default (NVIDIA X11 below 610, compositing off) | 565, 545, 523 ms |
53, 44, 44 ms | 791 to 886 px / 186 px |
| `UNSLOTH_WEBKIT_DISABLE_COMPOSITING=1` | 528, 536, 548 ms | 46, 48, 42
ms | 757 to 787 px / 186 px |
| `UNSLOTH_WEBKIT_DISABLE_COMPOSITING=0` (compositing on) | 194, 203,
200 ms | 196, 213, 202 ms | 138 to 203 px / 199 to 211 px |

### AMD GPU (gfx1151 AMD CI runner)

Both trees built in an `ubuntu:24.04` container (WebKitGTK 2.52.6) with
the Radeon render node passed through, Xvfb, 3 runs per plan and tree
(run 44322215922; the base and head binary hashes differ).

| Plan | Base reach median (per run) | Head reach median (per run) |
Largest jump base / head |
| --- | --- | --- | --- |
| Default (WebKit composites on the GPU) | 157, 164, 156 ms | 165, 156,
165 ms | 39 to 41 px / 40 to 43 px |
| `UNSLOTH_WEBKIT_DISABLE_COMPOSITING=1` | 289, 277, 280 ms | 0 ms (next
paint) | 144 to 189 px / 93 px |

With a GPU present, repaints with compositing off are fast, so the base
delay there is the animation itself (about 280 ms) rather than the 550
ms stall of a CPU-bound host. The harness gate I set before the run
(base median above 300 ms) therefore reads VOID; the numbers are above.

### Standalone WebKitGTK harness

GTK3 window with a `WebKitWebView` (system WebKitGTK 2.50.4), Xvfb, the
exact environment Desktop applies for NVIDIA X11 below 610 on WebKitGTK
< 2.54 (`WEBKIT_DMABUF_RENDERER_FORCE_SHM=1
WEBKIT_FORCE_DMABUF_RENDERER=1 WEBKIT_DISABLE_COMPOSITING_MODE=1`),
`GDK_SCALE=2` so CPU paints take about 100 ms like a 4K panel. Real X11
wheel clicks via XTest into a chat-like page (60 messages, code blocks,
blurred header and composer). "Reach" is the time from a wheel click
until the page has scrolled that click's distance. Arms alternated ABBA.

| Wheel input | Arm | Reach median | Reach max | Largest single-frame
jump |
| --- | --- | --- | --- | --- |
| 20 clicks, 50 ms apart (4 runs each) | smooth on (today) | 578 to 656
ms | 848 to 961 ms | 746 to 1067 px |
| | smooth off (this PR) | 56 to 78 ms | 129 to 203 ms | 279 to 372 px |
| 8 clicks, 200 ms apart (2 runs each) | smooth on (today) | 121 to 172
ms | 190 to 226 ms | 90 to 92 px |
| | smooth off (this PR) | 0 to 1 ms | 0 to 10 ms | 93 px |

The same harness applying this PR's predicate read `policy=NEVER` and
turned smooth scrolling off, giving the smooth off numbers.
`WEBKIT_DISABLE_DMABUF_RENDERER=1` (the plan on 2.54+) behaves the same:
559 to 564 ms reach with smooth on, 61 to 62 ms with it off. At 1x scale
with fast paints the stall does not appear, which is why composited
hosts are left alone.

## Tests

- New `smooth_scrolling_is_off_only_without_compositing` in
`linux_webkit.rs`: policy `Never` or a compositing-off value (`1`, `00`,
`false`, as WebKit reads it) turns smooth scrolling off; unset, `0` and
empty keep it.
- All 870 `studio/src-tauri` tests pass on Linux. Staging CI is green on
Linux, macOS and Windows (Tauri CI, Desktop app clean machine, Backend,
Lint, Wheel).

## Not tested

A physical NVIDIA X11 desktop session, WebKitGTK 2.54 inside the full
app, and the AppImage build. Browser panel webviews are unchanged.

## Before and after

Same Desktop binaries, reporter's plan, same 20 wheel clicks. Stills
taken at the same moments after the first click: AFTER is already
further down the chat while BEFORE is still catching up.

![Filmstrip: BEFORE (main) vs AFTER (this PR) at t=1.0, 1.4, 1.8 and 2.2
s](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/18267/filmstrip-94632724dc46.png)

![Side by side recording of the same wheel burst, BEFORE (main) left,
AFTER (this PR)
right](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/18267/scroll_side_by_side-a8f6b70181e6.gif)
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.

2 participants