Repository navigation
2026 11 26 admin tick design
History. Drafted 2026-11-26 for #226, to be built by PR #231 from its plan. #226's notes were the approved brief, and no draft spec was on the branch. This file finishes the brief against the code and against sse-starlette's source. "Found at plan time" lists what that changed. Its requirements are UI-34 and UI-35 in admin-ui.md, and the admin list row of runtime.md's limits table.
PR #231 built it. Its final review added to the design. UI-34 as shipped says "within 30 seconds plus a tick" and states the joiner rule. A partial build (the Grid or the store unreadable) is delivered but built again on the next tick. The REST flow and keep writes have no signal, so they fall under the bound. One test margin departed from the plan:
test_many_finished_calls_are_one_computationpolls at 0.4 s, not the plan's 0.2 s.
With one admin page open and no MCP traffic, the server spends about 23 mCPU, 41% of the process,
on the admin tick. Broadcast._run calls workspaces_payload every POLL_SECONDS (2 s), and each
call costs about 46 ms of CPU: a Redis SCAN and MGET, Configs.kept and revision, the flow
store's listing per workspace, and a Grid listing. That buys a list that rarely changes. A quiet
page also refetches GET /admin/workspaces and reopens /admin/events every 60 s. The stream's
keepalive is an SSE comment, which EventSource never shows to script, so the page's 45 s check
finds the stream silent.
This change rebuilds the list only when something marked it changed, or when the last build is
30 s old. The stream also sends a named beat event that the page counts.
From #226's thread (Dr K, 2026-11-26):
-
The bound is 30 s (
REFRESH_SECONDS), stated in UI-34. It is the longest a change with no signal can take to show, and it matches the page's 30 s fallback (UI-35). -
The beat is a named SSE event,
beat. The page listens withaddEventListener('beat', …). A beat can never be read as a payload. - The sse-starlette points are checked against the installed version before UI-34 says what the ping does. See Found 1 and 2.
These mark the list changed:
| Signal | Where | Nudges the tick |
|---|---|---|
call.finished on the bus (new) |
SeleniumMCP.__init__, subscription admin-calls
|
no |
Broadcast.changes on an admin route that isn't a GET |
invalidate() |
no |
session.opened, session.ended
|
the admin subscription, poke()
|
yes |
| a filed recording |
collector.on_filed, poke()
|
yes |
call.finished covers every MCP, HTTP and flow call on this pod: the page, history, files, flows
and site data a tool changes. It marks without nudging, so traffic costs at most one build per
POLL_SECONDS. The server runs as one replica, so no other pod writes.
These changes have no signal, and the 30 s bound covers them:
- a record or sub-session expiring in Redis;
- the Grid reaping a browser nothing watches (keep-alive 0 with no capture, recording or control);
- downloads, or capture counts, that the page makes between calls;
- a hand edit of a workspace config or of kept files on disk;
- the Grid's version or node for a session.
New state, all of it touched only on the event loop:
-
_changes: int, bumped bymark()and byinvalidate(); -
_seen: int, the value of_changeswhen the computation that became_lateststarted.
_latest keeps its shape, (started, payload, text), and _floor keeps its meaning.
-
mark()bumps_changes, and does nothing else. -
invalidate()bumps_changes, sets_latest = Noneand_floor = now, as today. -
poke()isinvalidate()and then a nudge, as today. -
Stale. The latest is stale when there is none, when
_seen != _changes, or when it started at leastREFRESH_SECONDSago. -
Current. The latest is current when it is younger than
FRESH_SECONDS, or when it is not stale.fresh()andjoin()hand out the current one. A latest that isn't current is always stale, so a joiner that is handed nothing nudges a tick that will compute. -
_run. It still wakes everyPOLL_SECONDS, or on a nudge. It computes only when the latest is stale, and otherwise does nothing: no build, no delivery. Before it starts a computation it reads_changeson the loop. A success stores that value as_seen, together with_latest, whenstarted >= _floor. So a mark that lands while a computation is under way is never counted as seen, and the next tick computes again. A failed computation stores nothing, so its mark is still unseen and the next tick tries again. -
GET /admin/workspacesanswersfresh()when it is current, and otherwise computes inline, as today.
-
/admin/eventspassesping_message_factory=lambda: ServerSentEvent(event="beat", data="")withping=HEARTBEAT(20 s). Each beat is written asevent: beat, thendata:, then a blank line. -
Live.#watchinui/src/admin/live.svelte.tsaddsevents.addEventListener('beat', () => this.#beat()). Thecatchinonmessagestays as the guard for a frame that isn't JSON, and its comment stops calling that frame a keepalive. - The page's 30 s timer and 45 s check stay. They still catch a stream that a proxy swallowed, or a
signed link that expired: an
EventSourcereconnect that gets a 401 stops for good, and the beats stop with it. - The capture tail (
http/admin/capture.py) keeps its comment ping. It has no fallback timer.
-
sse-starlette's ping runs on a fixed timer. Read at
v3.3.0(the floor,>=3.3) and atv3.7.1(the newest, which an image build installs, sincescripts/requirements.pypasses the floor through unpinned). In both,EventSourceResponse._pingloopswhile self.active: await anyio.sleep(self._ping_interval), then sendsping_message_factory()or its default comment. Nothing resets the timer when data is sent. So UI-34 says "every 20 seconds", not "after 20 seconds of no change", and theHEARTBEATcomment inworkspaces.pyis corrected the same way. Both versions takeping_message_factory: Callable[[], ServerSentEvent] | None, and both exportServerSentEventfromsse_starlette, so the floor doesn't move. -
data=""is written asdata:.ServerSentEvent.encodewrites data lines underif self.data is not None, and an empty string splits into one empty chunk. By the WHATWG algorithm, adata:line makes the data buffer"\n", which isn't empty, so thebeatevent is dispatched withdata"". Adata-less event would not be dispatched. -
A joiner on a quiet list would get nothing. Today
joinhands out_latestonly while it is underFRESH_SECONDS(1 s) old, and otherwise nudges a tick that always computes. Once the tick skips unchanged lists, a page joining 10 s after the last build would nudge a tick that does nothing, and it would wait up to 30 s for its first event. So "current" (§2) covers an unchanged latest within the bound too, forjoinandfresh()alike, and the nudge goes out only when the latest is stale. -
_latestkeeps its 3-tuple shape.test_a_poke_forgets_the_last_broadcast_and_ticks_now(tests/test_recording_collector.py) writes it directly, so the counter that a build saw is a separate field,_seen. -
The existing broadcast tests count ticks.
test_every_connected_page_is_sent_the_same_eventsand the other tick-counting tests intests/test_admin_events.pydepend on every tick computing. They setREFRESH_SECONDS = 0.0, which keeps what they test (pacing, dedup, the late joiner) and is exactly today's behaviour.test_the_listing_is_the_last_broadcast_while_it_is_freshasserts that a stale listing is never served, which now means a listing past the bound or marked since. -
The
_listenhelper reads everydata:line as a payload. A beat'sdata:line would read as an empty payload. It now splits each body into frames, and a frame withevent: beatgoes to a beats list, not to the payloads. -
The files tab's
header()(http/admin/files.py) callsbroadcast.computeon every request. That's out of scope here, and the PR says so. - No image is built for a pull request (CONTRIBUTING, "CI"), so the before and after CPU need an image of the branch running on the cluster. See the plan's "After the tasks".
One changelog line:
- An open admin page costs next to nothing while nothing changes, and no longer refetches the list every minute; a change made outside the server shows within 30 s.
| Id | Becomes |
|---|---|
| UI-34 | One server task, running only while a page is connected, wakes every 2 seconds and computes the list only when a change was marked since its last computation started, or that computation is 30 seconds old, or there is none. These mark a change: a call finishing on this server (any surface), a route that changes what the list shows (as listed today), a session opening or ending, and a recording filed. The last two compute at once. A change with no signal (a record expiring, the Grid reaping a browser nothing watches, a file edited on disk) shows within 30 seconds. A page receives a message when the payload differs from its last. The stream sends a beat event every 20 seconds from when it opens, whatever else it sends |
| UI-35 | Adds: a beat counts as hearing from the stream, so an open stream never trips the fallback |
| runtime.md, limits | The row reads "Admin list: tick; refresh bound; fallback poll; stream beat", "2 s; 30 s; 30 s; 20 s", citing UI-34, UI-35 |
- The files tab's
header()computing the whole list per request (Found 7). - A beat on the capture tail.
- A change signal for Redis expiry (keyspace notifications) or for the disk.
The action pages are generated from the server's tool schemas, so they describe the version that shipped.
selenium-flow · MIT
Start here
Guides
Lifecycle
Going places
Doing things
Getting things out
Site data
Console and network