Repository navigation
perf: read channel history ahead of the reader and slide past the budget - #4194
kalvinnchau wants to merge 25 commits into
Conversation
9a0083d to
ac79fef
Compare
wesbillman
left a comment
There was a problem hiding this comment.
🤖 Star Lord recommends changes on 41244e8 for history continuity, paging recovery and window budgets. These findings come from source review. Required CI was green in the snapshot.
jedwards27
left a comment
There was a problem hiding this comment.
Channel-window reads in Desktop/browser now split rows (include_summaries, no include_aux) from 50-row auxiliary closure reads (include_aux, no summaries), with older pages up to 200 rows and client/HTTP concurrency of 8/10; verify Desktop history/reconnect and Mobile's existing combined 50-row query against the relay.
🤖 :bot: Jude’s code review agent — integrated review of 352f46e77e4eb0682fe2c29b7139f823f2effc74..41244e8c64595104ccafbed78c78e927a0200ab0 (clean checkout). Verdict: COMMENT; author fixes required before approval. Risk: high (history continuity, window budgets, and reconnect). The change aims to prefetch older rows, paint before aux, and slide the retained window; the failures below affect those very contracts. I independently traced the client store against the channel-window relay path and reconciled focused behavioral probes with the product/interaction review.
Blocking findings — author action required:
src/features/relay/store.ts:1063–1084: the second query pages by cursor/limit again rather than by the IDs of the rows just shown. A backdated/same-second row inserted between reads consumes a chunk slot; the displaced original row never gets its edit/reaction closure. A production-store scripted-relay probe kept the original text instead of applying its edit. Author action: bind aux closure to the original row IDs or a common snapshot; add an intervening-row displacement regression.store.ts:1088–1101,4615–4633: aux events merge without re-enforcing the 8 MiB retained-window budget. A focused probe exceeded that budget, then a live arrival evicted the row the reader had just reached;store.test.ts:363–376currently accepts an oversized closure. Author action: bound cumulative retention without losing effective edits/deletions or the reader anchor; cover multi-chunk aux plus live trim.store.ts:1103–1111,4172–4179: a quota retry timer can restart an older channel's aux at foreground priority after another channel opens. A focused probe observed the old-channel read after navigation. Author action: pause queued and late aux dispatch when the channel is inactive, resume on revisit, and use background admission where appropriate.store.ts:1571–1582: Jump to latest discards outstanding aux before the head replaces its rows. On head-read failure the detached segment remains but its edit/reaction work is gone; a focused failure/revisit probe found no resumed aux query. Author action: retain paused aux until replacement succeeds, and resume it on failure.store.ts:1413–1427: a refreshed head overlapping only a previously received live tail is mistaken for continuity with the older paged segment. A focused probe with old rows through time 20, a live row at 60 and a fresh head at 60…41 retained a missing 21…40 interval and marked it verified. Author action: prove overlap with fetched history, fill the gap, or replace the segment; add the split-tail regression.store.ts:4364–4417,4728–4743,5091–5111andsrc/features/messages/ChannelTimeline.tsx:2110–2129: a stream drop abortsloadNewer()but leavesloadingNewertrue; continuous resume does not clear it, and the UI refuses subsequent forward paging. Jump to latest is an escape, not recovery of the reader's place. Author action: clear the flag for the owning cancelled request and cover held forward read → disconnect → continuous resume → another forward page with anchor preserved.
At the row cap, store.ts:4615–4633 also aborts an in-flight older read on each new live row. A single cancellation is covered; sustained traffic faster than read latency may starve older paging. This is a source-established risk, not a reproduced sustained-load failure. Please stabilize the older-page boundary through trims and test repeated arrivals as part of the paging fix. Conversely, the 200×48-KiB response-too-large scenario is not established as a dead-end: the visible Retry calls the default 20-row read at the unchanged cursor. A refusal → smaller retry → stable-anchor journey still needs checking; do not treat the hypothetical as a separate blocker without that evidence.
Validation and verification ownership: At this exact head, pnpm typecheck, pnpm check, and pnpm build passed on an isolated Linux workstation; pnpm test was still running at publication (Node integration 340 passed, 6 skipped, 0 failed; Vitest/Rust/browser aggregate not established). Required hosted CI and Chromium/WebKit browser/flake shards reported success; green CI does not negate the focused failures. No native macOS Tauri, Flutter device, or concurrent real-relay acceptance was run in this review. Verification owner: reviewer/tooling, not an author-action item by itself: exercise a seeded >2,400-row Desktop channel with edits/deletions/reactions/summaries, wheel/keyboard paging, window slide, reconnect and Jump to latest in the exact native artifact; in parallel exercise Mobile's existing 50-row combined NIP-CW request and older cursor with the Desktop split-read pattern on the same relay, including reconnect and no gaps/duplicates. Check relay fleet load for the increased read concurrency. Residual risk: native/touch behavior, real-relay cross-client behavior, and the incomplete full local suite remain unverified.
Recommendation: request changes for the six concrete defects above; the desktop/mobile check is a separate reviewer/tooling-owned merge gate, not a code-defect inference.
41244e8 to
e2470b8
Compare
|
🤖 Re the review above: all six blockers and both noted risks are addressed at e2470b8. Each has its own commit and regression test; details are in the inline threads.
Validation at e2470b8: |
e2470b8 to
95e7bbd
Compare
wesbillman
left a comment
There was a problem hiding this comment.
🤖 Carl, an automated reviewer, commenting via Wes's GitHub account.
Changes requested. Reading ahead and sliding past the budget are good ideas, and CI is green. But the PR adds two paging bugs (reproduced below), and it starts a lot of unrequested relay work at foreground priority. Each problem is explained in its own inline thread.
Merge criteria
- Unrequested history and aux reads run at background priority. Size the relay load for the whole fleet, or start smaller (one idle page) and measure.
- The live-trim cursor skip and the stray live row after a revisit replacement are fixed, each covered by extending an existing store test.
- A failing aux chunk no longer stalls the aux queue, sliding prunes
traffic, and the Jump button stops counting rows read into a detached window as new messages.
Validation gaps (not blocking on their own)
- The ~101 px WebKit move on the page that reaches the channel start may be a product jump, not a flake. In that commit
hasMoreturns false and the.edgeswaps "Loading older…" for the intro above Virtua, while the slide takes the non-prepend hold path. Logging the.edgeheight in that spec would settle it. - No browser journey has aux land after its rows, so late edits and reactions reflowing under a reader are untested end to end.
older pages were a fixed 20 rows, read only once the reader neared the top, and a window at its row or byte budget stopped paging at a history wall. - loadOlder takes a row count of 20..200; head reads keep 20 - the timeline sizes each older page from decaying upward scroll speed and a smoothed, bounded request-to-render round trip, refilling the prefetch distance plus twice the distance scrolled during one round trip; the distance grows with that reach, capped at one page - a settled reader at the bottom reads ahead once the main thread is idle: a first page sized to the reach, then full pages up to twelve screens, at most five pages a visit. a revisit restored at the bottom or below a pending saved row reads ahead too, and a read-ahead page never returns the reader to that saved row. leaving the channel cancels it - an older page shows its rows and thread summaries first; its aux closure (edits, reactions, deletions) follows in the background in 50-row reads, one at a time per window, merged only for rows the window still holds and cancelled when the window closes. a part applies to the held rows past the budget too, without sliding; the next older page slides or limits the window. a part the relay refuses with a retry hint is read again when the hint expires - concurrent relay reads: reader 8, http 10, broker 10 - an older read cancelled under the window, as a stream drop cancels every relay read, ends its page so the window pages again - an older page past the budget slides the window down to it: the newest rows drop and the window detaches from the head. a detached timeline reads newer rows near its end, does not follow its end, and jump to latest reattaches the head - live traffic at the budget drops the oldest rows instead of stopping; an older read in flight below them is cancelled - budget trims keep a kept row's edits and reactions together with their deletions, through one shared rule - the reader hold picks up an unmounted row's new inset when it mounts and waits two frames after each height change, so a large page landing among the loaded rows keeps the reader in place - the hold releases only once every row from the viewport top to the held row is mounted at the size virtua lays it out with, on the scheduled check and at input end alike, bounded at sixteen checks - opening a channel pauses the other channels' aux reads; their pages stay queued and are read again on revisit - a revisit past the head's freshness lease revalidates any attached window: a reader paged back from the head merges the newer head when it meets the rows, and takes the head past a gap - browser journeys settle the read ahead before their baseline; the fixture bounds every window read, as the relay does, and serves an aux closure read without holding it, and drops a read the app cancels; journeys whose premise is unloaded history hold the read ahead - perf harness: short-message corpus, delayed-short paging case and edgeWaitMs (time held at the top edge) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
a read-ahead page still in flight when the reader scrolls within reach of it is now the reader's read, so leaving the channel no longer cancels it and returning to the saved top finds it in flight, as with reads the reader starts. tests: serve the background aux read unheld in the channels page context fixture; count only rows served outside the visit's own pages as preloaded in the first-seen perf case; measure wheel progress in the production broker journey as distance from the bottom, which rows above measuring taller do not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
the ended-before-hold journeys judge the reader's move at scrollend net of virtua corrections. a correction dispatched after the input's scrollend, as a further older read can cause, left the move unjudged. judge it again on each correction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
one 1500 px wheel per pass lands more than 250 ms after the last when the pass waits on a read, so no pace is measured and every page stays at the base size. three 500 px notches per step keep samples inside the gap. linux webkit: 6/10 before, 12/12 after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
the two-filter head read awaited its parts inside the fault catch, so a held part the app cancelled was reported as an unexpected fixture fault. returning the promise keeps cancellation out of the catch, like the presence hold. unread.spec focus cancellation failed in both engines after rebasing onto the head-notices read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
the head that meets a paged window keeps the older rows; with notices read beside the head (#4179) it must take them from that read rather than issue a second notice read. fails if the path falls back to a separate notice read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
a runner too slow to land wheel notches inside the 250 ms pace sample gap gives the app no pace, so base-size pages are correct there. the test counts scrolls that land under 125 ms apart and skips the size assertion with a reason when fewer than five did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
the aux closure counted down by rows, so a row written into the page's range between the two reads took a place and left an original row without its edits and reactions. track the rows still uncovered and read on from the relay cursor, no older than the page's oldest row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
a page or retry timer landing after navigation started an aux read for a channel no longer shown; it now waits for the revisit, which ensure already fills. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
an aux merge could leave a window above maxHistoryBytes, so the next live reaction trimmed the oldest rows the reader had just paged to. past the budget the merge now slides down to the rows paged to, as an older page does; a closure that leaves no shown row applies as is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
at the cap every live row trimmed the oldest and aborted the older read, so fast traffic could stop older paging. live traffic no longer trims while an older page is in flight; the page slides the window within its budget when it lands. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
a 200-row page of large messages passes the reader's 8 mib response budget and stopped older paging. a response-size refusal now reads the same cursor again at the default page size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
a stream drop cancelled the newer read and left loadingNewer set, so every later scroll near the bottom skipped forward paging. the cancelled read now clears the flag when no other read owns the window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
a live row can sit in the window past a stretch the stream missed; a fresh head that met only that row kept the hole and marked the window verified. overlap now counts only rows read, not live traffic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
jump to latest dropped the queued aux work before the head landed, so a failed head read left the segment without its edits and reactions. aux work now waits while the head loads: it ends when the head replaces the rows and continues when the read fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
… floor a live row backdated below the loaded floor that survived a byte trim moved the next older read to it, skipping every unread row between. a trim now moves the cursor only when it drops rows paging read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
halves the unrequested older pages, and their aux closures, a settled visit reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
…laces the window past a gap the head replaced the paged rows but kept their floor and live traffic, so a live row below the head stayed on screen across the gap. the replacement now resets the floor and drops live rows below the head. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
a failed aux part went back to the front unchanged, so a closure past the response budget blocked the aux of every page behind it. a part too large for a response now reads again in halves; one that fails without a retry hint goes behind the other pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
a slide replaced the window's events but kept their live traffic, so dropped bodies outlived both budgets and showed again on return to the head. a committed slide now drops traffic outside the rows kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
rows a newer page read into a detached window, up to the page that reaches the head, raised jump to latest's new-message count for history the reader was scrolling back into. live rows never enter a detached window, so its updates now count no arrivals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
95e7bbd to
1b55e27
Compare
wesbillman
left a comment
There was a problem hiding this comment.
🤖 Carl, an automated reviewer, commenting via Wes's GitHub account.
Changes still requested. I re-reviewed the fix commits (9b53e31f3..1b55e27ab; the rebase itself is clean). The revisit stray row, the slide traffic leak and the detached new-message count are fixed, and the original cursor probe now passes. Three store issues remain or are new (inline below), and the relay admission thread is still open.
Merge criteria
- The aux merge no longer drops live rows held only in
traffic(a regression from the fix). - The trim guard compares against the composite cursor, not just the timestamp.
- A failing aux page goes behind the queue without ending the drain.
- Relay admission: speculative pages and aux go in the background lane, and the reader/HTTP/broker caps go back to 3/6/6 or come with reconnect evidence (see the existing thread at store.ts:1075).
- reconcile traffic only when an aux closure slides the window, so a live row held only in traffic survives an aux merge - decide which rows paging read by the (created_at, id) cursor in relay order, so a trim in the cursor's second does not skip unread rows - read every queued aux page once before stopping on one that failed - read-ahead browser helper waits for six screens, as the app does - reword the foreground comment: a read the reader entered survives a switch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
|
🤖 Owner decision on relay admission (merge criterion 4):
This PR does not include simultaneous-reconnect evidence. That would need relay-side measurement. |
- reader runs at most 7 reads at once, under the api lane's 10, so writes and other signed requests keep the three spare slots they had at 3/6 - companion layout journeys take their paging baseline after the reader's own wheel: a fast wheel reads ahead at its pace past six screens, and the invariant is that panel close and restoration do not page Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kalvin Chau <kalvin@block.xyz>
Problem
Older channel history loaded in fixed 20-row pages, read only once the reader neared the top. Scrolling back under real relay latency kept hitting the edge and waiting. A window at its row or byte budget stopped paging altogether.
Change
Tests
Unit
history-prefetch.test.ts: page sizing.rows-settled.test.ts: the settle predicate.Browser (
history-loading.spec.mjs, both engines)Fixture changes
Perf
scroll-paging.perf.mjsadds a short-message corpus, a delayed short-paging case andedgeWaitMs(time held at the top edge).Deferred
layout.spec.mjs"Alt+ArrowUp from a message link preserves native scroll ownership" fails on main too, in both engines; untouched here.history-loading.spec.mjs"split before the first loaded row" fails intermittently (2 of 20 runs on this branch); cause not confirmed.history-loading.spec.mjs"paging older slides the window to the channel start" moved the reader's row about 101 px twice in Linux WebKit CI, both times on the last page, which reaches the channel start; 0 of 6 in a local Linux WebKit container. Cause not confirmed.rows-settledunit mock has no start margin.🤖 Generated with Claude Code