Repository navigation
Description
Problem
Three mechanisms own the scroll position of the same element (chatLayout.scrollContainerRef):
- Astryx
ChatLayout's built-inuseChatStreamScroll. useChatScroll->createArrivalBottomPin, which exists only to override (1). Its own doc comment states why: Astryx positions the first fill of a scroller instantly and springs every later growth, and that one-shot is spent on whichever session was open at boot, so every later switch is "later growth".useTurnVirtualizer, which observes every turn with aResizeObserver, captures and restores its own scroll anchor, and bumpsgeometryRevision.
Five call sites write scrollTop: chat-scroll-anchor.ts:75, arrival-bottom-pin.ts:120, use-chat-scroll.ts:74, use-chat-scroll.ts:115, plus the scrollIntoView at use-turn-virtualizer.ts:195.
Why this is hard to change today
A session switch starts all three. The pin sets scrollTop = scrollHeight; the virtualizer restores an anchor; use-chat-scroll gates turnWindow='ready' behind document.fonts.ready, then up to 50 x 100 ms of polling for .maka-markdown-pending, then a double requestAnimationFrame.
Timing is what keeps the three from colliding, so each new arrival condition tends to add another gate rather than remove one. That is the maintenance cost this issue is about.
Measurements, and what they do not yet show
On a dev build, five consecutive session switches produced 9 long tasks (67, 51, 78, 65, 65, 109, 102, 51, 129 ms), 717 ms total, and a CLS of 0.55.
These numbers were observed on the same path but are not yet attributed. Three authorities fighting over one scroller is a plausible source of layout shift, but no discriminating measurement has been run, so this issue does not claim them as the cause. Root-causing that jank is separate work; this issue stands on the duplicated authority alone.
Decision needed
Who owns transcript scroll position.
- Astryx owns it - delete
arrival-bottom-pin.ts(237 lines) and the positioning half ofuse-chat-scroll. Cost:ChatLayoutmust reset its first-fill one-shot perconversationKey, which needs either an upstream change or a remount by key; otherwise switches animate instead of arriving. - Maka owns it - disable Astryx's path explicitly and merge
useChatScrollwithuseTurnVirtualizer. The virtualizer already holds the full geometry, so bottom-pinning becomes a window state rather than a separate mechanism. - Status quo - keep three authorities separated by timing.
No current architecture document assigns this ownership.
Non-goals
No visual or copy change. Prompt-anchor-rail navigation and earlier-history loading keep their current behavior.
Activity
Astro-Han commentedon Aug 28, 2026
Root cause found, and it narrows this issue
Follow-up measurement on the transcript scroller. All numbers are within-instance A/B (alternating configs in one running app, 3 repetitions each). Cross-instance comparison turned out to be unusable: the same build measures CLS 0.000 and 0.511 for the same session across restarts, while within one instance σ ≈ 0.02.
What causes the shift
A single
requestIdleCallback(prefetch, { timeout: 250 })atuse-chat-scroll.ts:157. It is the only idle callback registered during a session switch. It fires ~150 ms after the switch and callsrequestEarlier(), which loads earlier history and inserts turns above the current scroll position.83% of measured CLS. Dose-response holds: session #0's prefetch pulls in a turn carrying 51 tool-activity blocks (CLS 0.854); session #12's pulls in one carrying a single block (CLS 0.238, and blocking barely moves it).
What was ruled out, each by controlled test
prefers-reduced-motion: reduceremoved 89% of its layout reads; CLS unchangedDEFAULT_TURN_ESTIMATED_HEIGHT = 280being wrongINITIAL_TURN_WINDOW_SIZE = 2window.maka.*calls during a switchWhy this narrows rather than widens the issue
The browser already does the job the hand-rolled anchor does. Measured on the live scroller:
Native scroll anchoring is not merely available — it is active and working on this element.
chat-scroll-anchor.ts(129 lines) reimplements it, anduse-chat-scroll.ts:74adds a fallback that applies the full height delta on top of the browser's already-applied compensation wheneverrestoreChatScrollAnchorfails to relocate its article:Observed consistent with double compensation:
scrollHeight1491 → 5349 (+3858) in the same frame asscrollTop582 → 4440 (+3858).The ownership question this issue opened is already answered in-tree
chat-surface-layout.tsxstates it:Against that, the current code holds a second implementation. Maka never calls
useChatStreamScroll; it takes onlyscrollContainerRefoffuseChatLayoutContext()while Astryx's own controller runs on that same element. Astryx already provides what the parallel implementation hand-rolls:arrival-bottom-pinpinned/released +data-arrival-pinisLocked/lock()/unlock()pin()on content resizescrollIfLocked()use-chat-scroll.ts:115scrollTop = scrollHeightscrollToBottom({ behavior: 'instant' })— documented for "opening a conversation, restoring a session"scrollIntoVieweffectscrollToMessage(el)chat-scroll-anchor.tsoverflow-anchorThe seam for reaching them already exists and is already used:
patches/@astryxdesign+core+0.5.0.patchwidensChatLayoutContextValuewithunlockAutoFollow: scroll.unlock, consumed atchat-view.tsx:675. Exposing the rest ofUseChatStreamScrollReturnthrough that same context is the established path, and is upstreamable.So the transcript carries exactly two scroll facts: "am I following the bottom" (Astryx owns it, and is already running) and "content was inserted above me, don't move" (the browser owns it, verified). Everything else in this area is a third implementation of the first or a redundant copy of the second.
Disappearance surface
chat-scroll-anchor.ts(129 lines) +chat-scroll-anchor.test.ts; call sites atuse-chat-scroll.ts:60,72anduse-turn-virtualizer.ts:153,187,239including thependingAnchorrefroot.scrollTop += root.scrollHeight - scrollHeightfallback — actively harmful, not merely redundantarrival-bottom-pin.ts(200 lines) once bottom-lock is read from Astryxdata-arrival-pin— written atuse-chat-scroll.ts:121, read nowhere in the repositoryCapability given up: the
scrollTop === 0case, where native anchoring does not engage. That is one known constant, not a mechanism to maintain.Still open
requestEarlierRef, an effect exporting a mutable callback so a different effect can invoke it.data-turn-window="ready"is produced by afonts.ready→ up to 50 × 100 ms.maka-markdown-pendingpoll → double-rAF chain whose only consumer isapps/desktop/e2e/prompt-rail.spec.ts. That chain is also where the prefetch is scheduled.Measurements were taken with temporary runtime switches on a local build; the working tree is unmodified.
Astro-Han commentedon Aug 28, 2026
Provenance: the parallel implementation was never a counter-decision
Correcting something in my previous comment. I leaned on the ownership statement in
chat-surface-layout.tsxas authority. A file comment is not authority on its own, so I traced why the parallel implementation exists.arrival-bottom-pin.tscomes from #2239 ("land a switched-to session at its latest turn instead of flying there"). Its reasoning is explicit and was correct at the time:I assumed the capability to fix that arrived in a later Astryx release. It did not. Unpacking
@astryxdesign/[email protected], the version in the tree at #2239, the controller surface is identical to today's 0.5.0:What was missing was reachability, not capability.
ChatLayoutContextValuein 0.2.0 exposed exactly two members:useChatStreamScrollruns insideChatLayout; Maka's transcript code lives inChatView, a descendant. The controller was not reachable from where the fix had to go, so the only available lever wasscrollToponscrollContainerRef— which is what the pin writes, from aResizeObserver. The pin is a hand-rolledlock()+scrollIfLocked()+unlock().That constraint was removed later, by Maka, for a different feature. #2923 patched
ChatLayoutContextValueto addunlockAutoFollow: scroll.unlock, consumed today atchat-view.tsx:675. Piping one controller method through the context is established and in production; the pin was never revisited against it.conversationKeyhas the same shape — absent from 0.2.0, added by Maka's patch, still carried inpatches/@astryxdesign+core+0.5.0.patchrather than upstream.#2239's supports today
ChatViewcontent-visibilityleft is unrelated code-block stylingarrivaldata-arrival-pinpublished "so a test can wait on the real boundary"requestIdleCallbackprefetch measured aboveThe last row closes a loop worth naming: the pin exists to absorb growth the prefetch produces, and that growth is the measured source of 83% of the layout shift. Each mechanism is part of the other's justification.
So the ownership statement is not stale and the parallel implementation is not a rejection of it. The workaround outlived its constraint by one PR.
The real cost of converging
Not "can Astryx do this" — it could in 0.2.0. It is whether Astryx's unlock heuristics are equivalent. #2239 spent six review rounds on exactly that: gestures must originate inside the transcript element, a horizontal wheel reports
deltaY === 0and is not the reader leaving, and the synthetic scroll Chromium fires for a resize must not be read as reader intent. Those semantics are currently held byarrival-bottom-pin.test.ts.Those cases should be retargeted at the Astryx-backed behavior rather than deleted with the pin. That is the one place where converging costs real work.
Astro-Han commentedon Aug 28, 2026
One more independent signal that the transcript scroll boundary remains timing-sensitive:
PR #4090 failed on exact head
89f8a9d89e839afb51c8710e54e03486e7efca45in the prompt-rail eviction journey:https://github.com/apache/maka/actions/runs/33195433169/job/98931236633
After the test set the transcript to the bottom, explicitly dispatched a scroll event, and waited two painted frames,
turn-prompt-rail-120was still absent for the full 10-second assertion timeout. This is the same failure previously tracked in #3862, despite its synchronization fix having merged in #3863.The fixture is 120 plain completed turns and does not exercise #4090's aborted-turn path. This run therefore does not establish that #4090 caused the failure. It also does not identify which scroll owner won the race. What it does establish is that the existing event-plus-two-frames test barrier does not make the virtualizer's tail window deterministic while the current ownership model remains in place.
#4105 already removes the competing ownership paths and retargets the prompt-rail readiness checks. Its hosted prompt-rail result should also be treated as regression evidence for this exact recurrence, not only for the session-switch CLS symptom.
Posted with Codex assistance; @Astro-Han verified the linked run and diagnosis.
refactor(ui): make the transcript the only writer of its scroll posit…
Phoenix500526 commentedon Aug 29, 2026
take
Astro-Han commentedon Aug 29, 2026
Closed by #4105 (
afc1a750b).Decision: Maka owns it. Worth recording that "Astryx owns it" was the branch's first answer, not a rejected option —
d061bdba3handed following the tail back and deletedarrival-bottom-pin.tsoutright. Reading Astryx's controller, it already covered what six review rounds had put into that pin: resize-synthetic scroll events excluded by comparingscrollHeightandoffsetHeight, horizontal wheels excluded by requiringdeltaY < 0, gestures scoped by binding to the scroller rather than by testing pointer position.Three fixes later it was clear the ownership could not sit there, and the deciding one is not an Astryx defect. Astryx decides "the reader left the tail" from a gesture, and gestures bubble. The transcript is self-scrolling, so its scroller is the whole
ChatLayoutroot — with a tool output body, a pty terminal, the composer and the graph panel inside it, each scrolling on its own. A wheel one of those consumes never moves the outer scroller, so noscrolland noscrollendfollow and the re-lock can never run: following is off, distance to the bottom is still zero so the affordance stays hidden, and the reader has no way back. That is a modelling assumption (no self-scrolling descendants) that this DOM does not satisfy, not a bug upstream.So the predicate changed from gesture to position.
scrolldoes not bubble, which is what makes a gesture a nested scroller consumed physically unable to reach the authority. One genuine upstream defect did surface on the way — underprefers-reduced-motionthe spring never runs, so both of Astryx's gesture releases are dead code — and it was reported rather than worked around.Taken slightly differently from the option as worded here: rather than merging
useChatScrollintouseTurnVirtualizer, the authority is its own module and the virtualizer keeps only its height index. Same ownership answer; the virtualizer's geometry turned out to be the wrong home, because the transcript renders content outside the turn wrappers it observes.All five
scrollTopwriters named above are gone or subordinate:chat-scroll-anchor.tsandarrival-bottom-pin.tsdeleted outright, the two inuse-chat-scrollnow one-shot commands that release the pin first, the virtualizer'sscrollIntoViewlikewise. Thedocument.fonts.readygate, the 50×100 ms markdown polling and the doublerequestAnimationFrameare all removed. Non-goals held: rail navigation and earlier-history loading behave as before.Not done here, deliberately: the long tasks and CLS 0.55 in the Measurements section stay unattributed, as this issue said they would. CLS did fall from 0.481–0.521 to 0.089, but that came from removing the speculative prefetch, not from the ownership change — a post-merge A/B against the merge-base showed the streaming and scrolled-up cases identical on both sides. Root-causing the jank remains separate work.
🤖 Posted by Claude Code