Skip to content

fix(session-ui): drive markdown readiness, steer grow-in and tool status titles through state machines - #61977

Merged
Hona merged 6 commits into
devfrom
sessionui-lows-one
Nov 5, 2026
Merged

Hona merged 6 commits into
devfrom
sessionui-lows-one

Conversation

@Hona

@Hona Hona commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Three Session UI lifecycles that run while a reply streams now each live in one explicit state machine: Markdown readiness, steer grow-in, and the tool status title animation.

Bugs fixed

Machine Trigger Before After
Markdown readiness Any unrelated rerun of the render effect (language, code block plugins, session titles) data-markdown-ready removed and re-added: 2 mutations per <Markdown> on the timeline's MutationObserver Attribute changes only when readiness changes
Markdown readiness Stream ends (streaming → false) Last live render reported ready, then the settled render removed it again while it checked paths Stays not-ready until the settled render and its path checks finish
Markdown readiness localFileExists never settles Never ready; cold reveal waits for its 3 s emergency timeout Ready after INLINE_PATH_CHECK_TIMEOUT_MS (2 s); the path stays plain code
Markdown readiness streaming flips before the html fetcher runs Fetcher read a mutable let streamed, not the mode of its own source Each source carries its mode
Steer grow-in Scroll up in a busy session; history pages in above All prepended user messages grew in (0px → natural) History never grows in
Steer grow-in Steer sent while its row is offscreen, then any other row update Next memo pass dropped the arrival; the steer never grew in Kept until its row renders
Steer grow-in Idle prompt, or a steer left unrendered when the turn ended, scrolled to during a later turn Old prompt grew in on scroll Arrivals clear when the session goes idle
Tool status title active flips in a hidden tab (display: none) Measured "0px", pinned width: 0px + overflow: hidden for 600 ms: the title was invisible if the tab showed in that window Hidden title switches at once, no inline width
Tool status title The hidden tail changes (doneText while active) Mounted both texts and pinned the width for 600 ms No-op
Tool status title Title switches between suffix and swap Width of the old container pinned on the new one for a frame Snaps

State

// markdown-phase-machine.ts
type MarkdownMode = "static" | "streaming" | "settled"
type MarkdownPhaseState =
  | { status: "pending"; mode: MarkdownMode; attempts: number }
  | { status: "checking"; mode: "static" | "settled"; attempt: number }
  | { status: "ready"; mode: MarkdownMode; attempts: number }
  | { status: "disposed" }

// steer-arrival-machine.ts
type SteerArrivalState =
  | { status: "tracking"; sessionID: string; seen: ReadonlySet<string>; arriving: ReadonlySet<string> }
  | { status: "disposed" }

// tool-status-title-machine.ts
type ToolStatusTitleState =
  | { status: "idle"; active; mode; text; attempts: number }
  | { status: "measuring"; active; mode; text; attempt: number; from: string; crossfade: boolean }
  | { status: "animating"; active; mode; text; attempt: number; width: string }
  | { status: "disposed" }
stateDiagram-v2
  direction LR
  state "Markdown" as md {
    pending --> ready: rendered, no checks (or streaming)
    pending --> checking: rendered, checks pending
    checking --> ready: checks.settled / checks.timed-out (same attempt)
    checking --> checking: new blocks → attempt + 1
    ready --> pending: render stale / stream ends
    checking --> pending: render stale / stream starts
  }
  state "Tool status title" as tool {
    idle --> measuring: sync with a width
    idle --> idle: hidden, reduced motion, mode switch
    measuring --> animating: measured (same attempt)
    measuring --> idle: measured 0px or same width without crossfade
    animating --> idle: settled (same attempt)
    measuring --> measuring: reversal → attempt + 1
  }
Loading

Steer arrivals: a user message is a steer only when it lands below the last row already seen while the session works. Rows are keyed by message ID (user, shell, assistant), so a prepended page lands above every seen row and a first page has no seen row at all.

// session-timeline-row.tsx
createComputed(syncArrivals) // sessionID, rows, busy → transitionSteerArrival
const grow = arriving(current().userMessageID) // shouldGrowUserMessage, then { type: "rendered" }

