Skip to content

fix(app): load older history before the reader reaches the top - #66033

Open
Hona wants to merge 3 commits into
devfrom
load-history-early
Open

Hona wants to merge 3 commits into
devfrom
load-history-early

Conversation

@Hona

@Hona Hona commented Nov 24, 2026 •

Copy link
Copy Markdown
Member
  • Before: an older page loaded only once a detached reader was within 200 px of the top. At scroll speed the reader got there first and waited. With a page that takes 150 to 300 ms, 4 to 9 of about 20 wheel bursts stopped at the top.
  • After: a scroll toward the top with less than a runway of loaded history above the view asks for the next page. The runway is 2,400 px, or two screens in a taller window. With pages of about 3,000 px, 0 to 2 bursts stop.
  • Bounded: paging follows the reader and does not run ahead by itself. One wheel step loads one page.
  • No flag: a fix.

How it works

export function historyRunway(viewportHeight: number) {
  return Math.max(HISTORY_RUNWAY_MIN, viewportHeight * HISTORY_RUNWAY_SCREENS) // 2,400 px, 2 screens
}

// Any scroll at the top, and one toward the top with less than the runway above the view.
export function scrollLoadsHistory(top: number, previousTop: number, viewportHeight: number) {
  return top < HISTORY_SCROLL_THRESHOLD || (top < previousTop && top < historyRunway(viewportHeight))
}
stateDiagram-v2
  direction LR
  idle --> loading: scroll at the top, or toward it inside the runway
  loading --> probeTop: page landed
  probeTop --> loading: within 200 px of the top (as before)
  probeTop --> idle
Loading
  • The history machine is the one on dev. Only the scroll that asks changed: onHistoryScroll in interaction.ts.
  • A page that lands moves the offset down the list. That scroll does not count: only a lower offset is the reader moving toward the top.

Why this rule

The rule with the distance set by a lab switch, against dev for 200 px. Real session (6,193 messages, pages of about 3,000 px), headless wheel, old timeline, two runs for each cell. A burst is 1,800 px in 450 ms. The count is bursts that sat at offset 0 while a page was loading. These runs are from the head before this one, which also sent the next page after a scroll made while one was loading (see "Removed").

Distance Page 150 ms Page 300 ms Short window (600 px), 150 ms Pages loaded for 28,900 px
200 px (dev) 4, 5, 6 of 21 to 23 7, 7, 6 of 19 to 20 4 of 17, 5 of 18 5 to 8
600 px 1 of 17, 4 of 19 5 of 17, 2 of 21 2 of 17, 11 of 19 6 to 9
1,200 px 0, 0 0, 0 0, 0 7 to 9
2,400 px 0, 0 0, 0 0, 0 7 to 10
3,600 px 0, 0 0, 0 0, 0 10 to 12
4,800 px 0, 0 0, 0 0, 0 11 to 14
  • Pixels, with a floor: a wheel is no slower in a short window, so the short window needs the same distance. 1,200 px still let one page of nine arrive late under bursts 100 ms apart, in one of two runs; 2,400 px did not (0 of 8, 0 of 12).
  • Two screens in a tall window: a page key moves most of a screen. In a 2,000 px window, PageUp every 300 ms reached the top on 9 to 12 of 11 to 16 pages with 200 px.
  • Not "page until the runway is full": a row that is not measured yet counts 60 px, and a run of tool calls is one row. In one live session a page of 20 messages added 0 px. That loop then loads until the session ends, after one wheel notch. The keeper covers it: with that loop, the fixture's second older page loads unasked.
  • The 11 of 19 is one run in which three pages took 0.9 to 4.8 s to arrive instead of 150 ms. The page request waited in the app's request queue (fix(app): send the older page a reader waits for ahead of background reads #66161).

Real sessions, this pull request against dev, interleaved

Frozen lab: the session's pages are replayed from a snapshot, and the server adds the delay to each older page. Counts are bursts that sat at offset 0 while a page was loading, of 17 to 25; or older pages that were still loading when the reader reached the top. This head: 3 or 4 runs for each cell. dev: 3 runs.

