Skip to content

Commit 3f1c84c

Browse files
authored
fix: tool titles stop after transcript pruning (#133078)
Generated tool titles now continue through long, virtualized transcripts after retention prunes scheduler cursors, while bounded decorative model work remains isolated by session and search-filtered views cannot corrupt cursor progress.
1 parent 00f8d76 commit 3f1c84c

8 files changed

Lines changed: 1367 additions & 119 deletions

File tree

‎ui/src/e2e/tool-titles.e2e.test.ts‎

Lines changed: 602 additions & 0 deletions
Large diffs are not rendered by default.

‎ui/src/pages/chat/chat-history.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ export function retireChatBranchRequests(state: ChatState): void {
198198
getChatHistoryPaneRequests(state).branchVersion += 1;
199199
}
200200

201+
export function getChatHistoryVersion(state: ChatState): number {
202+
return getChatHistoryPaneRequests(state).historyVersion;
203+
}
204+
201205
type ChatHistoryRequestOwnership = {
202206
version: number;
203207
client: GatewayBrowserClient;

‎ui/src/pages/chat/chat-pane-lifecycle.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import {
8787
resolveChatSnapshotKey,
8888
} from "./session-message-cache.ts";
8989
import { closeSlot, isSidebarSlotVisible, openSlot, type SidebarSlotId } from "./sidebar-layout.ts";
90+
import { subscribeToolTitleChanges } from "./tool-titles.ts";
9091

9192
const COMPOSER_PREFILL_ATTENTION_DURATION_MS = 600;
9293
const COMPOSER_PREFILL_ATTENTION_CLASS = "agent-chat__input--prefill-attention";
@@ -297,14 +298,11 @@ export abstract class ChatPaneLifecycle extends ChatPaneSessionCreation {
297298
});
298299
}
299300

300-
protected readonly handlePaneFocus = () => {
301-
this.onFocusPane?.(this.paneId);
302-
};
301+
protected readonly handlePaneFocus = () => this.onFocusPane?.(this.paneId);
303302

304303
/** Receives one complete browser annotation without mixing generated context into the user's draft. */
305304
protected receiveBrowserAnnotation(event: Event): void {
306-
const accepted = admitBrowserAnnotation(this.state, this.active && this.presented, event);
307-
if (!accepted) {
305+
if (!admitBrowserAnnotation(this.state, this.active && this.presented, event)) {
308306
return;
309307
}
310308
// A null mount binds only when its first annotation ownership begins.
@@ -437,6 +435,7 @@ export abstract class ChatPaneLifecycle extends ChatPaneSessionCreation {
437435
document.addEventListener("keydown", this.handleDocumentKeydown, true);
438436
document.addEventListener("pointerdown", this.handleDocumentPointerdown, true);
439437
const chatState = this.chatState;
438+
chatState.addCleanup(subscribeToolTitleChanges(() => this.state?.requestUpdate?.()));
440439
chatState.addCleanup(() => {
441440
document.removeEventListener("keydown", this.handleDocumentKeydown, true);
442441
document.removeEventListener("pointerdown", this.handleDocumentPointerdown, true);

‎ui/src/pages/chat/chat-pane-render.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { buildAgentMainSessionKey } from "../../lib/sessions/session-key.ts";
2929
import { showToast } from "../../lib/toast.ts";
3030
import { generateUUID } from "../../lib/uuid.ts";
3131
import { mutateChatGoal, submitChatGoalDraft } from "./chat-goals.ts";
32-
import { clearChatHistory } from "./chat-history.ts";
32+
import { clearChatHistory, getChatHistoryVersion } from "./chat-history.ts";
3333
import { resolveChatMessageAccess } from "./chat-message-access.ts";
3434
import { requiresChatModelSetup } from "./chat-model-setup.ts";
3535
import { ChatPaneLayoutRender } from "./chat-pane-layout-render.ts";
@@ -151,7 +151,9 @@ export class ChatPane extends ChatPaneLayoutRender {
151151
client: state.connected ? state.client : null,
152152
sessionKey: catalogKey ? null : state.sessionKey || null,
153153
agentId: currentAgentId || null,
154-
onTitlesChanged: () => state.requestUpdate?.(),
154+
schedulingEnabled: this.active && this.presented,
155+
historyOwner: state,
156+
historyVersion: getChatHistoryVersion(state),
155157
});
156158
const selectedAgent = this.context.agents.state.agentsList?.agents.find(
157159
(agent) => agent.id === currentAgentId,

‎ui/src/pages/chat/chat-thread.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,19 @@ export function getExpandedUserMessages(sessionKey: string): Map<string, boolean
387387
return getOrCreateSessionCacheValue(expandedUserMessagesBySession, sessionKey, () => new Map());
388388
}
389389

390+
export function collectToolTitleCandidates(items: readonly (ChatItem | MessageGroup)[]) {
391+
return items.flatMap((item) =>
392+
item.kind === "group"
393+
? item.messages.flatMap((entry) =>
394+
extractToolCardsCached(entry.message, entry.key).map(({ args, name }) => ({
395+
args,
396+
name,
397+
})),
398+
)
399+
: [],
400+
);
401+
}
402+
390403
export type AssistantMessageExpansionState =
391404
| { status: "loading"; revision: number }
392405
| { status: "error"; revision: number }

‎ui/src/pages/chat/components/chat-transcript-projection.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
agentRunFrameGroups,
2020
assistantMessageExpansionSignature,
2121
buildCachedChatItems,
22+
collectToolTitleCandidates,
2223
coalesceAgentRunFrames,
2324
coalesceActivityRuns,
2425
coalesceStreamRuns,
@@ -31,7 +32,7 @@ import {
3132
setExpansionState,
3233
syncToolCardExpansionState,
3334
} from "../chat-thread.ts";
34-
import { getToolTitlesVersion } from "../tool-titles.ts";
35+
import { getToolTitlesVersion, scheduleToolTitlesForTranscript } from "../tool-titles.ts";
3536
import { renderAgentRunFrame } from "./chat-agent-run-frame.ts";
3637
import { renderBackgroundTasksStatusRow } from "./chat-background-tasks-status.ts";
3738
import { renderChatDivider, renderChatNotice } from "./chat-divider.ts";
@@ -176,6 +177,9 @@ export function projectChatTranscript(
176177
searchOpen: state.searchOpen,
177178
searchQuery: state.searchQuery,
178179
});
180+
if (props.showToolCalls && !searchFiltering) {
181+
scheduleToolTitlesForTranscript(collectToolTitleCandidates(chatItems));
182+
}
179183
const latestBrowserTabs =
180184
props.browserTabPreviewsActive === false
181185
? latestBrowserTabCards([], [])

0 commit comments

Comments
 (0)