Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(transcript): retire old navigation on disclosure takeover

Seraph-xbf38d53721a8
diff --git a/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.ts b/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.ts
index 26179b162..e9f925e5f 100644
--- a/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.ts
+++ b/apps/desktop/src/features/chat/transcript/hooks/useTranscriptScroll.ts
@@ -144,6 +144,15 @@ export function useTranscriptScroll({
onRestore: onRestoreReading, onMissing: readingPositionMissing,
});
+ // State transition only: completion calls this after starting its own
+ // prompt navigation, which must be allowed to finish.
+ const leaveFollow = useCallback(() => {
+ cancelReadingPosition();
+ cancelFollowScroll();
+ pinnedRef.current = false;
+ setShowJump(true);
+ }, [cancelFollowScroll, cancelReadingPosition]);
+
/*
Leave follow mode. Every reader-driven move inside the transcript starts
here: while the scroller is still pinned, a scroll that carries no input
@@ -151,11 +160,9 @@ export function useTranscriptScroll({
the view one frame later and undoes the move.
*/
const releaseFollow = useCallback(() => {
- cancelReadingPosition();
- cancelFollowScroll();
- pinnedRef.current = false;
- setShowJump(true);
- }, [cancelFollowScroll, cancelReadingPosition]);
+ stopSmoothScroll(scrollRef.current);
+ leaveFollow();
+ }, [leaveFollow]);
// A manual disclosure (a tool, thinking or activity title; #324) hands this
// scroller the very title it was toggled from, before the expansion state
@@ -486,7 +493,7 @@ export function useTranscriptScroll({
useTurnCompletionScroll({
isRunning, paneVisible, readingWindow, messages, scrollRef, contentRef,
isFollowing: () => pinnedRef.current && !isDisclosureAnchorHeld(),
- onAnchored: releaseFollow,
+ onAnchored: leaveFollow,
});
useLayoutEffect(() => {
@@ -616,6 +623,7 @@ export function useTranscriptScroll({
);
const releaseSearchFollow = useCallback((fresh: boolean) => {
+ stopSmoothScroll(scrollRef.current);
cancelReadingPosition();
if (fresh) prependHeightRef.current = null;
releaseDisclosureAnchor();
diff --git a/apps/desktop/src/hooks/use-follow-scroll.ts b/apps/desktop/src/hooks/use-follow-scroll.ts
index 0f56decfe..2053a7fd8 100644
--- a/apps/desktop/src/hooks/use-follow-scroll.ts
+++ b/apps/desktop/src/hooks/use-follow-scroll.ts
@@ -77,6 +77,7 @@ export function useFollowScroll(): FollowScroll {
} = useDisclosureAnchor(
scrollRef,
useCallback(() => {
+ stopSmoothScroll(scrollRef.current);
cancelFollowScroll();
pinnedRef.current = false;
setShowJump(true);
@@ -205,6 +206,7 @@ export function useFollowScroll(): FollowScroll {
}, [releaseDisclosureAnchor, scrollToBottom]);
const releaseFollow = useCallback(() => {
+ stopSmoothScroll(scrollRef.current);
releaseDisclosureAnchor();
cancelFollowScroll();
pinnedRef.current = false;
diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.md
index 82754eea9..d7c3f142d 100644
--- a/docs/spec/04-ux/09-interaction-patterns.md
+++ b/docs/spec/04-ux/09-interaction-patterns.md
@@ -779,6 +779,9 @@ may be retained while exactly one workspace supplies the visible shell context.
belong to the select. The same ownership and cancellation rules apply to
delegated transcript scrollers. Releasing follow after a completed turn's
prompt navigation does not cancel that newly started navigation.
+ A manual disclosure or history navigation also cancels the prior browser
+ navigation before taking ownership; completion's state-only follow release
+ is separate from these reader-driven moves.
- Sending a new prompt, retrying, or regenerating always re-pins follow mode and jumps to the bottom before the turn continues, even if the user had scrolled up
- "Scroll to bottom" floating button appears as soon as manual upward scrolling
releases follow mode
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 1c6f1b18e..1237c232a 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -44,6 +44,8 @@
ancestor cancellation. Button Space must allow the original navigation to
finish. `e2e-transcript-turn-completion.mjs` also verifies normal completed-turn
prompt navigation and a reader's manually retained position.
+ Start smooth navigation immediately before toggling a real disclosure in
+ both main and delegated scrollers; its clicked title must keep its offset.
- **Coverage:** `node scripts/e2e-transcript-disclosure-anchor.mjs` and
`node scripts/e2e-transcript-render.mjs`.
- **Specs:** Interaction patterns §2.2. **Milestone:** Maintenance.
diff --git a/scripts/e2e/transcript-disclosure-anchor.tsx b/scripts/e2e/transcript-disclosure-anchor.tsx
index 9a4fecddd..9500d321b 100644
--- a/scripts/e2e/transcript-disclosure-anchor.tsx
+++ b/scripts/e2e/transcript-disclosure-anchor.tsx
@@ -684,10 +684,16 @@ globalThis.transcriptDisclosureProbe = async () => {
await waitForLayout({ label: "interruption mount", scroller: interruptScroller,
content: interruptContent, title: interruptTitle,
expected: () => interruptTitle.isConnected, direction: "initial" });
+ const beforeDisclosureNavigation = geometry(interruptScroller, interruptTitle);
await waitForLayout({ label: "interruption disclosure", scroller: interruptScroller,
content: interruptContent, title: interruptTitle,
expected: () => interruptTitle.getAttribute("aria-expanded") === "true", direction: "grow",
- trigger: () => interruptTitle.click() });
+ trigger: () => {
+ interruptScroller.scrollTo({ top: 0, behavior: "smooth" });
+ interruptTitle.click();
+ } });
+ assert(Math.abs(geometry(interruptScroller, interruptTitle).titleTop - beforeDisclosureNavigation.titleTop) < 2,
+ "a pending navigation moved the manually toggled disclosure title");
assert(interruptScroller.scrollTop > 0, "interruption fixture has no scroll range");
interruptScroller.scrollTo({ top: 0, behavior: "smooth" });
const interruptedTop = interruptScroller.scrollTop;
@@ -719,10 +725,16 @@ globalThis.transcriptDisclosureProbe = async () => {
await waitForLayout({ label: "nested interruption mount", scroller: nestedScroller,
content: nestedContent, title: nestedTitle,
expected: () => nestedTitle.isConnected, direction: "initial" });
+ const beforeNestedDisclosureNavigation = geometry(nestedScroller, nestedTitle);
await waitForLayout({ label: "nested interruption disclosure", scroller: nestedScroller,
content: nestedContent, title: nestedTitle,
expected: () => nestedTitle.getAttribute("aria-expanded") === "true", direction: "grow",
- trigger: () => nestedTitle.click() });
+ trigger: () => {
+ nestedScroller.scrollTo({ top: 0, behavior: "smooth" });
+ nestedTitle.click();
+ } });
+ assert(Math.abs(geometry(nestedScroller, nestedTitle).titleTop - beforeNestedDisclosureNavigation.titleTop) < 2,
+ "a pending nested navigation moved the manually toggled disclosure title");
const nestedTop = nestedScroller.scrollTop;
assert(nestedTop > 0, "nested fixture has no scroll range");
nestedScroller.scrollTo({ top: 0, behavior: "smooth" });
diff --git a/scripts/e2e/transcript-long-history.tsx b/scripts/e2e/transcript-long-history.tsx
index 1f2d7779c..16a260556 100644
--- a/scripts/e2e/transcript-long-history.tsx
+++ b/scripts/e2e/transcript-long-history.tsx
@@ -246,24 +246,6 @@ export async function transcriptLongHistoryProbe() {
await until(() => host.textContent?.includes("Older row corrected") === true, "older row correction");
await settled();
const markers = [...host.querySelectorAll<HTMLButtonElement>(".minimap-marker.assistant")];
- const scrollTrace: unknown[] = [];
- const observedScroller = element(".thread-scroll");
- const nativeScrollTo = observedScroller.scrollTo.bind(observedScroller);
- observedScroller.scrollTo = (options?: ScrollToOptions | number, y?: number) => {
- scrollTrace.push({ kind: "scrollTo", options, y });
- if (typeof options === "number") nativeScrollTo(options, y ?? 0);
- else nativeScrollTo(options ?? {});
- };
- const topProperty = Object.getOwnPropertyDescriptor(Element.prototype, "scrollTop")!;
- Object.defineProperty(observedScroller, "scrollTop", {
- configurable: true,
- get() { return topProperty.get!.call(this); },
- set(top: number) {
- scrollTrace.push({ kind: "scrollTop", top });
- topProperty.set!.call(this, top);
- },
- });
- observedScroller.addEventListener("wheel", () => scrollTrace.push({ kind: "wheel" }));
assert(markers.length > 0, "minimap markers missing");
let freshPreview = false;
const previews: string[] = [];
@@ -295,7 +277,6 @@ export async function transcriptLongHistoryProbe() {
await settled();
const readingTop = scroller.scrollTop;
const readingHeight = scroller.scrollHeight;
- scrollTrace.push({ kind: "before-stream", readingTop, readingHeight });
await stream(largest, " reader-stays");
assert(Math.abs(scroller.scrollTop - readingTop) < 2,
`stream stole the reader's scroll position: ${JSON.stringify({
@@ -303,11 +284,6 @@ export async function transcriptLongHistoryProbe() {
after: { top: scroller.scrollTop, height: scroller.scrollHeight },
viewport: scroller.clientHeight,
reducedMotion: window.matchMedia("(prefers-reduced-motion: reduce)").matches,
- scrollTrace,
- animations: host.getAnimations({ subtree: true }).map((animation) => ({
- playState: animation.playState,
- property: (animation as CSSTransition).transitionProperty,
- })),
})}`);
// Terminal re-key must replace exactly the provisional row, survive cache
@@ -425,7 +401,7 @@ export async function transcriptLongHistoryProbe() {
assert(reads.every((read) => read.limit === 100), "ordinary selection requested unbounded Host history");
assert(errors.length === 0, `render errors: ${errors.map(String)}`);
return { ok: true, workCounts, hostPageSize: 100, simultaneousRunningSessions: 3,
- diagnostics: { scrollTrace, eventToSettledDomMs: latencies, longTasksMs: observer ? longTasks : null,
+ diagnostics: { eventToSettledDomMs: latencies, longTasksMs: observer ? longTasks : null,
heapBefore, heapAfter: heap() } };
} finally {
flushSync(() => root.unmount());