Scenario dev old This PR old dev new This PR new
Wheel bursts, page 150 ms 4, 5, 6 0, 0, 0, 0 5, 5, 9 0, 2, 0, 0
Wheel bursts, page 300 ms 7, 7, 6 1, 0, 0, 0 5, 4, 6 0, 0, 0, 0
Wheel bursts, no delay 2, 0, 2 0, 0, 0, 0 2, 3, 3 0, 0, 0, 0
Bursts 100 ms apart, 150 ms: pages late 5 of 6, 5 of 6 0 of 9, 0 of 9, 1 of 12, 0 of 10 4 of 6, 6 of 6, 6 of 7 0 of 9, 0 of 10, 0 of 9, 0 of 11
Autoscroll at 5,000 px/s, 150 ms: pages late 8 of 8, 9 of 9, 8 of 8 1 of 11, 0 of 16, 1 of 12, 1 of 11 5 of 6, 7 of 8, 8 of 8 0 of 12, 0 of 13, 0 of 11
PageUp every 300 ms, 2,000 px window, 300 ms: pages late 10 of 11, 11 of 11, 12 of 14 4 of 17, 6 of 13, 2 of 14 7 of 14, 6 of 12, 10 of 14 1 of 14, 0 of 17, 7 of 15
Session with short pages (1,100 px), bursts, 150 ms 10, 8, 10 2, 3, 6 10, 11, 9 0, 2, 5
  • The last two rows are the limit of one page of 20 messages for each scroll. A page key moves a screen in one step, and a page of 1,100 px is less than a wheel burst. The reader's next scroll asks for the next page only when the first has landed.
Check dev This PR
A page lands while the reader is 1,500 px from the top: the row in view moves 0 px, old and new timeline, 3 of 3 0 px, old and new timeline, 3 of 3
The reader reached the top first, then scrolled 300 px down before the page landed -8 px old, 20 px new -8 px old, 20 px new (unchanged; #66014 has that one)
Opening a session and waiting 10 s: older pages loaded (two sessions) 2 and 3 2 and 3, 12 of 12 opens
One wheel notch up with 5,000 px above the view 0 pages 0 pages, 12 of 12
40 wheel steps of 600 px, 1.65 s apart, pages landing at once: pages for each step 0 or 1; on the session with short pages, 2 for one step at the top 0 or 1 in every step, both sessions, both timelines

Removed

  • The page that followed a scroll made while one was loading (advanced, and the runway probe). The head before this one sent the next page as soon as one landed, when the reader had scrolled toward the top meanwhile and still had less than the runway above.
  • What it bought, measured on that head: PageUp in the tall window 0, 1 of 17, 0 (old) and 0, 2 of 20, 0 (new) pages late; the session with short pages 0, 0, 0 and 0, 2, 0 bursts stalled. The other rows were the same.
  • What it cost: with pages that land at once, one wheel step loaded two pages in 2 of 40 steps on the session with short pages.

Not changed

  • A reader who scrolls faster than pages arrive still reaches the top: pages are 20 messages and load one at a time.
  • An older page is a background read in the app's request queue (four requests at once). Rows that mount on the way up look up the paths they name, and the page stands behind those lookups. On a slow server the page was not sent for 4 to 6 s. That is fix(app): send the older page a reader waits for ahead of background reads #66161.
  • An earlier version of this text gave lower counts for dev (2 to 5 of 17). Those runs delayed pages in a route through the test driver, which stretched under load. Every number above is from the frozen lab.
  • The strobe run below compares the fix before its rebase (ebe9c2c77a) with dev at 5b66287cad. It was stopped after 8 pairs: nine benches shared the slot.

strobe · exp_e41378 · packages/app/perf/timeline.bench.ts · generated

No answer yet. Main-thread work: no clear change in 8 pairs; shift −10,000 −110,000 … +10,000 µs (warned).

No answer yet

Scroll history: Main-thread work per 2.7 s run: no answer, stopped after 8 pairs.
Different screens: the builds did not all show the same screen, so part of the difference may be the screen.

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

Details · metrics, pairs, profiles, method

Metrics

Metric 5b66287 HEAD@ebe9c2c77a Change Likely range Verdict
Main-thread work per run main 424,988 µs 417,105 µs −2%
−10,000 µs (warned)
−20% to +2%
−110,000 to +10,000 µs
stopped warned
Main-thread busy time 15.3% 15.2% −0.2% −19% to +2% not tested warned

Likely range: 98.4% confidence for the main metric (checked at 8, 12, 18, 26, 40 pairs, 95% over all of them), 96.1% for the others. Change: the pairs' typical change (Hodges–Lehmann: the median of the averages of every two pairs' changes).

Pairs

