Streaming and rendering
One poller, many viewers
Section titled “One poller, many viewers”Opening a dashboard authorizes dashboard:view and renders LiveDashboard,
which opens exactly one EventSource to /api/dashboards/[id]/stream.
Server side (.../stream/route.ts and src/lib/poller/registry.ts):
- The SSE handler re-authorizes the subscriber against the dashboard’s workspace
— SSE is cookie-authenticated — then attaches to the shared poller for
that dashboard.
getPollerguarantees one poller per dashboard, shared across all subscribers; a newer saved version replaces the old poller. - Each tick (
max(minRefreshIntervalMs, spec.refreshIntervalMs)), the poller executes every panel once viamakePanelExecutor. A panel with arefreshIntervalMsof its own (#114) runs on that cadence instead, under the same floor. The poller keeps one timer and a due time per distinct cadence; when it fires, every cadence due within a quarter of its interval (at most a second) runs in the same cycle, so a 15-second and a 30-second panel make one cycle every 30 seconds, not two. A panel with its owntimeRangeis run over that window, resolved on the server like the dashboard’s, and itspanelframes carry the window they were selected over. For each panel it:- Re-resolves the source every tick. If the source is missing,
tombstoned, or belongs to a different workspace than the dashboard, it
emits a
tombstoneevent. All three cases look identical, so a crafted spec cannot probe for cross-workspace sources. - Re-runs its source kind’s guard (
validateSql,validatePromqlorvalidateLogql), builds the guarded plan, and executes it. - Remembers the result and computes each subscriber’s delta. The
poller keeps every panel’s last result. For a time-series panel each
subscriber has its own cursor (the newest timestamp it has been
sent), and
computeDeltasends it the rows from that timestamp on as anappendcarryingsince. The browser drops what it holds fromsinceand puts these in its place, so the newest bucket of a series, still filling, is updated rather than frozen at its first value. Non-time panels are sent as a fullreplacesnapshot.
- Re-resolves the source every tick. If the source is missing,
tombstoned, or belongs to a different workspace than the dashboard, it
emits a
Events go to every subscriber’s stream. The event types are panel
(append/replace), panel-error, panel-degraded, panel-waiting,
dashboard-error, tombstone, and tick, plus the per-stream
session-expired, session-ended, access-ended and drop described below.
When a panel keeps failing
Section titled “When a panel keeps failing”A failed execution used to be retried on the next tick, forever. A source
that was down, or a statement that always timed out, was hit again every
refresh by every dashboard showing it. The poller now counts each panel’s
consecutive failures (src/lib/poller/backoff.ts):
- Under
POLLER_FAILURE_THRESHOLD(default 3), nothing changes. The failure is apanel-errorand the next tick tries again, so a single blip costs one refresh. - From the threshold on, the panel sits out until its
retryAt. The wait is twice the refresh interval and doubles with each further failure, up toPOLLER_MAX_BACKOFF_MS(default 5 minutes): 30s, 60s, 120s, 240s, then 5 minutes on a fifteen-second dashboard. The viewer gets apanel-degradedframe with the error, the count andretryAt, and the panel shows when it is tried next. - One success clears it, and the panel is back on the refresh interval at once.
Only failures that reached the source count. A statement the guard refuses or a missing row-filter claim never runs, so it puts no load on the source to back off from.
Retry now on a degraded panel posts to
/api/dashboards/[id]/panels/[panelId]/retry, which runs it at once on every
poller showing the dashboard. The poller ignores a retry within
MIN_REFRESH_INTERVAL_MS of the panel’s last attempt, and a failed retry
counts like any other failure, so the button can’t run a failing statement
faster than a refresh would.
The state is per panel, per poller. Two dashboards on the same failing source each back off on their own. A source-wide breaker would stop a down source being tried by every panel that reads it, and is a follow-up if it turns out to be needed.
Joining and resuming
Section titled “Joining and resuming”A subscriber that joins a poller already running — a second viewer, or a
reconnect while someone else is watching — is caught up at once from the
poller’s last results: a replace per panel and the last tick, without
waiting for the next cycle (#43).
Each time-series frame carries an SSE id:, the subscriber’s cursors and the
spec version (src/lib/poller/resume.ts). EventSource sends the last one
back as Last-Event-ID when it reconnects by itself; LiveDashboard passes it
as ?lastEventId= when it builds a new EventSource for the same window (a
manual Reconnect, a tab shown again). The subscriber then gets only the rows
it missed, and the panels keep their history. An id from another spec version,
or one that does not decode, is ignored and the subscriber gets a full
snapshot. The id is not trusted: the worst a forged one can do is ask for rows
the viewer could already see.
The stream also sends a comment every 15 seconds, so a proxy that closes quiet connections does not close one whose dashboard refreshes slowly.
How long a stream stays authorized
Section titled “How long a stream stays authorized”The handler authorizes a subscriber when it connects, and the response then
stays open. So that one check cannot outlive the session it was made with,
each stream is guarded by the token it was opened with
(src/lib/auth/stream-guard.ts, #32), and ended with a named event:
| Event | When | The browser |
|---|---|---|
session-expired |
the token reaches its exp |
reconnects with its last event id, renewing first unless another tab already has |
session-ended |
the realm ends the session (#28) | tries one renewal, which is refused, and the sign-in banner appears |
access-ended |
a re-check finds the dashboard deleted, or no longer in the viewer’s workspaces | stops and says so above the grid |
The re-check runs every SSE_REAUTH_INTERVAL_MS (default 60s): it verifies
the token again and re-authorizes dashboard:view against the dashboard as it
is now. A database error during it keeps the stream and tries again next time.
A stream cannot see the browser’s newer cookie, so expiry ends it rather than extending it. The reconnect is cheap — it resumes, and the panels never go stale — and it is authorized from the renewed token, which is how a group the realm removed reaches an open stream: within one session-token lifetime, half the realm’s refresh lifetime (#27). Only the one subscriber is closed; the others on the same poller carry on.
A tick is sent only when the whole cycle completed. A cycle that failed
before the panels — an unresolvable time range, say — sends a
dashboard-error instead, the poller reschedules anyway, and the viewer shows
the failure above the grid rather than a Live badge over frozen charts.
Many viewers, slow viewers
Section titled “Many viewers, slow viewers”A stream is one subscriber of the shared poller, written by
subscriberStream in src/lib/sse-stream.ts (#489):
- Serialized once.
encodeEventFrame(src/lib/sse.ts) keeps each event object’s bytes, and the poller hands every subscriber on the same cursor the same delta object. A cycle on a dashboard a hundred people watch is serialized once per distinct payload, not once per viewer. - Backpressure. Each stream buffers up to 1 MiB unread. A stream still
over that when
SSE_SLOW_TICKScycles in a row complete (default 3) is sent adropframe with a spreadretry:hint and closed. A stalled viewer, or a proxy in front of one, can no longer make the server buffer without limit, and the other viewers are untouched. The drop is recorded as a seconddashboard.streamaudit row withoutcome: failureanddetail.dropped. The browser treatsdroplike a drain and reconnects, resuming from its last event id. - Headers. Every stream response carries
Cache-Control: no-cache, no-transformandX-Accel-Buffering: no, so an nginx-style proxy or ingress neither buffers nor compresses it. - Resume. A reconnect with a valid
Last-Event-IDgets only what its cursors are missing, and an unknown or stale id gets a full snapshot. A reconnect at token expiry passes the id in the query and resumes the same way.
npm run load:stream opens many viewers against a demo instance, some of
them stalled, to see this hold.
Merge, never recreate
Section titled “Merge, never recreate”Client side (LiveDashboard.tsx → PanelView.tsx → EChart.tsx):
LiveDashboard fans SSE events out to per-panel React state:
appendrows are concatenated into a bounded rolling window (MAX_WINDOW_POINTS, default 1,000) — old points fall off the front.replaceswaps the window, held to the same budget;panel-error,panel-degradedandtombstoneflip panel status.panel-waiting(#487) means the panel’s source had no free slot or connection this cycle. The panel keeps its rows and shows waiting. It is not remembered for a joiner, and it never counts toward backoff.dashboard-errorbelongs to no panel: it renders as a banner above the grid, marks every panel stale, and clears on the next completedtick.- A staleness watchdog marks panels
staleif notickarrives within roughly two cycles (the fastest panel’s cadence,cycleMs), and on anEventSourcetransport error — which auto-reconnects and resumes. - Panels are cleared only when a stream starts over (first load, or a new time window). A resumed stream keeps them.
- Each panel records when its data arrived; the status badge reports it, so panels that go stale independently can be told apart.
- Truncation is said, never silent (#486). A frame carries
truncatedwhen the server cut its result (the row cap, a PromQL step the point cap widened, or a Loki log query that returned its wholelimit), and the window adds its own when it drops rows. The panel header shows a badge (“Newest 1,000 of 1,440 rows”) whose popover names the limit.MAX_WINDOW_POINTSandPROMQL_MAX_POINTSare one point budget: keep them equal, so a PromQL series fits its panel whole. A Chat panel is held to the same budget (fitToWindow), so a query reads the same in both. - One commit per tick. A cycle’s frames are queued and applied together
when its
tickarrives (or on the next animation frame, for a frame that comes alone), throughapplyPollerEventsinsrc/lib/panel-state.ts. A panel no frame names keeps its state object, andPanelViewis memoized, so a tick that changes one panel renders that panel and no other. Chart options are memoized on what they read, and every date and number goes through a cachedIntlformatter rather than building one per label.
PanelView looks panel.viz up in the panel registry and draws what it
finds:
stat→ the last numeric value, run throughformatValueperpanel.format.table→ an HTML table of the windowed rows.text→ the panel’s Markdown, rendered into React elements bysrc/lib/markdown.ts(never as an HTML string). It runs no query.- every other kind → the kind’s option builder (
src/components/charts/options.ts) makes an ECharts option, drawn byEChart.
The connection indicator
Section titled “The connection indicator”EventSource retries forever and says nothing about it, so a dead stream and a
slow one look the same. LiveDashboard therefore tracks the connection
separately from panel data, through the reducer in src/lib/connection.ts:
connecting → live → reconnecting → failed, plus paused. The
header indicator shows that state and names the attempt while reconnecting.
Once the automatic retries have failed MANUAL_RECONNECT_AFTER_ATTEMPTS
times, or the browser gives up outright (readyState === CLOSED, typically an
expired session), a manual Reconnect appears; it replaces the
EventSource, which is the only way to shortcut the browser’s own retry
schedule. The whole indicator is one polite aria-live region carrying a full
sentence, so a state change is announced rather than a stream of counting
seconds.
The freshness clock counts from the last data, not the last connection: a
reopened socket does not reset it, because it answers “how old is this
number”, not “how old is this connection”. Pause closes the EventSource and
resuming reattaches to the shared poller; while paused the transient live
and loading badges are suppressed, since they no longer reflect reality, but
error and tombstone states remain meaningful.
The window the browser asks for
Section titled “The window the browser asks for”Everything the time picker emits is a pair of IR TimeExpr strings. The
client is never the authority on the window that was queried: the expressions
go out on the stream URL, the route re-parses them against TimeRange, and
the poller calls resolveTimeRange itself on every tick (invariant 8). A
window that TimeRange refuses is a 400 on the stream and falls back to
the dashboard’s own range on the page.
An absolute window is frozen by definition — the poller keeps ticking, but it re-queries the same seconds — so the picker badges it Fixed range, and the staleness watchdog is switched off for it. “No new data” is the correct state there, not a stale one.
The chosen window is written into the URL with history.replaceState, so a
range is a link someone can send. It is replaceState and not a Next
navigation because re-rendering the server page would remount the viewer and
tear down the EventSource on every change. The dashboard’s own range is left
out of the query string, so the default link stays clean.
Brushing reads the timestamps of the first and last rows the selection covered
(brushedRange); a selection it cannot read leaves the window alone rather
than guessing at one. Only kinds whose registry entry sets timeBrush (line,
area and bar) are brushable; on the rest the x-axis is not time laid out left
to right, or there is no axis at all. The shared crosshair forwards the hovered
category index between the instances rather than using echarts.connect,
which mirrors every connected action — a brush included — and would make one
drag produce a selection on every panel.
Fullscreen and exports
Section titled “Fullscreen and exports”Fullscreen is not a portal: the same card becomes fixed, so the panel’s
position in the React tree never changes and the ECharts instance is resized
by the ResizeObserver already in EChart rather than disposed and rebuilt
(#76). The same observer reports the chart’s size, stepped by 20px and once a
resize has settled, and the kind’s builder reads it as ChartContext.size to
fit its ticks, labels and legend (#643, src/components/charts/size.ts); the
rebuilt option is merged like a data update, so a builder that varies a field
by size sets it at every size (test/chart-theme.test.ts).
Export CSV serializes the window the panel is holding — RFC 4180 quoting,
CRLF, a UTF-8 BOM so Excel reads it as UTF-8. A text cell that starts with
=, +, -, @ or a tab is prefixed with an apostrophe, because a
spreadsheet would otherwise run it as a formula and the values come from a
database Holotable does not own; numbers are never touched. Export PNG
comes out of the ECharts instance with the theme’s surface color painted behind
it, since the canvas itself is transparent.
Neither export asks the server for anything, so an export cannot contain a row the panel was not already showing and cannot become a second, unguarded way to run a query. Exporting the full result set server-side would be a different feature.
Panel kinds
Section titled “Panel kinds”The kinds a panel can be are registered in one list,
PANEL_KINDS in src/lib/panels/registry.ts (#61). Each kind is a small
module under src/lib/panels/kinds/ that says, in plain data:
| Field | Used by |
|---|---|
kind |
panel.viz. VizType in src/lib/ir.ts is built from the registered names, so an unregistered one fails validation with the list of valid kinds. |
summary |
The Visualization types reference, generated from it. |
promptHint |
The generation prompt, whose list of kinds is built from the hints. |
promqlHint, logqlHint |
The hint in its place when the source is Prometheus or Loki. |
canvas |
Drawn by ECharts: PNG export. |
image |
Draws its own image rather than an ECharts chart (a custom visual): PNG export. |
timeBrush |
Whether a drag across the chart selects a time range. |
skeleton |
The shape the panel shows while it loads. |
query |
"required", or "none" for a kind that runs nothing (text). The IR holds the panel to it, and code that executes or lists queries filters through hasQuery. |
requiresTimeField |
The IR refuses the panel without query.timeField (state timeline). |
options |
The kind’s own options schema, which panel.options is validated against. See Panel options. |
optionGroups |
The shared option groups the editor’s Display section draws fields for. |
rowLimit |
The rows the query is asked for, from the kind’s own options (a table’s or a log’s limit). |
datumColumns |
Columns a click carries beyond the result’s own (a graph node’s node and parent), which the link editor offers. |
starterOptions |
What a panel switched to this kind in the editor starts with, when {} would not do. |
check |
A server-side check of the options beyond their schema, run wherever a dashboard is saved. A custom visual’s spec must compile. |
How a kind is drawn is the browser half, PANEL_RENDERERS in
src/components/panels/registry.ts: { type: "chart", option, shape?, problem?, notice?, table? }, an ECharts option builder; { type: "html", Body }, a component; or
{ type: "view", Body }, a component that draws its own image and is handed
the PNG export handle a chart is (a custom visual). An option
builder is given the rows and a context: the viewer’s time display, and the
window the server resolved for the rows (sent with every tick, and returned
by /api/query), so a chart that runs to “now” ends where the server’s window
does. shape names a layout of the kind, such as a gauge’s dial or bars.
PanelView keys the chart by it, so switching layouts remounts the chart.
Data updates never change it, so they still merge (invariant 11). problem
says why a result cannot be drawn, naming what is wrong, and the panel shows
it in the shared error state instead of the chart; notice says the rows were
drawn other than the spec asked, and the panel shows it as a badge beside its
title, as it shows a truncation (a graph’s tree drawn as a directed graph
because its rows are not a tree, #624, a Sankey’s rows left out for
having no volume, #625, or a graph’s blocks drawn as markers where the panel
has no room for them, #649; a Sankey whose flows cycle is a problem); table is the kind’s own
screen-reader table where its marks are not one per row (a graph’s edges). It is kept
apart because src/lib/ir.ts imports the registry, and the server and the
prompt must not pull React in with it. The renderer map is typed as
Record<VizType, PanelRenderer>, so a kind registered without a renderer does
not compile.
Adding a kind is therefore:
- a module under
src/lib/panels/kinds/and one line inPANEL_KINDS; - its renderer (an option builder, or a component under
src/components/panels/) and one line inPANEL_RENDERERS. - if its option builder uses an ECharts series or component no other kind
does, one line in
src/components/charts/echarts.ts(the graph’sTreeChart, #623, its directed graph’sGraphChartand insideDataZoom, #624, and the Sankey’sSankeyChart, #625, are; the graph’s force layout, #625, isGraphChartagain). That module loadsecharts/corewith only what the panels draw (#488), and it is the only one that imports ECharts at runtime (test/echarts-runtime.test.ts). A missing registration draws nothing in production and warns only in development.
The chart itself loads with the first panel that draws one (#497).
PanelView reaches AccessibleChart, and through it ECharts, with
React.lazy, and shows the panel’s skeleton until the chunk arrives. A
dashboard of stats, tables and text, or an embed of one, never fetches the
library. test/client-bundle.test.ts holds the dashboard and embed routes to
that.
Registration is an import. Nothing is loaded at runtime, so there is no way for a request to add a kind.
A new kind is an additive change to the IR: every spec saved before it still
parses, so it needs no specVersion bump (see
invariant 3). Renaming or removing a kind does
need one, with an upgrader that rewrites the old name.
EChart is the invariant that keeps charts smooth: the ECharts instance is
created once, and every update is setOption(option, { notMerge: false }).
The chart merges incoming data into the existing series — it is never torn
down and recreated on a data tick, so streaming feels continuous.
A rendering detail worth knowing
Section titled “A rendering detail worth knowing”Design tokens are authored in OKLCH, but ECharts cannot parse oklch(),
and a canvas cannot read a CSS variable at all. Every color a
chart draws is a token read off <html>’s computed style by readChartTheme
(src/lib/color/chart-theme.ts) through the useChartTheme() hook
(src/components/chart-theme.tsx), converted from OKLCH (src/lib/color/oklch.ts)
and handed to every option builder as ctx.theme: the series --chart-1 to
--chart-8, the ramps, and the chrome around them, --chart-text,
--chart-axis, --chart-grid, --chart-track and --chart-faint. A change
of theme or color scheme re-reads them and the chart merges the new colors in,
so a chart’s text is the same gray as the text beside it in either color
scheme and no chart is recreated. test/chart-theme.test.ts holds every chart
kind to this: none may draw a color that suits only one color scheme. The font, type
scale, corners and line width arrive the same way, through the one chart
style every kind spreads (src/components/charts/style.ts; see
Theming).
One layout is Holotable’s own rather than ECharts’: the graph kind’s directed
graph (layout: "dag", #624). ECharts’ graph series lays nodes out only by
force or in a circle, so graphLayout (src/lib/graph/layout.ts) places
them in layers, pure and deterministic, and the builder in
src/components/charts/graph.ts hands ECharts the positions. Why that is not
dagre, and what was measured to decide it, is
Graph layout.
What the viewer does with the stream once it arrives — the time picker, pausing, fullscreen, exports, the command palette and the dashboard chat — is Viewing a dashboard.