Skip to content
TypeScript

refactor(web): drop the unreachable paint-only thread timeline path (#25787)

Julius Marminge6f6c6c14b76e
diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.ts
index 969a5d2e24c..363e5db0b60 100644
--- a/apps/web/src/components/ChatView.logic.test.ts
+++ b/apps/web/src/components/ChatView.logic.test.ts
@@ -45,7 +45,6 @@ import {
rememberReadyThreadTimeline,
resetHeldThreadTimeline,
resolveThreadSwitchTimeline,
- threadKeysShareEnvironment,
timelineHasEphemeralPreviewUrls,
createLocalDispatchSnapshot,
deriveCommittedServerUserMessageIds,
@@ -371,19 +370,18 @@ describe("resolveThreadSwitchTimeline", () => {
activeThreadKey: "env-1:thread-a",
nextEntries: [],
}),
- ).toEqual({ entries: ["a1", "a2"], displayThreadKey: "env-1:thread-a" });
+ ).toEqual(["a1", "a2"]);
});
- it("does not hold another environment's timeline across a jump", () => {
- expect(threadKeysShareEnvironment("env-1:thread-a", "env-2:thread-b")).toBe(false);
+ it("does not paint the last-viewed thread for a destination with nothing remembered", () => {
+ rememberReadyThreadTimeline(held);
expect(
resolveThreadSwitchTimeline({
loading: true,
activeThreadKey: "env-2:thread-b",
nextEntries: [],
- lastReady: held,
}),
- ).toEqual({ entries: [], displayThreadKey: "env-2:thread-b" });
+ ).toEqual([]);
});
it("does not remember a timeline that still has handoff blob previews", () => {
diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.ts
index 67c10d9dfea..0e36a3ef468 100644
--- a/apps/web/src/components/ChatView.logic.ts
+++ b/apps/web/src/components/ChatView.logic.ts
@@ -46,7 +46,6 @@ import {
} from "@t3tools/contracts";
import { worktreeSetupAgentStarted } from "@t3tools/client-runtime/worktree-setup";
import * as DateTime from "effect/DateTime";
-import { parseScopedThreadKey } from "@t3tools/client-runtime/environment";
import { resolveAssetUrl } from "@t3tools/client-runtime/state/assets";
import {
squashAtomCommandFailure,
@@ -346,15 +345,12 @@ export function resolveDraftHeroState(input: {
export type HeldThreadTimeline<T extends readonly unknown[]> = {
threadKey: string | null;
entries: T;
- markdownCwd?: string | null;
- workspaceRoot?: string | null;
};
const MAX_REMEMBERED_THREAD_TIMELINES = 16;
let rememberedThreadTimelines = new Map<string, HeldThreadTimeline<readonly unknown[]>>();
let rememberedThreadTimelineOrder: string[] = [];
-let lastReadyThreadKey: string | null = null;
function rememberThreadTimelineEntries(held: HeldThreadTimeline<readonly unknown[]>): void {
if (held.threadKey === null) {
@@ -371,7 +367,6 @@ function rememberThreadTimelineEntries(held: HeldThreadTimeline<readonly unknown
rememberedThreadTimelines.delete(evicted);
}
}
- lastReadyThreadKey = held.threadKey;
}
export function rememberReadyThreadTimeline<T extends readonly unknown[]>(
@@ -392,41 +387,9 @@ export function peekRememberedThreadTimeline<T extends readonly unknown[]>(
return (rememberedThreadTimelines.get(threadKey)?.entries as T | undefined) ?? null;
}
-export function peekHeldThreadTimeline<
- T extends readonly unknown[],
->(): HeldThreadTimeline<T> | null {
- if (lastReadyThreadKey === null) {
- return null;
- }
- const held = rememberedThreadTimelines.get(lastReadyThreadKey);
- if (held === undefined || held.entries.length === 0) {
- return null;
- }
- return held as HeldThreadTimeline<T>;
-}
-
export function resetHeldThreadTimeline(): void {
rememberedThreadTimelines = new Map();
rememberedThreadTimelineOrder = [];
- lastReadyThreadKey = null;
-}
-
-export function threadKeysShareEnvironment(left: string | null, right: string | null): boolean {
- if (left === null || right === null) {
- return false;
- }
- const leftRef = parseScopedThreadKey(left);
- const rightRef = parseScopedThreadKey(right);
- return leftRef !== null && rightRef !== null && leftRef.environmentId === rightRef.environmentId;
-}
-
-export function isPaintOnlyThreadTimeline(
- displayThreadKey: string | null,
- activeThreadKey: string | null,
-): boolean {
- return (
- displayThreadKey !== null && activeThreadKey !== null && displayThreadKey !== activeThreadKey
- );
}
export function resolveThreadSwitchTimeline<T extends readonly unknown[]>(input: {
@@ -434,19 +397,18 @@ export function resolveThreadSwitchTimeline<T extends readonly unknown[]>(input:
activeThreadKey: string | null;
nextEntries: T;
rememberedForActive?: T | null;
- lastReady?: HeldThreadTimeline<T> | null;
-}): { entries: T; displayThreadKey: string | null } {
+}): T {
if (input.nextEntries.length > 0) {
- return { entries: input.nextEntries, displayThreadKey: input.activeThreadKey };
+ return input.nextEntries;
}
const rememberedForActive =
input.rememberedForActive ?? peekRememberedThreadTimeline<T>(input.activeThreadKey);
if (input.loading && rememberedForActive !== null && rememberedForActive.length > 0) {
- return { entries: rememberedForActive, displayThreadKey: input.activeThreadKey };
+ return rememberedForActive;
}
- return { entries: input.nextEntries, displayThreadKey: input.activeThreadKey };
+ return input.nextEntries;
}
export function startNewThreadForProject(
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index 462728f093c..6486137a171 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -32,14 +32,7 @@ import { THREAD_FIND_BAR_RESERVED_HEIGHT } from "./chat/ThreadFindBar";
import { usageLimitRecoveryBannerItem } from "./chat/UsageLimitRecoveryBanner";
import { resolveDraftHeroState } from "./ChatView.logic";
import { useQueuedRunEdit } from "./chat/useQueuedRunEdit";
-import {
- isPaintOnlyThreadTimeline,
- peekHeldThreadTimeline,
- peekRememberedThreadTimeline,
- resolveThreadSwitchTimeline,
- recallCheckoutIsRepo,
- rememberCheckoutIsRepo,
-} from "./ChatView.logic";
+import { recallCheckoutIsRepo, rememberCheckoutIsRepo } from "./ChatView.logic";
import { useLogicalProjectEnvironments } from "../hooks/useLogicalProjectEnvironments";
import { useStableCallback } from "../hooks/useStableCallback";
import { useProjectScriptEditing } from "./chat/useProjectScriptEditing";
@@ -74,7 +67,6 @@ import {
type ServerProvider,
type ScopedThreadRef,
type ThreadId,
- type RunId,
ProviderInteractionMode,
resolveIdleCompaction,
RuntimeMode,
@@ -405,11 +397,6 @@ type ChatViewProps =
draftId: DraftId;
};
-const EMPTY_HELD_TURN_DIFF_SUMMARIES: readonly never[] = [];
-const noopHeldTurnDiff = (_turnId: RunId, _filePath?: string) => {};
-const noopHeldRevert = (_targetTurnCount: number) => {};
-const noopHeldAttachment = (_attachment: ChatFileAttachment) => {};
-
export default function ChatView(props: ChatViewProps) {
const {
environmentId,
@@ -1469,17 +1456,7 @@ export default function ChatView(props: ChatViewProps) {
entry.kind === "message" ? [entry.message] : [],
);
const timelineEmpty = timelineEntries.length === 0 && !hasStreamedTimelineRows;
- const displayedTimeline = resolveThreadSwitchTimeline({
- loading: timelineEmpty && threadSyncPhase !== null,
- activeThreadKey,
- nextEntries: timelineEntries,
- rememberedForActive: peekRememberedThreadTimeline<typeof timelineEntries>(activeThreadKey),
- });
- const displayedTimelineKey = displayedTimeline.displayThreadKey ?? routeThreadKey;
- const paintOnlyDisplayedTimeline = isPaintOnlyThreadTimeline(
- displayedTimeline.displayThreadKey,
- activeThreadKey,
- );
+ const displayedTimelineKey = activeThreadKey ?? routeThreadKey;
const displayedThreadRef = parseScopedThreadKey(displayedTimelineKey);
const {
worktreeSetup,
@@ -1624,9 +1601,6 @@ export default function ChatView(props: ChatViewProps) {
const activeProjectCwd = activeProject?.workspaceRoot ?? null;
const activeThreadWorktreePath = activeThread?.worktreePath ?? null;
const activeWorkspaceRoot = activeThreadWorktreePath ?? activeProjectCwd ?? undefined;
- const heldPaintContext = paintOnlyDisplayedTimeline
- ? peekHeldThreadTimeline<typeof timelineEntries>()
- : null;
const activeTerminalLaunchContext =
terminalUiLaunchContext?.threadId === activeThreadId ? terminalUiLaunchContext : null;
const liveIsGitRepo = gitStatusQuery.data?.isRepo;
@@ -2590,8 +2564,7 @@ export default function ChatView(props: ChatViewProps) {
const timelineSkills = activeProviderStatus
? resolveProviderSkillsForCwd(activeProviderStatus, gitCwd)
: EMPTY_PROVIDER_SKILLS;
- const threadFindEnabled =
- isServerThread && serverConfig?.threadFind === true && !paintOnlyDisplayedTimeline;
+ const threadFindEnabled = isServerThread && serverConfig?.threadFind === true;
const isThreadFindActive = useThreadFindOpen(activeThreadRef, threadFindEnabled);
useChatShortcuts({
@@ -2669,7 +2642,6 @@ export default function ChatView(props: ChatViewProps) {
serverProjection,
activeThread,
timelineMessages,
- paintOnlyDisplayedTimeline,
phase,
isConnecting,
isSendBusy,
@@ -3249,126 +3221,79 @@ export default function ChatView(props: ChatViewProps) {
activeThreadKey={activeThreadKey}
syncing={threadSyncPhase !== null}
detailLoading={threadDetailLoading}
- readyMarkdownCwd={gitCwd}
- readyWorkspaceRoot={activeWorkspaceRoot ?? null}
- citationRequest={paintOnlyDisplayedTimeline ? null : citationRequest}
+ citationRequest={citationRequest}
citationHistory={citationHistory}
- {...(!paintOnlyDisplayedTimeline
- ? {
- onCiteAssistantText: citeAssistantTextStable,
- ...(activeProject ? { onRunShellCommand: runShellCommandStable } : {}),
- }
- : {})}
- isWorking={!paintOnlyDisplayedTimeline && isWorking}
+ onCiteAssistantText={citeAssistantTextStable}
+ {...(activeProject ? { onRunShellCommand: runShellCommandStable } : {})}
+ isWorking={isWorking}
runlessWorkActive={runlessWorkStartedAt !== null}
- activeTurnInProgress={
- !paintOnlyDisplayedTimeline && (isWorking || !latestRunSettled)
- }
- isCompacting={!paintOnlyDisplayedTimeline && isCompacting}
+ activeTurnInProgress={isWorking || !latestRunSettled}
+ isCompacting={isCompacting}
awaitingUser={
- paintOnlyDisplayedTimeline
- ? null
- : activePendingApproval !== null
- ? "approval"
- : activePendingUserInput !== null ||
- // A secret request has no runtime request; the shell carries it.
- activeThreadShell?.hasPendingUserInput === true
- ? "input"
- : null
+ activePendingApproval !== null
+ ? "approval"
+ : activePendingUserInput !== null ||
+ // A secret request has no runtime request; the shell carries it.
+ activeThreadShell?.hasPendingUserInput === true
+ ? "input"
+ : null
}
awaitingRequestId={
- paintOnlyDisplayedTimeline
- ? null
- : (activePendingApproval?.requestId ??
- activePendingUserInput?.requestId ??
- null)
+ activePendingApproval?.requestId ?? activePendingUserInput?.requestId ?? null
}
- activeTurnStartedAt={paintOnlyDisplayedTimeline ? null : activeWorkStartedAt}
- worktreeSetup={paintOnlyDisplayedTimeline ? null : worktreeSetup}
+ activeTurnStartedAt={activeWorkStartedAt}
+ worktreeSetup={worktreeSetup}
onCancelWorktreeSetup={onCancelWorktreeSetupStable}
- {...(paintOnlyDisplayedTimeline
- ? {}
- : {
- retryableWorkspacePreparationRunIds,
- onRetryWorkspacePreparation: onRetryWorkspacePreparationStable,
- })}
+ retryableWorkspacePreparationRunIds={retryableWorkspacePreparationRunIds}
+ onRetryWorkspacePreparation={onRetryWorkspacePreparationStable}
{...(draftId
? { onWorktreeSetupWorkLocally: onWorktreeSetupWorkLocallyStable }
: {})}
{...(onOpenWorktreeSetupTerminal ? { onOpenWorktreeSetupTerminal } : {})}
- isPreparingWorktree={!paintOnlyDisplayedTimeline && isPreparingWorktree}
- footer={paintOnlyDisplayedTimeline ? null : timelineFooter}
+ isPreparingWorktree={isPreparingWorktree}
+ footer={timelineFooter}
listRef={legendListRef}
- runs={paintOnlyDisplayedTimeline ? [] : (serverProjection?.runs ?? [])}
- latestRun={paintOnlyDisplayedTimeline ? null : activeActivityRun}
- announcedRun={
- paintOnlyDisplayedTimeline
- ? null
- : announcedRun(activeActivityRun, serverProjection?.runs ?? [])
- }
- detailBehindShell={
- !paintOnlyDisplayedTimeline &&
- isDetailBehindShell(activeLatestRun, activeThreadShell?.latestRun ?? null)
- }
- runningRunId={paintOnlyDisplayedTimeline ? null : activeRunningTurnId}
- turnDiffSummaries={
- paintOnlyDisplayedTimeline ? EMPTY_HELD_TURN_DIFF_SUMMARIES : turnDiffSummaries
- }
+ runs={serverProjection?.runs ?? []}
+ latestRun={activeActivityRun}
+ announcedRun={announcedRun(activeActivityRun, serverProjection?.runs ?? [])}
+ detailBehindShell={isDetailBehindShell(
+ activeLatestRun,
+ activeThreadShell?.latestRun ?? null,
+ )}
+ runningRunId={activeRunningTurnId}
+ turnDiffSummaries={turnDiffSummaries}
activeThreadEnvironmentId={
displayedThreadRef?.environmentId ?? activeThread.environmentId
}
routeThreadKey={displayedTimelineKey}
displayThreadKey={displayedTimelineKey}
- paintOnly={paintOnlyDisplayedTimeline}
announceTurnStatus={!isProviderSubagent}
- onOpenTurnDiff={
- paintOnlyDisplayedTimeline ? noopHeldTurnDiff : onOpenTurnDiffStable
- }
+ onOpenTurnDiff={onOpenTurnDiffStable}
onOpenThread={onOpenRelatedThreadStable}
- parentThreadLink={paintOnlyDisplayedTimeline ? null : parentThreadLink}
- workflowOpening={paintOnlyDisplayedTimeline ? null : workflowOpening}
- onForkFromRun={paintOnlyDisplayedTimeline ? async () => {} : onForkFromRunStable}
+ parentThreadLink={parentThreadLink}
+ workflowOpening={workflowOpening}
+ onForkFromRun={onForkFromRunStable}
onRollbackCheckpoint={onTimelineRollbackCheckpointStable}
- supportsConversationRollback={
- !paintOnlyDisplayedTimeline && supportsConversationRollback
- }
+ supportsConversationRollback={supportsConversationRollback}
threadStartCheckpointReady={threadStartCheckpointReady}
availableRevertTurnCounts={availableRevertTurnCounts}
- onRevertToTurnCount={
- paintOnlyDisplayedTimeline ? noopHeldRevert : onRevertTimelineTurnStable
- }
- {...(!paintOnlyDisplayedTimeline
- ? {
- onUseArtifactTemplate: insertArtifactTemplateStable,
- onSendAppMessage: sendAppMessageStable,
- }
- : {})}
+ onRevertToTurnCount={onRevertTimelineTurnStable}
+ onUseArtifactTemplate={insertArtifactTemplateStable}
+ onSendAppMessage={sendAppMessageStable}
isRevertingCheckpoint={isRevertingCheckpoint}
onImageExpand={onExpandTimelineImageStable}
- onFileOpen={
- paintOnlyDisplayedTimeline ? noopHeldAttachment : openFileAttachmentStable
- }
- onFileDownload={
- paintOnlyDisplayedTimeline ? noopHeldAttachment : downloadFileAttachmentStable
- }
- markdownCwd={
- paintOnlyDisplayedTimeline
- ? (heldPaintContext?.markdownCwd ?? undefined)
- : (gitCwd ?? undefined)
- }
+ onFileOpen={openFileAttachmentStable}
+ onFileDownload={downloadFileAttachmentStable}
+ markdownCwd={gitCwd ?? undefined}
resolvedTheme={resolvedTheme}
timestampFormat={timestampFormat}
- workspaceRoot={
- paintOnlyDisplayedTimeline
- ? (heldPaintContext?.workspaceRoot ?? undefined)
- : activeWorkspaceRoot
- }
+ workspaceRoot={activeWorkspaceRoot}
skills={timelineSkills}
- anchorMessageId={paintOnlyDisplayedTimeline ? null : timelineAnchorMessageId}
+ anchorMessageId={timelineAnchorMessageId}
onAnchorReady={onTimelineAnchorReadyStable}
onAnchorSizeChanged={onTimelineAnchorSizeChangedStable}
contentInsetEndAdjustment={composerTimelineInset}
- liveFollowEnabled={!paintOnlyDisplayedTimeline && timelineLiveFollowEnabled}
+ liveFollowEnabled={timelineLiveFollowEnabled}
onIsAtEndChange={onIsAtEndChangeStable}
onContentOverflowChange={setTimelineOverflows}
onToolOutputCollapsedAtEnd={onToolOutputCollapsedAtEndStable}
@@ -3377,7 +3302,7 @@ export default function ChatView(props: ChatViewProps) {
hideEmptyPlaceholder={isDraftHeroState || threadDetailLoading}
emptyPlaceholderInset={composerReservedHeight}
topFadeEnabled={!hasTimelineTopBanner}
- {...(paintOnlyDisplayedTimeline || threadHistoryControls === undefined
+ {...(threadHistoryControls === undefined
? {}
: { historyControls: threadHistoryControls })}
/>
diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx
index e9b21061c47..fbfa67e61bf 100644
--- a/apps/web/src/components/chat/MessagesTimeline.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.tsx
@@ -231,7 +231,6 @@ interface MessagesTimelineProps {
turnDiffSummaries: ReadonlyArray<TurnDiffSummary>;
routeThreadKey: string;
displayThreadKey?: string;
- paintOnly?: boolean;
/** Off where another region already speaks the thread's status, like a subagent's bar. */
announceTurnStatus?: boolean;
onOpenTurnDiff?: (runId: RunId, filePath?: string) => void;
@@ -339,7 +338,6 @@ const ConversationTimeline = memo(function ConversationTimeline({
turnDiffSummaries,
routeThreadKey,
displayThreadKey,
- paintOnly = false,
announceTurnStatus = true,
onOpenTurnDiff,
onOpenThread,
@@ -906,7 +904,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
if (restoringThreadPosition || state?.data !== rows) return;
const isAtEnd = resolveTimelineIsAtEnd(state);
const position = state.data.length ? resolveWorkGroupScrollAnchor(state) : undefined;
- if (position && isAtEnd !== undefined && !paintOnly) {
+ if (position && isAtEnd !== undefined) {
const index = state.indexByKey(position.rowId);
const row = index === undefined ? undefined : state.elementAtIndex(index);
const element = listRef.current?.getScrollableNode();
@@ -1075,7 +1073,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
// starts from a baseline instead of a fresh, silent region.
const activityAnnouncer = (
<ThreadActivityAnnouncer
- threadKey={paintOnly || !announceTurnStatus ? null : listIdentityKey}
+ threadKey={announceTurnStatus ? listIdentityKey : null}
status={awaitingUser ?? (isWorking ? "working" : "idle")}
requestId={awaitingRequestId}
runId={announcedRun?.runId ?? null}
diff --git a/apps/web/src/components/chat/ThreadTimeline.tsx b/apps/web/src/components/chat/ThreadTimeline.tsx
index be34a93162e..6a9d372e951 100644
--- a/apps/web/src/components/chat/ThreadTimeline.tsx
+++ b/apps/web/src/components/chat/ThreadTimeline.tsx
@@ -23,8 +23,6 @@ export function ThreadTimeline({
activeThreadKey,
syncing,
detailLoading,
- readyMarkdownCwd,
- readyWorkspaceRoot,
...timelineProps
}: Omit<ComponentProps<typeof MessagesTimeline>, "timelineEntries"> & {
/** Null until the thread's detail may load; see resolveThreadDetailRef. */
@@ -35,8 +33,6 @@ export function ThreadTimeline({
activeThreadKey: string | null;
syncing: boolean;
detailLoading: boolean;
- readyMarkdownCwd: string | null;
- readyWorkspaceRoot: string | null;
}) {
const visibleTurnItems = useThreadVisibleTurnItems(threadDetailRef);
const serverEntries = useIncrementalTimelineEntries(activeThreadKey, {
@@ -44,7 +40,7 @@ export function ThreadTimeline({
visibleTurnItems,
});
const entries = draftEntries ?? serverEntries;
- const displayed = resolveThreadSwitchTimeline({
+ const displayedEntries = resolveThreadSwitchTimeline({
loading: entries.length === 0 && syncing,
activeThreadKey,
nextEntries: entries,
@@ -54,12 +50,7 @@ export function ThreadTimeline({
if (detailLoading || entries.length === 0 || timelineHasEphemeralPreviewUrls(entries)) {
return;
}
- rememberReadyThreadTimeline({
- threadKey: activeThreadKey,
- entries,
- markdownCwd: readyMarkdownCwd,
- workspaceRoot: readyWorkspaceRoot,
- });
- }, [activeThreadKey, detailLoading, entries, readyMarkdownCwd, readyWorkspaceRoot]);
- return <MessagesTimeline {...timelineProps} timelineEntries={displayed.entries} />;
+ rememberReadyThreadTimeline({ threadKey: activeThreadKey, entries });
+ }, [activeThreadKey, detailLoading, entries]);
+ return <MessagesTimeline {...timelineProps} timelineEntries={displayedEntries} />;
}
diff --git a/apps/web/src/components/chat/useTimelineRewind.ts b/apps/web/src/components/chat/useTimelineRewind.ts
index 6c7aef0a756..b222fc55ec4 100644
--- a/apps/web/src/components/chat/useTimelineRewind.ts
+++ b/apps/web/src/components/chat/useTimelineRewind.ts
@@ -41,7 +41,6 @@ interface TimelineRewindInput {
readonly serverProjection: ThreadStructure | null;
readonly activeThread: EnvironmentThreadShell | undefined;
readonly timelineMessages: ReadonlyArray<ChatMessage>;
- readonly paintOnlyDisplayedTimeline: boolean;
readonly phase: SessionPhase;
readonly isConnecting: boolean;
readonly isSendBusy: boolean;
@@ -68,7 +67,6 @@ export function useTimelineRewind(input: TimelineRewindInput) {
serverProjection,
activeThread,
timelineMessages,
- paintOnlyDisplayedTimeline,
phase,
isConnecting,
isSendBusy,
@@ -270,7 +268,7 @@ export function useTimelineRewind(input: TimelineRewindInput) {
readonly checkpointId: string;
readonly scopeId: string;
}) => {
- if (!paintOnlyDisplayedTimeline) void onRollbackCheckpoint(input);
+ void onRollbackCheckpoint(input);
};
const onTimelineRollbackCheckpointStable = useStableCallback(onTimelineRollbackCheckpoint);
const onRevertTimelineTurn = (targetTurnCount: number, messageId: MessageId) => {