Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(web): stop tool calls from leaving a blank page in threads (#7971)

Theo Browneea8c9e5ca3ac
diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.ts
index 66e83f1f7..cb814dace 100644
--- a/apps/web/src/components/ChatView.logic.test.ts
+++ b/apps/web/src/components/ChatView.logic.test.ts
@@ -34,6 +34,7 @@ import {
scheduleEnvironmentReconnectWarning,
startNewThreadForProject,
shouldDockDraftHeroForSubmission,
+ shouldReleaseTimelineAnchorForToolActivity,
shouldShowBranchMismatchBanner,
shouldWriteThreadErrorToCurrentServerThread,
} from "./ChatView.logic";
@@ -77,6 +78,114 @@ describe("draft hero submission transition", () => {
});
});
+describe("shouldReleaseTimelineAnchorForToolActivity", () => {
+ const activeTurnId = TurnId.make("active-turn");
+ const anchorMessageId = MessageId.make("anchored-message");
+ const activeToolEntry = {
+ id: "tool-entry",
+ kind: "work" as const,
+ createdAt: now,
+ entry: {
+ id: "active-tool",
+ createdAt: now,
+ turnId: activeTurnId,
+ label: "Run command",
+ tone: "tool" as const,
+ command: "git status",
+ },
+ };
+
+ it("releases the send anchor for tool activity in the active turn", () => {
+ expect(
+ shouldReleaseTimelineAnchorForToolActivity({
+ anchorMessageId,
+ liveFollowEnabled: true,
+ runningTurnId: activeTurnId,
+ timelineEntries: [activeToolEntry],
+ }),
+ ).toBe(true);
+ });
+
+ it("keeps the anchor while the user reads history", () => {
+ expect(
+ shouldReleaseTimelineAnchorForToolActivity({
+ anchorMessageId,
+ liveFollowEnabled: false,
+ runningTurnId: activeTurnId,
+ timelineEntries: [activeToolEntry],
+ }),
+ ).toBe(false);
+ });
+
+ it("ignores tool activity from earlier turns", () => {
+ expect(
+ shouldReleaseTimelineAnchorForToolActivity({
+ anchorMessageId,
+ liveFollowEnabled: true,
+ runningTurnId: activeTurnId,
+ timelineEntries: [
+ {
+ ...activeToolEntry,
+ entry: {
+ ...activeToolEntry.entry,
+ turnId: TurnId.make("previous-turn"),
+ },
+ },
+ ],
+ }),
+ ).toBe(false);
+ });
+
+ it("ignores thinking and error rows without tool activity", () => {
+ expect(
+ shouldReleaseTimelineAnchorForToolActivity({
+ anchorMessageId,
+ liveFollowEnabled: true,
+ runningTurnId: activeTurnId,
+ timelineEntries: [
+ {
+ ...activeToolEntry,
+ entry: {
+ id: "thinking-entry",
+ createdAt: now,
+ turnId: activeTurnId,
+ label: "Thinking",
+ tone: "thinking",
+ },
+ },
+ {
+ ...activeToolEntry,
+ id: "error-entry",
+ entry: {
+ id: "error-entry",
+ createdAt: now,
+ turnId: activeTurnId,
+ label: "Provider error",
+ tone: "error",
+ },
+ },
+ ],
+ }),
+ ).toBe(false);
+ });
+
+ it("does nothing without an anchor or running turn", () => {
+ const input = {
+ anchorMessageId,
+ liveFollowEnabled: true,
+ runningTurnId: activeTurnId,
+ timelineEntries: [activeToolEntry],
+ };
+
+ expect(shouldReleaseTimelineAnchorForToolActivity({ ...input, anchorMessageId: null })).toBe(
+ false,
+ );
+ expect(shouldReleaseTimelineAnchorForToolActivity({ ...input, runningTurnId: null })).toBe(
+ false,
+ );
+ });
+});
+
describe("environment reconnect warning grace", () => {
afterEach(() => vi.useRealTimers());
diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.ts
index b790aa025..83bea23b6 100644
--- a/apps/web/src/components/ChatView.logic.ts
+++ b/apps/web/src/components/ChatView.logic.ts
@@ -2,6 +2,7 @@ import {
type EnvironmentId,
isProviderDriverKind,
ProjectId,
+ type MessageId,
type ModelSelection,
type ProviderDriverKind,
type ServerProvider,
@@ -22,6 +23,7 @@ import {
} from "../lib/terminalContext";
import type { DraftThreadEnvMode } from "../composerDraftStore";
import type { ComposerSubmissionIntent } from "../composer-logic";
+import type { TimelineEntry } from "../session-logic";
export const LAST_INVOKED_SCRIPT_BY_PROJECT_KEY = "t3code:last-invoked-script-by-project";
export const MAX_HIDDEN_MOUNTED_TERMINAL_THREADS = 10;
@@ -42,6 +44,31 @@ export function shouldDockDraftHeroForSubmission(input: {
);
}
+export function shouldReleaseTimelineAnchorForToolActivity(input: {
+ anchorMessageId: MessageId | null;
+ liveFollowEnabled: boolean;
+ runningTurnId: TurnId | null;
+ timelineEntries: ReadonlyArray<TimelineEntry>;
+}): boolean {
+ if (input.anchorMessageId === null || !input.liveFollowEnabled || input.runningTurnId === null) {
+ return false;
+ }
+
+ return input.timelineEntries.some((timelineEntry) => {
+ if (timelineEntry.kind !== "work" || timelineEntry.entry.turnId !== input.runningTurnId) {
+ return false;
+ }
+
+ const entry = timelineEntry.entry;
+ return (
+ entry.tone === "tool" ||
+ entry.itemType !== undefined ||
+ entry.requestKind !== undefined ||
+ (entry.command?.trim().length ?? 0) > 0
+ );
+ });
+}
+
export function resolveDraftHeroState(input: {
isLocalDraftThread: boolean;
hasTimelineEntries: boolean;
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index bbee2d170..46ed05115 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -328,6 +328,7 @@ import {
hasServerAcknowledgedLocalDispatch,
isBranchMismatchDismissedForSession,
shouldDockDraftHeroForSubmission,
+ shouldReleaseTimelineAnchorForToolActivity,
shouldShowBranchMismatchBanner,
getStartedThreadModelChangeBlockReason,
LAST_INVOKED_SCRIPT_BY_PROJECT_KEY,
@@ -1756,6 +1757,9 @@ function ChatViewContent(props: ChatViewProps) {
return openTerminalThreadKeys.filter((nextThreadKey) => existingThreadKeys.has(nextThreadKey));
}, [draftThreadKeys, openTerminalThreadKeys, serverThreadKeys]);
const activeLatestTurn = activeThread?.latestTurn ?? null;
+ const activeRunningTurnId =
+ (activeThread?.session?.status === "running" ? activeThread.session.activeTurnId : null) ??
+ (activeLatestTurn?.state === "running" ? activeLatestTurn.turnId : null);
// Reading a finished thread clears the sidebar's Done badge. The visit is
// stamped at the turn's completion time — not now/updatedAt — so it clears
// exactly the completion the user is looking at: a wake or completion that
@@ -3895,6 +3899,8 @@ function ChatViewContent(props: ChatViewProps) {
liveFollowUserScrollGenerationRef.current = anchorUserScrollGenerationRef.current;
setTimelineLiveFollowEnabled(true);
pendingTimelineAnchorRef.current = null;
+ positionedTimelineAnchorRef.current = null;
+ settledTimelineAnchorRef.current = null;
activeTimelineAnchorIndexRef.current = null;
showScrollDebouncer.current.cancel();
setShowScrollToBottom(false);
@@ -3903,6 +3909,28 @@ function ChatViewContent(props: ChatViewProps) {
void legendListRef.current?.scrollToEnd?.({ animated });
});
}, []);
+ useLayoutEffect(() => {
+ if (timelineScrollModeRef.current !== "anchoring-new-turn") {
+ return;
+ }
+
+ if (
+ shouldReleaseTimelineAnchorForToolActivity({
+ anchorMessageId: timelineAnchorMessageId,
+ liveFollowEnabled: timelineLiveFollowEnabled,
+ runningTurnId: activeRunningTurnId,
+ timelineEntries,
+ })
+ ) {
+ scrollToEnd();
+ }
+ }, [
+ activeRunningTurnId,
+ scrollToEnd,
+ timelineAnchorMessageId,
+ timelineEntries,
+ timelineLiveFollowEnabled,
+ ]);
useEffect(() => {
let removeListeners: (() => void) | null = null;
let frame: number | null = null;
@@ -6640,11 +6668,7 @@ function ChatViewContent(props: ChatViewProps) {
listRef={legendListRef}
timelineEntries={timelineEntries}
latestTurn={activeLatestTurn}
- runningTurnId={
- activeThread.session?.status === "running"
- ? activeThread.session.activeTurnId
- : null
- }
+ runningTurnId={activeRunningTurnId}
turnDiffSummaryByAssistantMessageId={turnDiffSummaryByAssistantMessageId}
activeThreadEnvironmentId={activeThread.environmentId}
routeThreadKey={routeThreadKey}
diff --git a/apps/web/src/components/chat/MessagesTimeline.test.tsx b/apps/web/src/components/chat/MessagesTimeline.test.tsx
index 4647384fc..6d007a5b6 100644
--- a/apps/web/src/components/chat/MessagesTimeline.test.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.test.tsx
@@ -558,6 +558,49 @@ describe("MessagesTimeline", () => {
expect(onAnchorReady).not.toHaveBeenCalled();
});
+ it("keeps reserved end space when tool work starts while reading history", () => {
+ const turnId = TurnId.make("turn-with-active-tool");
+ const firstEntry = buildUserTimelineEntry("Run the command.");
+ const markup = renderToStaticMarkup(
+ <MessagesTimeline
+ {...buildProps()}
+ isWorking
+ activeTurnStartedAt={MESSAGE_CREATED_AT}
+ latestTurn={{
+ turnId,
+ state: "running",
+ startedAt: MESSAGE_CREATED_AT,
+ completedAt: null,
+ }}
+ runningTurnId={turnId}
+ anchorMessageId={firstEntry.message.id}
+ liveFollowEnabled={false}
+ timelineEntries={[
+ firstEntry,
+ {
+ id: "entry-active-tool",
+ kind: "work",
+ createdAt: MESSAGE_CREATED_AT,
+ entry: {
+ id: "work-active-tool",
+ createdAt: MESSAGE_CREATED_AT,
+ turnId,
+ toolCallId: "call-active-tool",
+ label: "Run command",
+ tone: "tool",
+ itemType: "command_execution",
+ command: "git status",
+ toolLifecycleStatus: "inProgress",
+ },
+ },
+ ]}
+ />,
+ );
+
+ expect(markup).toContain('data-anchor-index="0"');
+ expect(markup).not.toContain('data-maintain-scroll-at-end="enabled"');
+ });
+
it("hands end-following back to the list once the send anchor is released", () => {
const firstEntry = buildUserTimelineEntry("First prompt.");
const secondEntry = {