Deleted

  • markdown.tsx: let streamed, every direct dataset.markdownReady write, the Promise.all(pending) guard.
  • session-timeline-row.tsx: the mutable seen object, the arrivals memo that mutated it, and arrivals().delete(...) during render.
  • tool-status-title.tsx: createStore({ active, animating, width }) and the finish() / animate() pair.

Hot path

  • Every streamed delta dispatches dom.rendered; states without a started check are frozen singletons, so a steady stream allocates nothing in the machine. The driver reuses its event objects.
  • transition* returns the state; drivers derive timers, frames and the worker projection cleanup from the state change (the paced-text-machine pattern), so no effect arrays are allocated.
  • data-markdown-ready uses toggleAttribute(name, ready), which records no mutation when unchanged.
  • The steer machine returns the same state for row updates that add no message; the driver skips a sync whose sessionID, rows and busy did not change.

Benchmark

  • One short stream a reply run (packages/app/perf/stream.bench.ts) on an Apple M4, comparing base 5ea5c5e610 (this branch's merge base) with head; strobe's block is at the end. The Windows machine was locked.
  • It stopped after 17 pairs with no verdict: main-thread work (main.work) came out 16% lower, with an interval of −47% to +13%. The device was loaded (29% background CPU, 43–49% run-to-run variation), so the run shows no sign of a regression but proves no win.
  • This PR makes no speed claim; it fixes behavior only. The machines keep the streaming path allocation-free (frozen states, reused events).

Product calls

  • A hung inline path check gives up after 2 s (below the timeline's 3 s cold reveal timeout); the path stays plain code.
  • Under reduced motion the tool status title snaps instead of pinning widths for 600 ms (its CSS already disabled the transitions).
  • A same-width text change with the same active settles at once; an active flip at the same width still crossfades for 600 ms.
  • A steer needs the session to be working when its row arrives (same as dev, which checked status at render time).

Deviations from the design

  • Quiet compaction entrance (message-content.tsx) stays as is: already one 3-value union ("grace" | "now" | undefined) with one monotonic transition and no flags.
  • Transitions return the state only; effects come from the state change in the driver, not effect arrays.
  • Steer arrivals: no loading variant. "No seen row above" covers a first page, a leading notice, and rows replaced wholesale.
  • Markdown exposes markdownMode / markdownReady selectors instead of an allocating view() object, because the effect reads them on every delta.

Visual

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 72" width="240" height="72" fill="none">
  <style>
    .row{fill:currentColor;opacity:.16}
    .old{fill:currentColor;opacity:.16;animation:page 5s ease-out infinite}
    .steer{fill:currentColor;opacity:.5;transform-box:fill-box;transform-origin:50% 100%;animation:grow 5s ease-out infinite}
    .line{fill:currentColor;opacity:.22}
    .ready{fill:currentColor;opacity:.7;animation:ready 5s steps(1) infinite}
    .ring{stroke:currentColor;stroke-width:1;opacity:.5}
    .title{fill:currentColor;font:600 9px sans-serif}
    .active{opacity:0;animation:active 5s ease-out infinite}
    .done{animation:done 5s ease-out infinite}
    @keyframes page{0%,10%{transform:translateY(-6px);opacity:0}22%,100%{transform:none;opacity:.16}}
    @keyframes grow{0%,45%{transform:scaleY(0)}62%,100%{transform:scaleY(1)}}
    @keyframes ready{0%,70%{opacity:0}71%,100%{opacity:.7}}
    @keyframes active{0%,30%{opacity:1}42%,100%{opacity:0}}
    @keyframes done{0%,30%{opacity:0}42%,100%{opacity:1}}
    @media (prefers-reduced-motion:reduce){*{animation:none!important}}
  </style>
  <rect class="old" x="8" y="6" width="64" height="8"/>
  <rect class="old" x="20" y="17" width="88" height="8"/>
  <rect class="row" x="8" y="30" width="72" height="8"/>
  <rect class="row" x="20" y="41" width="80" height="8"/>
  <rect class="steer" x="40" y="54" width="68" height="12"/>
  <path d="M120 6v60" stroke="currentColor" opacity=".15"/>
  <rect class="line" x="132" y="8" width="84" height="5"/>
  <rect class="line" x="132" y="18" width="64" height="5"/>
  <circle class="ring" cx="226" cy="10.5" r="3.5"/>
  <circle class="ready" cx="226" cy="10.5" r="2.5"/>
  <text class="title active" x="132" y="54">Exploring</text>
  <text class="title done" x="132" y="54">Explored</text>
  <rect x="132" y="58" width="44" height="1" fill="currentColor" opacity=".3"/>
</svg>

strobe ┬╖ exp_0fc370 ┬╖ packages/app/perf/stream.bench.ts ┬╖ generated

No answer yet. Main-thread work: no clear change in 17 pairs.

No answer yet

Stream a reply: Main-thread work per 4.2 s run: no answer, stopped after 17 pairs; unsteady case: its work grew each run.

Stopped early: the results cover only the pairs that finished.

Details ┬╖ metrics, pairs, profiles, method

Metrics

Metric Before This PR Change Likely range Verdict
Main-thread work per run main 1.66 s 925 ms −16% −47% to +13% stopped
Frame gap, p95 33.3 ms 33.3 ms 0.0% −29% to +15% inconclusive
Dropped frames 1.66% 0% −1.08 pp −13.1 pp to 0 pp inconclusive
JavaScript time per run 400 ms 211 ms −18% −43% to +1.4% inconclusive
Layout time per run 106 ms 71.3 ms −11% −29% to +18% inconclusive
Style time per run 296 ms 147 ms −13% −45% to +5.6% inconclusive
Main-thread busy time 39.8% 21.8% −17% −44% to +3.0% inconclusive
Total CPU use 54.5% 56.3% +7.8% −18% to +39% inconclusive

Likely range: 98.5% confidence for the main metric, 95.5% for the others. Change: the median of the pairs' own changes.

Pairs

Pair Main-thread work per run, before → this PR Change Longest frame gap
1 AB 2.18 s → 774 ms −64% 1000 → 817 ms
2 BA 520 ms → 1.47 s +184% 383 → 167 ms
3 AB 2.64 s → 867 ms −67% 1.48 s → 33.3 ms
4 BA 1.35 s → 928 ms −31% 800 → 33.3 ms
5 AB 2.13 → 1.79 s −16% 617 → 550 ms
6 BA 2.61 → 2.20 s −16% 817 → 167 ms
7 AB 384 → 848 ms +121% 33.3 → 33.3 ms
8 BA 1.66 s → 919 ms −44% 317 → 66.7 ms
9 AB 1.83 → 1.61 s −12% 117 → 50.0 ms
10 BA 1.65 → 1.85 s +13% 150 ms → 6.88 s
11 AB 2.94 → 1.84 s −37% 1000 → 50.0 ms
12 BA 1.69 → 1.60 s −5.0% 33.3 → 33.3 ms
13 AB 1.72 s → 465 ms −73% 66.7 → 33.3 ms
14 BA 744 → 567 ms −24% 33.3 → 33.3 ms
15 AB 882 → 923 ms +4.7% 33.3 → 33.3 ms
16 BA 945 → 925 ms −2.0% 33.3 → 33.3 ms
17 AB 859 → 888 ms +3.4% 33.3 → 33.3 ms

Each pair launched both builds fresh, in alternating order (AB or BA). Change: the main metric.

Frame pacing

60 Hz display Before This PR
On time 90.08% 91.02%
One frame late 7.98% 8.25%
Two or more late 1.94% 0.73%
Frame gap, p50 16.7 ms 16.7 ms
Frame gap, p95 33.3 ms 33.3 ms
Frame gap, p99 66.7 ms 33.3 ms
Longest frame gap 1.48 s 6.88 s

Shares of all 18,664 and 20,148 gaps between frames; a frame is late from 1.5 frame times. Gap percentiles: each launch's own, median across launches.

How it was measured

  • Before: 5ea5c5e610, fix(gui-plugins): drive the Pierre file tree through one state machine
  • This PR: origin/sessionui-lows-one@ed28f79726, test(session-ui): locate the done title by its slot
  • Machine: macOS 27.0.1 (26A434), Apple M4, 4P+6E, ANGLE (Apple, ANGLE Metal Renderer: Apple M4, Version 27.0.1 (Build 26A434)), automatic (Low Power Mode off) power plan, Edg 156.0.4314.58, 60 Hz display, not pinned (no V-Cache CCD)
  • On screen: 'Timeline collapse state regression ┬╖ OpenCode ┬╖ Timeline collapse state regression ┬╖ Session renderer review 119'
  • Method: fresh launches in alternating pairs; Wilcoxon signed-rank test and HodgesΓÇôLehmann interval; main metric checked at 8, 12, 18, 26, 40 pairs, others Holm-corrected; 36.1┬ámin in all
  • Busy machine: 29% of all CPUs were busy before the run; close heavy apps for tighter intervals
  • Stale calibration: no calibration on this device yet: the Throttled check has no baseline (run strobe up)
  • Power plan: automatic (Low Power Mode off) (kept: macOS has no power plan to switch; Low Power Mode off is its fastest)
  • High variance: before: main-thread work per run varies 49% between launches (CV)
  • High variance: this PR: main-thread work per run varies 43% between launches (CV)
  • Unsteady warmup: 4 block(s) never did the same work twice in 10 warmup runs: the case's state grows across runs; add a reset
  • Recorded with strobe 0.7.3, formatted with strobe 0.7.3+0f6b4d52c2

Also measured, not tested

Metric Before This PR Change Likely range
Frame latency, p50 40.7 ms 40.6 ms −0.4% −23% to 0.0%
Frame latency, p95 41.6 ms 41.4 ms −16% −38% to 0.0%
Frame latency, p99 57.7 ms 57.3 ms — skipped too few frames, 873 of 1000
Layouts per run 262 313 +30 0 to +79.5
Style recalculations per run 512 565 +35 −0.5 to +127.5
Run time 4.21 s 4.21 s +0.1% −0.2% to +0.2%
Renderer CPU use 35.0% 34.3% +0.6% medians −2.1% −17% to +37%
GPU process CPU use 17.4% 19.0% +1.0% −22% to +52%
Browser process CPU use 1.95% 2.01% +0.9% −20% to +113%
GPU use 20.1% 21.5% +9.0% −3.1% to +42%
App memory 1287 MB 1278 MB −0.9% −4.9% to +6.7%
JavaScript heap 63.0 MB 63.6 MB −4.8% medians +0.9% −24% to +23%

Unchanged: DOM nodes (1176), frame gap, p50 (16.7 ms). Uneven pairs: renderer CPU use read 16.6–60.6% before and 19.8–60.5% with this PR and JavaScript heap read 32.5–117 MB before and 32.6–106 MB with this PR; the medians' change (beside it) and the pairs' own point different ways, as when a few launches read far from the rest, so read neither as the change.

Rerun ┬╖ command and recordings
strobe bench packages/app/perf/stream.bench.ts \
  --base 5ea5c5e610 \
  --head origin/sessionui-lows-one \
  --filter "stream a reply"
  • Full report: strobe report experiment exp_0fc370 --open
  • Kept launches: rec_8eb2ef (before, pair 1), rec_b329a1 (this PR, pair 1)

strobe ┬╖ exp_0fc370 ┬╖ end of generated report

Copilot AI balanced review requested due to automatic review settings November 5, 2026 06:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three lifecycles look right to me, and the Markdown readiness and hidden-tab title fixes check out. I ran the new component specs on the base, where all 4 fail and show the bugs described. With this PR, the three Markdown readiness specs pass. Session-ui unit tests (494), tsc -b and 100 existing session-ui component tests (markdown, timeline, lifecycle, tool groups) also pass. I didn't run steer grow-in in a browser; I checked it through its unit tests and the existing timeline component tests.

The public API is unchanged. data-markdown-ready keeps its meaning; only when it toggles changes.

One blocker: the new tool-status-title.spec.ts fails every time on this branch (see the inline comment). CI runs test:components, so it will go red.

These are browser-only animation and timing changes, so a short before/after video of a steer growing in and of a history page loading above would help reviewers.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failing test is fixed: the done title is now found by its slot. With this branch, the tool status title and Markdown readiness component specs pass on repeated runs (3 runs each). On the base, the updated spec still catches the 0px width bug. Nothing new to raise. The public API is unchanged.

@Hona
Hona merged commit 883249d into dev Nov 5, 2026
24 checks passed
@Hona
Hona deleted the sessionui-lows-one branch November 5, 2026 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants