Skip to content

Agent pane virtualization

The agent pane displays the conversation as an ordered list of DocumentNodes — one per assistant message, user message, tool call, agent-to-agent message, shell command, etc. Long sessions accumulate 500-2000+ nodes. Rendering all of them in the DOM at once made the layout tree heavy enough that tab-switching INTO a pane with an active agent stalled for 200-300ms.

The renderer (frontend/app/view/agent/virtualization/) keeps only the rows in view, plus 5 rows or 600 px of overscan on each side (whichever reaches further), mounted in the virtualized region, and always mounts the trailing 50 nodes (the streaming buffer). Every other row is virtualized. Rows just past the mounted window, up to 2400 px away and at most 80 at a time, are drawn as empty boxes of their own height (skeleton-band.ts), so a fast scroll past the window’s edge, while the page is too busy to mount rows, shows the shape of a row and not blank space.

Scroll region containment: outer scrollRef (.agent-document, purple border) contains two inner regions side by side — virtualized region (steel-blue, position:relative, rows absolute translateY) and streaming buffer (blue, always mounted last 50 rows, normal flex flow).

The virtualized region is custom, not a virtualization library. Its rows sit at absolute positions taken from the layout slice (frontend/app/store/agent-pane-layout/), a reducer that holds each row’s measured and estimated height and computes every position as a prefix sum of those heights, so neighbouring rows never overlap. Each mounted row reports its height to the slice through a ResizeObserver. The streaming buffer (the trailing 50 rows) is rendered with a normal <Index> so token deltas to active streaming nodes update in place — no recycling, no measurement lag. As rows age past the buffer, they transition into the virtualized region by which point their measurement has stabilized.

Why <Key by=id> and not <For> or <Index> for the streaming buffer: each token replaces a node’s object reference (immutable update preserves the id but produces a fresh value), and <For> reconciles by reference, which would unmount and remount the streaming row on every token. <Index> keys by position, so a row’s own state (its expanded state, its last status) would leak into whatever node later takes that position. <Key by={n => n.id}> ties each DOM slot to one node id for its lifetime and exposes the item as a Solid signal, so the same DocumentRow stays mounted while its props.node() re-reads.

Anchor and stick-to-bottom flags live in the Solid store (AgentViewState):

{
nodes: Accessor<readonly DocumentNode[]>,
nodeIndex: Accessor<ReadonlyMap<string, number>>, // O(1) id → index
stickToBottom: Accessor<boolean>,
headAnchor: Accessor<{ nodeId: string, offsetPx: number } | null>,
streamingNodeId: Accessor<string | null>,
// ... atomic mutations: engageStickToBottom, captureHeadAnchor, ...
}

The view projects this state into the DOM; it does not derive state from layout reads. The one reader of scrollTop is the follow controller (frontend/app/view/agent/scroll/), a small state machine for whether the pane follows the newest output. Only a user gesture can leave the following state: a wheel-up, a key press, a selection or a jump to a node. A clamp, a layout adjustment or a history page-in cannot. When history pagination prepends 200 older nodes, the view captures the topmost-visible node id as an anchor, fetches, then restores scroll to that node’s new offset. The arithmetic uses node ids, not pixel deltas — robust against ResizeObserver-driven height changes that haven’t settled yet.

CSS overflow-anchor: auto on the scroll container is the cheap belt to the JS suspenders: Chromium auto-pins a visible anchor element when content above it changes height (image loads, tool block expand). The JS layer handles the cases CSS can’t (programmatic scroll, remount).

3. Per-kind size estimators + intelligent perf probing

Section titled “3. Per-kind size estimators + intelligent perf probing”

Each DocumentNode kind declares its own size estimator in the renderer registry:

KindEstimator
agent_messagetext-line heuristic, capped at 320px; collapsed → 32px
user_messageunwrapped text-line heuristic; a collapsed startup message → 32px
toolexpanded → 200px (a content-first tool uses the preview cap), collapsed → 32px
markdowntext-line heuristic plus a fixed allowance per inline image; a collapsed thought → 32px
shellcollapsed → 32px, expanded → 200px
context_compacted48px
Other one-line rows (system_note, day_divider, history_link, resume_preflight, hidden_run and so on)a fixed height per kind

estimateNodeForState gives an estimate for each open state, because the slice keeps measurements per row and state. The open or closed answer comes from one rule, rowDisclosure in disclosure.ts, shared by the rows, the slice and the estimators. These replace the single estimateSize: () => 80 from the first retrofit attempt, which produced visible gaps because short messages were given 80px slots.

A dev-mode perf probe (agent-pane-perf-section.tsx, a section of the diagnostics panel, which dev builds toggle with Ctrl+Alt+Shift+F12, or Cmd+Alt+Shift+F12 on macOS) compares each row’s measured size against its kind’s estimate. When p50 measured size diverges from the estimate by more than 30%, the section flags the kind for recalibration. Per-kind p50/p95/max render times also surface here, plus layout-shift events scoped to the agent pane.

All probing is dev-only — import.meta.env.DEV is folded to a literal at build time, dead-code elimination drops the probe paths from production bundles.

Nothing visible in the happy path. The pane scrolls, paginates, jumps to bookmarks, and streams content as before — just with a bounded layout-tree memory cost regardless of session length.

You may notice:

  • Tab-switch into a populated agent pane is dramatically faster. The 200-300ms long-task storms during reflow are gone; the layout tree is constant-size.
  • Auto-scroll-to-bottom is more deterministic. Sticky behavior is data-driven (stickToBottom flag) instead of read-from-DOM heuristics.
  • Pagination is smoother. Anchor-based scroll preservation doesn’t drift on slow image/font loads.

frontend/app/view/agent/virtualization/:

FilePurpose
state.tsAgentViewState factory — single source of truth for scroll + streaming state
anchor.tsPure scroll-anchor math (capture, restore, near-top/near-bottom)
renderers.tsPer-kind size estimators and streaming-capability flags
disclosure.tsrowDisclosure: whether a row is open, shared by the rows, the slice and the estimators
expansion-source.tscurrentExpansion: maps that answer onto the layout slice’s Expansion
DocumentRow.tsxSingle row component used by both regions; caller controls positioning via style + ref
AgentDocumentVirtualList.tsxHybrid renderer wiring everything together
held-release.tsReleases rows held open after arriving live once they scroll off the top
live-arrival.tsDecides whether a row arrived live or was loaded from history
show-settle.tsDecides when the catch-up after the pane is shown again is done
skeleton-band.tsThe empty boxes drawn for rows just past the mounted window
keep-on-screen.tsKeeps the rows on screen in place when rows above them are removed or added
scroll-memo.tsRemembers where each pane was scrolled across a reload of its window
zoom-anchor-adapter.tsKeeps the text under the pointer in place when the pane zoom changes
verbosity.tsThe view presets and switches that hide routine rows (a view-layer filter)

Test files sit next to these. streaming-buffer.ts (partitionForVirtualization(nodes), which splits the document into virtualized and streaming halves) and perf-probe.ts (dev-mode timing and estimator-miss detection) are in frontend/app/agent-model/.

frontend/app/devtools/agent-pane-perf-section.tsx — the diagnostics-panel section that polls agentPerfStore.snapshot() at 1 Hz and renders the per-kind table.