Pair Main-thread work per run, 5b66287 → HEAD@ebe9c2c77a Change Other apps' CPU
1 AB 422,656 → 415,819 µs −1.6% 357% → 165%
2 BA 602,508 → 405,249 µs −33% 1299% → 278%
3 AB 421,042 → 436,049 µs +3.6% 77% → 157%
4 BA 427,319 → 414,155 µs −3.1% 191% → 172%
5 AB 414,452 → 415,781 µs +0.3% 92% → 235%
6 BA 438,647 → 430,281 µs −1.9% 343% → 161%
7 AB 448,969 → 432,345 µs −3.7% 407% → 375%
8 BA 420,653 → 418,391 µs −0.5% 105% → 129%

Each pair launched both builds fresh, in alternating order (AB or BA). Change: the main metric. Other apps' CPU: other processes on the measured CPUs, % of one core, bold from 25%; 3 other processes ≥ 5%, busiest 651% of a core.

How it was measured

  • Base: 5b66287cad, chore(codemode): bump psychoscript to 0.3.0
  • Head: HEAD@ebe9c2c77a, fix(app): load older history before the reader reaches the top
  • Machine: Windows 11 26300 (26H2), Ryzen 9 9950X3D, NVIDIA GeForce RTX 5070 Ti, High performance power plan, Chrome 147.0.7727.15, headless browser (no display), pinned to CCD0 (96 MB L3, 16 CPUs), other processes kept off its 16 CPUs, window 1366×768
  • On screen: 'Timeline collapse state regression · OpenCode · Timeline collapse state regression · Session renderer review 119' → 'Timeline collapse state regression · OpenCode · Timeline collapse state regression · Session renderer review 117'
  • 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; 18.4 min in all
  • Background load: 63% of all CPUs were busy before the run; close heavy apps for tighter intervals
  • Stale calibration: calibrated 2026-10-31T03:33:19Z (more than 7 days ago; strobe up recalibrates)
  • EndedCpu: scroll history · web: processes ended inside 1 of 5 measured runs; the CPU they used there (155,578 µs a run, median of those) is counted from the…
  • OverheadBudget: scroll history · web · 5b66287 block: the reserved-CPU sweep used 8.9% of a core, over its 5% budget (SPEC §19)
  • OverheadBudget: scroll history · web · HEAD@ebe9c2c77a block: strobe (besides its budgeted parts) and the runner used 12.6% of a core in the runs (344,553 µs/run over 2,744,615…
  • OverheadBudget: scroll history · web · 5b66287 block: the sampler used 0.50% of a core, over its 0.5% budget (SPEC §19)
  • High variance: 5b66287: main-thread work per run varies 14% between launches (CV)
  • Outliers: main-thread work per run: 1 past the Tukey fences (1.5 × IQR): base pair 2 (602,508 µs); kept, the rank test is robust to them
  • Different screens: 5b66287: 7 of 8 blocks ended their runs on "Timeline collapse state regression · OpenCode · Timeline collapse state regression · Session renderer review…
  • Different screens: HEAD@ebe9c2c77a: 7 of 8 blocks ended their runs on "Timeline collapse state regression · OpenCode · Timeline collapse state regression · Session renderer review…
  • Other load: other processes used 25% of a core or more in 16 of 16 timed blocks (kept; see Pairs)
  • Recorded with strobe 0.44.1, formatted with strobe 0.44.1+53da950254

Also measured, not tested

Metric 5b66287 HEAD@ebe9c2c77a Change Likely range
JavaScript time per run 82,194 µs 80,609 µs −5%
0 µs (warned)
−25% to +8%
−30,000 to +10,000 µs
Layout time per run 16,261 µs 15,130 µs −7%
−1,000 µs (warned)
−24% to +5%
−6,000 to +1,000 µs
Style time per run 77,964 µs 73,258 µs −9%
−7,000 µs (warned)
−18% to +1%
−16,000 to +1,000 µs
Layouts per run 74.5 75 +0.2 −5 to +4
Style recalculations per run 516 517 +1 −26.5 to +13
Run time 2,735,575 µs 2,732,795 µs −0.1%
0 µs (warned)
−3% to +6%
−80,000 to +170,000 µs
GPU memory 128 MB 128 MB +0.1%
0 MB
−2% to +3%
−3 to +4 MB
Shared GPU memory 2.54 MB 2.54 MB −0.2%
0 MB
−11% to +12%
−0.3 to +0.3 MB
App memory 806 MB 803 MB −1%
−4 MB
−2% to +2%
−19 to +13 MB
JavaScript heap 29.9 MB 29.2 MB −3%
−0.8 MB
−7% to +1%
−2.2 to +0.4 MB
DOM nodes 971 971 0 −42.5 to +42.5
Total CPU use 53.5% 52.9% −0.1% −40% to +3%
CPU time per run 1,478,414 µs 1,446,819 µs −1%
0 µs (warned)
−39% to +2%
−1,200,000 to 0 µs
Rerun · command and recordings
strobe bench packages/app/perf/timeline.bench.ts \
  --base 5b66287cad \
  --head HEAD \
  --filter "scroll history" \
  --headless
  • Full report: strobe report experiment exp_e41378 --open
  • Kept launches: rec_f48a78 (5b66287, pair 1), rec_08b00a (HEAD@ebe9c2c77a, pair 1)

strobe · exp_e41378 · end of generated report

@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 change looks sound. A scroll toward the top inside the runway asks for the next older page. Paging goes on without another scroll only while the reader keeps moving up (advanced plus the runway probe), so one wheel notch loads at most one page. Only a lower offset counts as moving toward the top, so a page landing (which pushes the offset down) can't chain loads.

I ran timeline-history.spec.ts in headless Chromium. The new e2e test fails on the base and passes on this branch; the rest of the spec gives the same results on both (two tests fail the same way on both, from this environment). The history-machine unit tests pass and tsc -b is clean.

Public API: unchanged (all internal to packages/app).

No blocking concerns. One small edge: historyTop isn't reset when the session changes, so a detached reader restored onto a hash could get one extra page.

Related: #56285

@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 new commit only changes the stall figure in packages/app/AGENTS.md; there's no code change and nothing new to raise. My earlier review stands. Public API: unchanged.

@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 new commit fixes the stale historyTop point from my earlier review. Resetting it when a scroller is attached means the previous timeline's scroll position can't count as a scroll toward the top in the next one. Nothing new to raise; timeline unit tests pass. Public API: unchanged.

@Hona
Hona force-pushed the load-history-early branch from 9af02f2 to 5dd7a46 Compare November 24, 2026 09:30

@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.

This is a rebase onto a newer dev: the PR's own patch is unchanged and there is nothing new to raise. On top of #66034 the timeline unit tests and the timeline-history e2e spec still pass, including the new runway test (the one remaining e2e failure also fails on the base here). Public API: unchanged.

Hona added a commit that referenced this pull request Nov 24, 2026
The warm-up of "pages the timeline from the composer and the transcript ..."
pressed PageUp once and waited for scrollTop to drop. With history that loads
before the reader reaches the top (#66033), that PageUp lands inside the
distance in which the next older page is requested. The page lands above the
view and raises scrollTop, so the offset goes 3,136 -> 2,386 -> 4,387 and the
wait never ends, although the view paged as it should.

The warm-up now uses the test's own `paged` helper and waits until the first
row below the header has moved down the screen, as the measured steps after it
already do.
Hona added a commit that referenced this pull request Nov 24, 2026
The warm-up of "pages the timeline from the composer and the transcript ..."
pressed PageUp once and waited for scrollTop to drop. With history that loads
before the reader reaches the top (#66033), that PageUp lands inside the
distance in which the next older page is requested. The page lands above the
view and raises scrollTop, so the offset goes 3,136 -> 2,386 -> 4,387 and the
wait never ends, although the view paged as it should.

The warm-up now uses the test's own `paged` helper and waits until the first
row below the header has moved down the screen, as the measured steps after it
already do.

(cherry picked from commit 8b159f8)
Hona added a commit that referenced this pull request Nov 24, 2026
The warm-up of "pages the timeline from the composer and the transcript ..."
pressed PageUp once and waited for scrollTop to drop. With history that loads
before the reader reaches the top (#66033), that PageUp lands inside the
distance in which the next older page is requested. The page lands above the
view and raises scrollTop, so the offset goes 3,136 -> 2,386 -> 4,387 and the
wait never ends, although the view paged as it should.

The warm-up now uses the test's own `paged` helper and waits until the first
row below the header has moved down the screen, as the measured steps after it
already do.

(cherry picked from commit 8b159f8)
Hona added a commit that referenced this pull request Nov 24, 2026
…-page-size

#66033 dropped the page that follows a scroll made while one was loading (�dvanced). This branch keeps it: here it is what tells a moving reader's page from a resting one's, and the larger pages depend on it.

This branch has not been deployed

No deployments
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.

1 participant