Pushed state events
Doc status: proposal. Pushed state events in place of the 100 ms poll; nothing implemented. Checked 2026-11-10.
Stream C of openspec/changes/audit-2026-11-10/design.md, finding F4. The current contract is the 100 ms poll described below.
Today
- The control socket of the compositor (
native/smithay/src/ipc.rs) is request and response only. Every successful reply carries the whole state snapshot (desktop_snapshot()), whatever the command was. - The core polls with
{"action": "state"}every 100 ms on its control connection (web-shell/core/smithay.js, thesetIntervalat the end ofconnect), one request in flight at a time (this.polling). - Each state answer runs
update(): the input requests (Super tap, Super+N, the screenshot keys, the workspace keys) by generation,ingestStateand its listeners, everysync*of the core (chat_hold,agent_route,canvas_warp,visual_style,chat_alpha_glass, hot corners, the dock side, sharp zoom), the window bindings and the login restore. - The poll also keeps the connection alive: the compositor closes a connection that sent nothing for 30 s.
Costs of this shape:
- A key that the compositor hands to the core (an input request) waits up to 100 ms plus one round trip before the core sees it.
- The compositor builds and serializes the whole snapshot ten times a second while nothing
changes, and the core parses and validates it (
validState) ten times a second. - Every reply of every command also carries the whole state, so a burst of commands multiplies the cost.
Proposal
A control connection can ask for pushed state events. The poll stays as the fallback and as a slow heartbeat.
Wire
-
New command
subscribe(no fields), gated by the new capabilitycapabilities.stateEvents. It answers like any command (with the state) and marks the connection as subscribed until it closes. A secondsubscribeis a no-op. -
A subscribed connection also receives unsolicited lines:
{"version": 1, "event": "state", "seq": 42, "state": { ... }}eventlines have noidand nook.seqgrows by one per event on that connection.stateis the same snapshot that a reply carries. -
Only a connection that sent
subscribeever gets aneventline. An older core never sends it, so it never meets a line withoutid(today it would refuse it asInvalid Smithay responseand drop the connection).
When the compositor pushes
- At the control tick (every 30 ms,
ipc.rsinit), aftercontrol_tickand the socket poll, for each subscribed connection: build the snapshot once for all of them, and push it when it differs from the last one pushed to that connection. - The comparison leaves out the fields that change on their own:
lastInputMsandpointer. Their current values still ride in every event and every reply. A change of only these fields pushes at most once per 100 ms, so the pointer reader of the black-hole wallpaper (openspec/specs/hex-crystals-wallpaper/spec.md) keeps today's rate. - Coalescing: when the output buffer of a connection still holds an unsent
eventline, the new one replaces it (latest wins) instead of being appended, so a slow reader never reachesMAX_RESPONSE(256 KB) because of events alone. Replies are never dropped or reordered relative to each other. - An input request is a state change (the
inputRequestslist), so it pushes at the next tick, at most about 30 ms after the key.
What the core does
- After the connect sequence (the first
state, the workspace resend, the lock host and the lease renewals, which keep their order), ifcapabilities.stateEventsis true the core sendssubscribeand replaces the 100 ms poll with a 2 s heartbeat poll. Without the capability it keeps the 100 ms poll unchanged. consumeaccepts anevent: "state"line only after its ownsubscribesucceeded on that socket, checksseq(a gap or a repeat is a protocol error that drops the connection, as an invalid reply does today), validates the state withvalidStateand runs the sameupdate()as a reply. Everything downstream (sync*, bindings, listeners) is unchanged.- The heartbeat keeps the 30 s idle rule of the compositor satisfied and catches a compositor that stopped pushing.
Boundaries
- No new authority: the events go only to the control connection that asked, which is already same-UID and already reads the whole state. Nothing reaches generated HTML, plugin panels, agent tools or scheduled turns. The wallpaper stream and the host routes keep their own filters in the core.
- While locked the state is readable today, so the events keep flowing while locked; the
lock rules of the commands do not change (
subscribeis allowed while locked, likestate). - No window pixels: the snapshot holds none today and the events carry the snapshot only.
Compatibility window
| Core | Compositor | Result |
|---|---|---|
| old (poll only) | new (stateEvents) |
The core never subscribes and polls at 100 ms, as today |
| new | old (no stateEvents) |
The core sees no capability and polls at 100 ms, as today |
| new | new | Events plus a 2 s heartbeat |
- The compositor keeps answering
stateand keeps the full snapshot in every reply for as long as any supported core may poll: at least until the read-only recovery release of openspec/specs/immutable-base/spec.md and every supported fallback ship a core that subscribes. - The core keeps the 100 ms poll path for as long as a supported compositor may lack the capability, including the known-good fallback compositor of the recovery path.
- Rollback is a revert of either side; the table above shows that each mixed pair falls back to the poll. No setting, as with the other protocol changes.
protocol/control.jsongets thesubscribecommand and thestateEventscapability in the change that adds them, andscripts/check-host-skew.pyreports the capability difference through its generic manifest warning.
Phases
- Compositor:
subscribe,capabilities.stateEvents, the push at the control tick with the volatile fields left out of the comparison and the latest-wins coalescing, and Rust tests for: no event withoutsubscribe,seqorder, no push while nothing changes, coalescing under a reader that does not read, a pointer-only change at most every 100 ms. - Core: subscribe on the capability, the 2 s heartbeat, the
seqcheck, and tests with the fake compositor ofweb-shell/testfor both old and new compositors. - Measure before calling it done: CPU of the core and the compositor at rest and while dragging a window, and the delay from a Super tap to the core, against the poll. The nested QA run (docs/nested-qa.md) can measure the delay; the CPU figures need the user on the real session.
- Later and separate: deltas instead of whole snapshots, only if phase 3 shows the snapshot size matters.
Open questions
- Whether
windows[].*fields that animate (a canvas window rectangle during a camera fly) change at every tick; if they do, phase 1 needs the same 100 ms bound for them, or the push rate during an animation would be 33 per second. - Whether other readers of the control socket (scripts/smithay-pointer.py,
scripts/nested-qa.py) want
subscribe; they keep working without it.