Skip to content

Control channel: give up requests a hidden Wayland window can't answer, never run them late (#718) - #1070

Merged
bflatastic merged 1 commit into
storytold:mainfrom
emmertex:pr/wayland-control
Oct 13, 2026
Merged

bflatastic merged 1 commit into
storytold:mainfrom
emmertex:pr/wayland-control

Conversation

@emmertex

Copy link
Copy Markdown
Contributor

What

  • apps/lightcraft/src/control_server.rs: a request now waits in short slices and watches the app's frame counter. If the app has not started the request and has drawn no frame for 5 s, the server gives the request up and replies:

    the app drew no frame for 5 s, so the request was not run: its window is probably not visible (on Wayland a window on a hidden workspace or minimized is not redrawn, which pauses the app). Bring the window on screen and send it again

    A request the app has already started still gets the full 60 s, because a long command blocks frames while it runs.

  • ControlRequest now carries a state (pending, taken or abandoned, set atomically by whichever side gets there first). drain_control skips abandoned requests, so a request that timed out no longer runs later when the window comes back (the double document in the report).

  • docs/control-protocol.md describes the behaviour and what to do instead (keep the window on screen, or use headless or lightcraft-cli mcp without --connect).

  • crates/pipeline/src/spots.rs uses as_chunks::<3>(), because main fails the newer clippy chunks_exact_to_as_chunks lint (same change as Issue #989: clippy 1.99, fill_box reads its buffer with as_chunks::<3>() (item 4) #997).

Why

#718: on Wayland, the control channel and mcp --connect stalled for 60 s per request while the window wasn't visible, and the stalled requests ran later, a second time.

How tested

  • New unit tests in control_server.rs:
    • an app drawing no frames gets the request given up quickly, with the reason, and the request can no longer be taken;
    • a taken request waits for its reply even though frames stop;
    • an app that keeps drawing is simply waited for.
  • Ran the desktop app on Linux (Wayland, AMD Radeon 8060S, Vulkan) with --control 18731 --demo: ui.inspect answered in 0.1 s. I couldn't reproduce the hidden-workspace case end to end, since that needs OS-level window moves, which the project rules forbid.
  • cargo xtask ci: all 8 steps passed (fmt, clippy, heif, test, parity, layers, assets, wasm).

Not done: actually draining requests while the window is hidden. The app's command loop runs inside egui frames, so that would need a separate non-UI execution path.

Closes #718

🤖 Generated with Claude Code

… run it late (#718)

On Wayland a window on a hidden workspace or minimized gets no frame
callbacks, so queued control requests waited 60 s and then ran when the
window came back, doubling retried work. The server now abandons a request
the app hasn't started after 5 s without a frame, says why, and the app
skips abandoned requests. Running requests keep the full 60 s. Also
as_chunks in spots.rs for the newer clippy lint.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@tydude001

Copy link
Copy Markdown
Contributor

I ran the hidden-workspace case end to end, the one the description says couldn't be tested. Setup: headless sway
1.11 (Wayland), lightcraft --memory --control, wgpu renderer. I compared this PR (2c3d7a74) with its
parent main (76b53778). The window is hidden with swaymsg workspace 2, an empty workspace. Late runs are read
back through album.create, whose album ids go up by one per run, so a request that runs late leaves a gap.

main this PR
visible: album.create 0.0 s, id 8 0.0 s, id 8
hidden: ui.inspect 60.0 s, timeout 5.0 s, "the app drew no frame for 5 s, so the request was not run …"
hidden: album.create 60.0 s, timeout 5.0 s, same message
shown again: album.create id 10 (the timed-out request ran late as 9) id 9 (the given-up request never ran)
hidden, then shown 2 s after the request answered after 2.0 s answered after 2.0 s, not given up
visible, idle for 20 s first 0.0 s 0.0 s

So both parts of #718 reproduce on main, and this PR fixes both. A request that is given up now fails after 5 s with
a reason, and it doesn't run when the window comes back.

One difference from the issue: on sway 1.11, a window fully covered by a fullscreen window on the same workspace
kept getting frames. Requests were answered right away on both builds, so I could only reproduce the hidden-workspace
case.

Not tested: KWin or GNOME, mcp --connect, llvmpipe (LIGHTCRAFT_GPU=0), and a long command already running when
the window is hidden.

@bflatastic

Copy link
Copy Markdown
Member

Landed on main in #1431. Thank you, @emmertex!


Generated by Claude Code

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.

Control channel (and MCP --connect) stalls while the window is not visible on Wayland

3 participants