wire the broker to the compositor, containers and pointer

The four slices existed and nothing called them. Now the broker builds a
spatial container per session, reads back what the compositor actually did,
and aims the cursor into one container under a broker-wide lease.

Record schema 3 (registry.py): `container` {output, workspace, mode,
created_by, state}, `pointer` {bookmark, last_released_at, released_by} and
the compositor's `signature`. A v2 record is migrated on load, not refused —
its application is still running. Every field that could not be verified is
null; `container: null` means "no container", never "probably something".

Containers (new container_host.py, manager.py, launcher.py): `start`
allocates a slot from `WorkspaceAllocator`, runs `container_plan()`'s argv,
launches the app with the container stamp in its environment, then reads the
workspace, output and window back out of `clients -j`. Teardown removes the
output, releases the slot and reports survivors rather than claiming success
— and runs for an unprompted exit and for `gc` too, so no container is ever
left unattended. Broker start-up reconciles: adopt `hh-*` outputs a live
session claims, remove the rest, `contains_output()` being the only filter.
No IPC means `container: degraded` and lifecycle verbs unchanged.

The plans' argv are dispatched over the compositor's request socket rather
than by executing `hyprctl`, which is what hyprctl does with the same words;
the reply is checked, so a refused command is not recorded as a container.

Pointer (new driver.py, manager.py): a client for the driver's private
socket, and `pointer.acquire|move|button|click|release|state` on top of
`PointerLease`. The broker owns the lease, the driver executes. The bookmark
is marked on every move and before release and stored in the record, so it
survives a restart. On expiry `pressed()` is read before `expire()` and
`release_all` goes to the driver, because the lease cannot lift a button
itself; a sweep runs unprompted so the TTL is a promise.

containers.py to v2: `quarantine_plan()` -> `quarantine_argv()`, with the
before-any-per-session-rule ordering stated where the caller could get it
wrong. protocol.py: 9 NO_LEASE, 10 COMPOSITOR, the verb table, and the
`request_id` cache moved out of the server so the CLI agrees with it.

Tests: real AF_UNIX everywhere — a stateful fake compositor and the shipped
pointer driver behind a recording sink. No mocked sockets, no compositor, no
VM. 551 -> 693.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017mUq7QvQ9EZb2Wi35xj4cs
This commit is contained in:
HermenixandClaude Opus 5 committed 2026-10-02 19:47:33 +00:00
1 parent 20b2aee109
commit 129430bffd
20 files changed
+4805 -89

No files matched your search

