Galaxy Shell / docs
Docs / Interface and features

Pushed state events

openspec/changes/state-events/design.md · Edit on GitHub ↗

On this page

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, the setInterval at the end of connect), 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, ingestState and its listeners, every sync* 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 capability capabilities.stateEvents. It answers like any command (with the state) and marks the connection as subscribed until it closes. A second subscribe is a no-op.

  • A subscribed connection also receives unsolicited lines:

    {"version": 1, "event": "state", "seq": 42, "state": { ... }}
    

    event lines have no id and no ok. seq grows by one per event on that connection. state is the same snapshot that a reply carries.

  • Only a connection that sent subscribe ever gets an event line. An older core never sends it, so it never meets a line without id (today it would refuse it as Invalid Smithay response and drop the connection).

When the compositor pushes

  • At the control tick (every 30 ms, ipc.rs init), after control_tick and 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: lastInputMs and pointer. 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 event line, the new one replaces it (latest wins) instead of being appended, so a slow reader never reaches MAX_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 inputRequests list), 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), if capabilities.stateEvents is true the core sends subscribe and replaces the 100 ms poll with a 2 s heartbeat poll. Without the capability it keeps the 100 ms poll unchanged.
  • consume accepts an event: "state" line only after its own subscribe succeeded on that socket, checks seq (a gap or a repeat is a protocol error that drops the connection, as an invalid reply does today), validates the state with validState and runs the same update() 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 (subscribe is allowed while locked, like state).
  • 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 state and 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.json gets the subscribe command and the stateEvents capability in the change that adds them, and scripts/check-host-skew.py reports the capability difference through its generic manifest warning.

Phases

  1. 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 without subscribe, seq order, no push while nothing changes, coalescing under a reader that does not read, a pointer-only change at most every 100 ms.
  2. Core: subscribe on the capability, the 2 s heartbeat, the seq check, and tests with the fake compositor of web-shell/test for both old and new compositors.
  3. 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.
  4. 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.