Galaxy Shell / docs
Docs / Interface and features

Panic triage of the Smithay compositor

docs/panic-triage.md · Edit on GitHub ↗

On this page

Panic triage of the Smithay compositor

Doc status: current contract. Triage of the non-test unwrap and expect calls of native/smithay; indexing and overflow not triaged. Checked 2026-11-10.

Step 3 of stream C of openspec/changes/audit-2026-11-10/design.md (finding F7, "a panic ends the session"). A panic in the compositor ends the login, so every unwrap() and expect() that untrusted or runtime data can reach is a way to end it. This document records the triage and the rule that keeps it true. It adds no crate-wide lint.

Method

  1. Every .unwrap( and .expect( in native/smithay/src outside test code, found by a brace-matching scan that drops every #[cfg(test)] item (modules and functions) and every *_tests.rs file. A line scan that only cuts a top-level test module miscounts: input.rs and grabs.rs keep test code lower in the file.
  2. Each site read in its function: where the value comes from, what built the map entry, the Option, the lock or the slice, and who can change it.
  3. A site is class C when data from a Wayland client, the control socket, the outputs, a file read at run time, the clock or the GPU can make it fail. A fix returns the existing error type, refuses the element or the client, or logs and skips; it never changes the success path.

Classes and counts

254 hits in 47 files.

Class Count Meaning
A. Invariant 251 Cannot fail by construction (reasons below). Left as is.
B. Startup only 1 Fails before the session runs: a refused start. Left as is.
C. Reachable 1 Fixed (table below).
Not a panic 1 drm.rs .expect(head.crtc, ...) is a method named expect of the flip tracker.

C-deferred: none.

Most files by hits: desktop/canvas_mode.rs 40, desktop.rs 28, desktop/layout.rs 19, handlers/xdg_shell.rs 17, input.rs 15, grabs.rs 12, wgpu_workspace.rs 10, glass_mask.rs 9, plain_glass.rs 7. ipc.rs and the command handlers of desktop.rs (JSON from the control socket) hold none: they return Result<_, &str>.

Class A, by reason (about, by pattern)

Reason Sites Why it cannot fail
window.toplevel().unwrap() 69 Window values are created only by Window::new_wayland_window in handlers/xdg_shell.rs (new_toplevel). The compositor has no XWayland, so every Window is an xdg toplevel.
seat.get_keyboard()/get_pointer().unwrap() 54 Compositor::new adds both to the seat (state.rs, a failed keyboard falls back to the default keymap, a second failure is a startup error). They are never removed.
desktop.windows.get_mut(&w).unwrap() and get 29 The window comes from the same map (windows.keys().find(..)), from register_window just before, or from a list filtered by windows.get(..). Dead windows leave the map in apply_layout and the visibility predicates use get and refuse a missing entry.
Per-window GPU target maps (targets, active, textures, planes, Program, Programs, Cache) 45 + part of 52 The entry is inserted or ensured earlier in the same function (self.target(..)?, insert_if_missing, a contains_key check, an expired key list built from the map). Single-threaded render path.
lock().unwrap() 5 Mutexes of Smithay's own role data (XdgToplevelSurfaceData, CursorImageSurfaceData) and the xkb state, all used on the compositor thread only. A poisoned lock means an earlier panic.
Validated input 4 visual_style.rs hex channel (the #rrggbb shape and ASCII hex digits are checked first); themes.rs PNG chunk length (offset + 12 <= len); effects.rs linear() stops (2..8 stops, so non-empty); snapshot.rs to_value of a plain enum.
Outputs 4 output.current_mode() in drm.rs (and, at the time of the triage, winit.rs, deleted at step 8 of the GLES removal): every output gets its mode when it is created (change_current_state), before it renders.
Other rest capture.rs job taken after is_some_and(done); drm.rs held frame taken after a let Some(..) = as_ref(); ClientState of client_compositor_state (every client is inserted with it in state.rs); canvas_mode.rs grid formation after grid_view_camera returned Some; the position of a workspace key inside its own match arm.

Class B

Desktop::new (desktop.rs) reads /proc/sys/kernel/random/uuid once at startup and expects it.

Class C sites

Site before the change What reaches it What it does now
desktop.rs:1238 checked_add(1).expect("window IDs exhausted") in register_window Window IDs are a u32 counter that never wraps. A client that opens and closes toplevels (or many clients) for long enough ends it, and the compositor panicked on the next toplevel. The new window is refused like one over the cap: a warning, send_close and false, so it is not mapped. The counter stays put and the session goes on. Regression test: an_exhausted_window_id_counter_refuses_the_window_and_keeps_the_session in session_lock_tests.rs (the field Desktop::next is pub(crate) for it).

Checked and left, with the reason, because they look reachable:

  • handlers/xdg_foreign.rs:243 reads the role data of a client-named child: the line before it requires a tracked, live xdg toplevel.
  • handlers/xdg_shell.rs:339 handle_commit finds the window in the space first.
  • handlers/compositor.rs:28 ClientState: the only insert_client is in state.rs.
  • drm.rs:324 and the outputs of winit.rs (deleted at step 8): see Outputs above.
  • Other panic macros outside tests: unreachable! in themes.rs:233,571 (path components already checked as Normal) and main.rs:187 (refused by Options::parse). Those of layers.rs and canvas_warp.rs sit in test modules.

Not covered by this triage, by design: slice and map indexing (x[i], map[&k]), arithmetic overflow and unreachable!. They can panic too; a later pass can triage them the same way.

Rule for new code

  • No unwrap() or expect() on runtime or client data in non-test code: Wayland requests and surface state, control socket JSON, output and mode data, files read at run time, the clock, renderer and GPU results, integer conversions of those values. Return the function's error type, refuse the command with a typed error string, or log and skip the frame, element or client.
  • An invariant carries expect("reason") or a comment that names what guarantees it (the insert above, the check before, the startup that adds it).
  • Startup code (main, backend init, required environment) may fail the start.
  • #[cfg(test)] code is free to unwrap.