Skip to content

[deno] Don't panic on a lost device, and resolve device.lost after destroy() - #10

Open
matthargett wants to merge 2 commits into
review-base/trunk-60cef2be8from
fix/deno-webgpu-device-loss-20261126
Open

matthargett wants to merge 2 commits into
review-base/trunk-60cef2be8from
fix/deno-webgpu-device-loss-20261126

Conversation

@matthargett

@matthargett matthargett commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Connections

Found running the WebGPU CTS with cts_runner on a Mali-G52 MC2 whose driver loses the device in several tests (#7, #8 and #9 are the driver-side fixes). Nothing here is specific to that device; the second commit changes what cts_runner reports on macOS too.

Description

destroy() and device.lost. GPUDevice.destroy() polls once without blocking. wgpu only calls the device-lost closure once submissions have completed, so with one in flight device.lost never resolves. The CTS awaits it at teardown; the event loop then runs dry and cts_runner exits with status 0 without results for the remaining cases, which cargo xtask cts counts as a pass. destroy() now waits for the device's work to finish.

Panics on a lost device. mapAsync() and onSubmittedWorkDone() unwrap() a poll that fails once the device is lost, as do their completion callbacks' channel sends. The task that resolves device.lost unwrap()s a resolver the JS object's finalizer may already have removed. mapAsync() now rejects with an AbortError, onSubmittedWorkDone() resolves, and the rest return quietly. The per-device tables are keyed by a counter instead of the device's address, which could be reused.

Testing

  • macOS: cargo fmt --check and clippy for deno_webgpu and cts_runner are clean; cargo test -p cts_runner passes.
  • Metal (Apple M4 Max), cts_runner built from trunk 60cef2be8 and from this branch:

uncapturederror:iff_uncaptured on Metal: no results and exit status 0 on trunk, 4 of 4 with this PR

  • Mali-G52, the same comparison:

uncapturederror:iff_uncaptured on the Mali-G52, before and after

A lost device followed by mapAsync on the Mali-G52, before and after

  • CTS uncapturederror:iff_uncaptured and error_scope on the Mali-G52, 53 cases: on trunk 26 report a result (two processes exit with status 0 early); all 53 pass with this branch.
  • With all four PRs applied, a full run of cts_runner/test.lst on the device (54,915 of 54,931 cases; 16 left out to protect the phone's memory): 45,478 pass, 86 fail, 9,351 skip. 85 of the failures are in selectors marked fails-if(vulkan).
  • Not tested on DX12 or desktop Vulkan.

Squash or Rebase?

Rebase. The two commits are independent.

LLM Use?

Claude Code (Claude Mythos 5.2) found these on the device, traced the silent exit to destroy(), wrote the code, ran the tests and drafted this description.

Three places in deno_webgpu aborted the process when the driver lost the
device:

- `mapAsync()` and `onSubmittedWorkDone()` wait with
  `poll(wait_indefinitely()).unwrap()`. A lost device makes the poll fail.
  Reject the mapping with an `AbortError`, and resolve
  `onSubmittedWorkDone()`.
- Their completion callbacks `unwrap()` a channel send whose receiver is gone
  once the wait has failed.
- The task that resolves `device.lost` and the finalizer of the JS device
  object both remove the lost-promise resolver, and the task `unwrap()`s it.
  If the object is collected between the loss and the task, the task panics
  (`adapter.rs`, "called `Option::unwrap()` on a `None` value").

The per-device tables were also keyed by the address of the wgpu device, so a
stale task or finalizer for a freed device could act on a newer device at the
same address. Key them by a counter instead.
`GPUDevice.destroy()` polled the device once without blocking. wgpu calls the
device-lost closure only once the device's submissions have completed, so if
one was still in flight the closure was not called, nothing polls a destroyed
device again, and `device.lost` never resolved.

The WebGPU CTS awaits `device.lost` when it tears a test's device down. For a
test that had just called `queue.submit()`, such as
`api,operation,uncapturederror:iff_uncaptured`, the event loop ran out of work
with that promise pending, and `cts_runner` exited with status 0 without
printing a result for any case, which `cargo xtask cts` counts as a pass.

Wait for the device's work to finish in `destroy()`.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T22:21:38.328759Z 0d65760 PR opened
ℹ️ 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.

@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: 0d65760398

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

Comment thread deno_webgpu/queue.rs
Comment on lines +98 to +100
.is_err()
{
return Ok(());

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 Complete the entire queue wait when polling fails

If the device is lost while submissions are outstanding, returning Ok(()) only completes device_poll_fut; the tokio::try_join! below still waits for receiver_fut. In wgpu-core/src/device/resource.rs, a HAL wait or fence-query error returns from Device::maintain before queue maintenance collects submission callbacks, and Device::lose does not invoke those callbacks either. Consequently, the sender can remain stored in the queue while this method stops polling, leaving onSubmittedWorkDone() pending indefinitely. Make the poll-error path complete the overall operation without continuing to await the callback.

Useful? React with 👍 / 👎.

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.

1 participant