From 2fa0e4b169ee1d0daddd80dc167e67bf65f0ee2a Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Sat, 14 Nov 2026 09:32:44 +0000 Subject: [PATCH] fix(app): load older history when an upward wheel lands at the start (#9570) A wheel listener can run before or after the browser applies the scroll it causes. When the reader had already stopped following output and the last notch landed exactly at the history start, the listener saw the pre-scroll position, did not re-arm history-start pagination, and no older page was requested. The upward scroll now re-arms loading itself. The turn-collapse journey hung on this race until its 120s timeout; the older-history page wait now fails with a message after the expect timeout. Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- .../support/helpers/agent-timeline-gate.ts | 19 --------- .../support/helpers/timeline-pagination.ts | 6 ++- .../strategy-web.browser.test.tsx | 40 ++++++++++++++++++- .../app/src/agent-stream/strategy-web.tsx | 23 ++++++++--- 4 files changed, 61 insertions(+), 27 deletions(-) diff --git a/packages/app/e2e/support/helpers/agent-timeline-gate.ts b/packages/app/e2e/support/helpers/agent-timeline-gate.ts index 89a1d8c364..3c979bf51d 100644 --- a/packages/app/e2e/support/helpers/agent-timeline-gate.ts +++ b/packages/app/e2e/support/helpers/agent-timeline-gate.ts @@ -21,7 +21,6 @@ export interface OlderTimelinePagesGate { getRepeatedEntryCount(): number; getOwnedEntryCountContaining(text: string): number; releasePage(pageNumber: number): void; - waitForRequestCount(count: number): Promise; } export interface DaemonHydrationGate { @@ -371,15 +370,6 @@ export async function holdAgentOlderTimelinePages( const ownedEntries = new Map(); const releasedPages = new Set(); const delayedForwards = new Map void>>(); - const requestWaiters = new Map void>>(); - - const resolveRequestWaiters = () => { - for (const [count, resolvers] of requestWaiters) { - if (requestCount < count) continue; - requestWaiters.delete(count); - for (const resolve of resolvers) resolve(); - } - }; const routePattern = daemonPort === undefined ? daemonWsRoutePattern() : wsRoutePatternForPort(String(daemonPort)); @@ -393,7 +383,6 @@ export async function holdAgentOlderTimelinePages( sessionMessage.direction === "before" ) { requestCount += 1; - resolveRequestWaiters(); } server.send(message); }); @@ -439,14 +428,6 @@ export async function holdAgentOlderTimelinePages( for (const forward of delayedForwards.get(pageNumber) ?? []) forward(); delayedForwards.delete(pageNumber); }, - waitForRequestCount(count) { - if (requestCount >= count) return Promise.resolve(); - return new Promise((resolve) => { - const resolvers = requestWaiters.get(count) ?? []; - resolvers.push(resolve); - requestWaiters.set(count, resolvers); - }); - }, }; } diff --git a/packages/app/e2e/support/helpers/timeline-pagination.ts b/packages/app/e2e/support/helpers/timeline-pagination.ts index ed69897e4e..802ec2a29b 100644 --- a/packages/app/e2e/support/helpers/timeline-pagination.ts +++ b/packages/app/e2e/support/helpers/timeline-pagination.ts @@ -427,7 +427,11 @@ export async function holdOlderHistoryPages( const loader = page.getByTestId("load-older-history-spinner"); return { async expectRequestedPages(count) { - await gate.waitForRequestCount(count); + await expect + .poll(() => gate.getRequestCount(), { + message: `older history requests ${count} page(s)`, + }) + .toBeGreaterThanOrEqual(count); expect(gate.getRequestCount()).toBe(count); }, async expectSettledWithRequestedPages(count) { diff --git a/packages/app/src/agent-stream/strategy-web.browser.test.tsx b/packages/app/src/agent-stream/strategy-web.browser.test.tsx index 12127ea630..a9cc44a849 100644 --- a/packages/app/src/agent-stream/strategy-web.browser.test.tsx +++ b/packages/app/src/agent-stream/strategy-web.browser.test.tsx @@ -49,7 +49,12 @@ afterEach(() => { host.remove(); }); -function mountTimeline(historyMounted: StreamItem[]) { +type OlderHistoryInput = Pick< + StreamRenderInput, + "onNearHistoryStart" | "hasOlderHistory" | "olderHistoryProgressKey" +>; + +function mountTimeline(historyMounted: StreamItem[], olderHistory?: OlderHistoryInput) { const strategy = createWebStreamStrategy({ isMobileBreakpoint: true }); const viewportRef = React.createRef(); const input: StreamRenderInput = { @@ -76,6 +81,7 @@ function mountTimeline(historyMounted: StreamItem[]) { baseListContentContainerStyle: null, forwardListContentContainerStyle: null, contentMaxWidth: DEFAULT_CONTENT_MAX_WIDTH, + ...olderHistory, }; const render = (segments: Partial) => root.render(strategy.render({ ...input, segments: { ...input.segments, ...segments } })); @@ -100,6 +106,11 @@ function mountTimeline(historyMounted: StreamItem[]) { scrollTo: (top: number) => { scrollContainer.scrollTop = top; }, + // A wheel listener runs before the browser applies the scroll the wheel causes. + wheelUpTo: (top: number) => { + scrollContainer.dispatchEvent(new WheelEvent("wheel", { bubbles: true, deltaY: -1000 })); + scrollContainer.scrollTop = top; + }, distanceFromEnd: () => scrollContainer.scrollHeight - scrollContainer.clientHeight - scrollContainer.scrollTop, // Resize observers and the hold's settle run on animation frames. @@ -208,3 +219,30 @@ describe("web disclosure hold", () => { expect(timeline.distanceFromEnd()).toBeLessThanOrEqual(1); }); }); + +describe("web history start", () => { + it("loads older history when an upward wheel lands at the start after the reader stopped following", async () => { + let olderHistoryLoads = 0; + const history = [1, 2, 3, 4, 5, 6].map((index) => row(index)); + const timeline = mountTimeline(history, { + hasOlderHistory: true, + olderHistoryProgressKey: "epoch:1", + onNearHistoryStart: async () => { + olderHistoryLoads += 1; + return true; + }, + }); + await timeline.settle(); + // Opening a row at the bottom stops following output without any scroll. + timeline.hold("message-5", () => + timeline.render({ historyMounted: [...history.slice(0, 5), row(7, 200), history[5]!] }), + ); + await timeline.settle(); + expect(olderHistoryLoads).toBe(0); + + timeline.wheelUpTo(0); + await timeline.settle(); + + expect(olderHistoryLoads).toBe(1); + }); +}); diff --git a/packages/app/src/agent-stream/strategy-web.tsx b/packages/app/src/agent-stream/strategy-web.tsx index c47e0720f4..896b53b3f6 100644 --- a/packages/app/src/agent-stream/strategy-web.tsx +++ b/packages/app/src/agent-stream/strategy-web.tsx @@ -605,6 +605,15 @@ function WebStreamViewport(props: StreamRenderInput & { isMobileBreakpoint: bool window.performance.now() + UPWARD_INPUT_EVIDENCE_TIMEOUT_MS; }, []); + const hasUpwardInputEvidence = useCallback(() => { + const mouseGesture = mouseScrollGestureRef.current; + return ( + mouseGesture?.kind === "scrollbar" || + (mouseGesture?.kind === "autoscroll" && mouseGesture.hasUpwardEvidence) || + window.performance.now() < upwardInputEvidenceUntilRef.current + ); + }, []); + useLayoutEffect(() => { if (isActive) { return; @@ -791,16 +800,16 @@ function WebStreamViewport(props: StreamRenderInput & { isMobileBreakpoint: bool const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - USER_SCROLL_DELTA_EPSILON; const scrolledDown = currentScrollTop > lastKnownScrollTopRef.current + USER_SCROLL_DELTA_EPSILON; - const mouseGesture = mouseScrollGestureRef.current; - const hasUpwardInputEvidence = - mouseGesture?.kind === "scrollbar" || - (mouseGesture?.kind === "autoscroll" && mouseGesture.hasUpwardEvidence) || - window.performance.now() < upwardInputEvidenceUntilRef.current; + const userScrolledUp = scrolledUp && hasUpwardInputEvidence(); if (!followOutputRef.current && isAtBottom && scrolledDown && !isJumpSettling()) { setFollowOutput(true); - } else if (followOutputRef.current && scrolledUp && hasUpwardInputEvidence) { + } else if (followOutputRef.current && userScrolledUp) { stopFollowingOutputFromUserIntent(); + } else if (userScrolledUp) { + // Wheel listeners can run before or after the browser applies the scroll, so the + // upward scroll itself re-arms loading when it reaches the start. + rearmHistoryStartFromUserIntent(); } lastKnownScrollTopRef.current = currentScrollTop; @@ -811,8 +820,10 @@ function WebStreamViewport(props: StreamRenderInput & { isMobileBreakpoint: bool evaluateHistoryStart(); }, [ evaluateHistoryStart, + hasUpwardInputEvidence, isJumpSettling, readingAnchor, + rearmHistoryStartFromUserIntent, stopFollowingOutputFromUserIntent, updateScrollMetrics, ]);