+90 -22
View File
@@ -13,7 +13,6 @@ This module is framing and dispatch only. Every decision lives in
from __future__ import annotations
import asyncio
import collections
import contextlib
import logging
import os
@@ -35,14 +34,9 @@ DEFAULT_REQUEST_TIMEOUT_S = 5.0
#: A `kill` may legitimately take `grace` seconds, so it gets its own budget.
KILL_TIMEOUT_MARGIN_S = 5.0
#: Replies to mutating verbs are remembered so a CLI that died before reading
#: the reply can retry without launching a second application.
DEDUP_ENTRIES = 64
#: Verbs whose replies are cached by `request_id`. The read verbs are absent
#: deliberately: they are idempotent, so a retry costs nothing and a cached
#: `list` would be a stale one.
MUTATING_VERBS = frozenset({"start", "touch", "kill", "adopt", "gc"})
#: `request_id` idempotency lives in `protocol` (which verbs mutate, how many
#: replies are kept, what a replay looks like) because the CLI has to agree
#: with it and the CLI imports that module and not this one.
class ControlServer:
@@ -59,7 +53,7 @@ class ControlServer:
self.request_timeout_s = request_timeout_s
self.socket_mode = socket_mode
self._server: asyncio.AbstractServer | None = None
self._dedup: collections.OrderedDict[str, dict[str, Any]] = collections.OrderedDict()
self._dedup = protocol.IdempotencyCache()
self._ops: dict[str, Callable[[dict[str, Any], dict[str, Any]], Awaitable[dict[str, Any]]]] = {
"ping": self._op_ping,
"start": self._op_start,
@@ -70,6 +64,14 @@ class ControlServer:
"gc": self._op_gc,
"adopt": self._op_adopt,
"logs": self._op_logs,
"container.list": self._op_container_list,
"container.reconcile": self._op_container_reconcile,
"pointer.acquire": self._op_pointer_acquire,
"pointer.move": self._op_pointer_move,
"pointer.button": self._op_pointer_button,
"pointer.click": self._op_pointer_click,
"pointer.release": self._op_pointer_release,
"pointer.state": self._op_pointer_state,
}
# ------------------------------------------------------------------
@@ -188,9 +190,8 @@ class ControlServer:
"unknown_op", f"unknown op {op!r}", hint=f"known: {', '.join(sorted(self._ops))}"
)
if isinstance(request_id, str) and op in MUTATING_VERBS and request_id in self._dedup:
cached = dict(self._dedup[request_id])
cached["deduplicated"] = True
cached = self._dedup.lookup(op, request_id)
if cached is not None:
return cached
timeout = self.request_timeout_s
@@ -224,8 +225,7 @@ class ControlServer:
response.setdefault("elapsed_ms", elapsed_ms)
if isinstance(request_id, str):
response["request_id"] = request_id
if op in MUTATING_VERBS:
self._remember(request_id, response)
self._dedup.remember(op, request_id, response)
self.manager.audit.emit(
"request",
@@ -239,12 +239,6 @@ class ControlServer:
)
return response
def _remember(self, request_id: str, response: dict[str, Any]) -> None:
self._dedup[request_id] = dict(response)
self._dedup.move_to_end(request_id)
while len(self._dedup) > DEDUP_ENTRIES:
self._dedup.popitem(last=False)
# ------------------------------------------------------------------
# ops
# ------------------------------------------------------------------
@@ -290,7 +284,7 @@ class ControlServer:
return protocol.ok(id=record["id"], state=record["state"], session=record)
async def _op_gc(self, request: dict[str, Any], caller: dict[str, Any]) -> dict[str, Any]:
return protocol.ok(**self.manager.gc())
return protocol.ok(**await self.manager.gc())
async def _op_adopt(self, request: dict[str, Any], caller: dict[str, Any]) -> dict[str, Any]:
record = await self.manager.adopt(
@@ -300,6 +294,80 @@ class ControlServer:
)
return protocol.ok(id=record["id"], state=record["state"], session=record)
async def _op_container_list(
self, request: dict[str, Any], caller: dict[str, Any]
) -> dict[str, Any]:
return protocol.ok(**self.manager.container_list())
async def _op_container_reconcile(
self, request: dict[str, Any], caller: dict[str, Any]
) -> dict[str, Any]:
return protocol.ok(**await self.manager.container_reconcile(request.get("id")))
async def _op_pointer_acquire(
self, request: dict[str, Any], caller: dict[str, Any]
) -> dict[str, Any]:
return protocol.ok(
**await self.manager.pointer_acquire(
request.get("id"),
ttl_s=request.get("ttl_s"),
# Restoring is the default: the bookmark exists so a gesture
# can be picked up where it was left, and a caller that wants
# the centre of the output says so.
restore=bool(request.get("restore", True)),
)
)
async def _op_pointer_move(
self, request: dict[str, Any], caller: dict[str, Any]
) -> dict[str, Any]:
return protocol.ok(
**await self.manager.pointer_move(
request.get("id"),
request.get("lease_id"),
x=request.get("x"),
y=request.get("y"),
dx=request.get("dx"),
dy=request.get("dy"),
)
)
async def _op_pointer_button(
self, request: dict[str, Any], caller: dict[str, Any]
) -> dict[str, Any]:
return protocol.ok(
**await self.manager.pointer_button(
request.get("id"),
request.get("lease_id"),
request.get("button"),
request.get("state"),
)
)
async def _op_pointer_click(
self, request: dict[str, Any], caller: dict[str, Any]
) -> dict[str, Any]:
return protocol.ok(
**await self.manager.pointer_click(
request.get("id"),
request.get("lease_id"),
request.get("button", "left"),
request.get("count", 1),
)
)
async def _op_pointer_release(
self, request: dict[str, Any], caller: dict[str, Any]
) -> dict[str, Any]:
return protocol.ok(
**await self.manager.pointer_release(request.get("id"), request.get("lease_id"))
)
async def _op_pointer_state(
self, request: dict[str, Any], caller: dict[str, Any]
) -> dict[str, Any]:
return protocol.ok(**self.manager.pointer_state())
async def _op_logs(self, request: dict[str, Any], caller: dict[str, Any]) -> dict[str, Any]:
return protocol.ok(
**self.manager.logs(