TypeScript
fix(web): compaction row says "Compacting for 12s" instead of "after being idle" (#26299)
Theo Browne3ef16100796c
diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.tsindex 0961ccc2380..6582b8a55d9 100644--- a/apps/mobile/src/lib/threadActivity.test.ts+++ b/apps/mobile/src/lib/threadActivity.test.ts@@ -280,7 +280,7 @@ it("binds a persisted resume answer only to the next compaction in its run", ()expect(compactRows).toHaveLength(2);expect(labels.get(compactRows[0]!.id)).toEqual({title: "Context compacted after 2h 10m idle",- compacting: "Compacting after 2h 10m idle…",+ compacting: "Compacting…",});expect(labels.get(compactRows[1]!.id)).toBeUndefined();}diff --git a/apps/mobile/src/lib/threadActivity.ts b/apps/mobile/src/lib/threadActivity.tsindex 1175cdde025..03ea87da796 100644--- a/apps/mobile/src/lib/threadActivity.ts+++ b/apps/mobile/src/lib/threadActivity.ts@@ -359,7 +359,7 @@ export function threadFeedCompactionLabels(feed: ReadonlyArray<ThreadFeedEntry>)? undefined: {title: `Context compacted after ${age} idle`,- compacting: `Compacting after ${age} idle…`,+ compacting: "Compacting…",});if (labels) labelsByEntryId.set(entry.id, labels);pendingResumeAgeByRunId.delete(entry.runId);diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts b/apps/web/src/components/chat/MessagesTimeline.logic.test.tsindex cc4b386f17e..a3ed14223d8 100644--- a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts+++ b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts@@ -472,11 +472,7 @@ describe("deriveMessagesTimelineRows", () => {},"Context automatically compacted before cache expiry",],- [- "onReturn",- { kind: "working", compacting: "Compacting after being idle…" },- "Context compacted after being idle",- ],+ ["onReturn", { kind: "working", compacting: true }, "Context compacted before sending"],[undefined, { kind: "context-compaction", active: true }, undefined],] as const) {const prompt = compactPrompt(reason);@@ -629,9 +625,17 @@ describe("deriveMessagesTimelineRows", () => {},};const assistantItem = liveAssistant.item;+ // The answer can come long after the turn starts; the row times the compaction itself.+ const compactionStartedAt = DateTime.makeUnsafe(fixture.time(65));const compactionAt = (status: "running" | "completed") => ({...liveAssistant,- item: { ...assistantItem, type: "compaction" as const, status, driver: null },+ item: {+ ...assistantItem,+ type: "compaction" as const,+ status,+ driver: null,+ startedAt: compactionStartedAt,+ },});const rowsFor = (status: "running" | "completed", laterCompaction = false) =>deriveMessagesTimelineRows({@@ -668,7 +672,7 @@ describe("deriveMessagesTimelineRows", () => {return rows.slice(rows.findIndex((row) => row.id.includes("live-user")) + 1);};expect(liveRows("running")).toMatchObject([- { kind: "working", compacting: "Compacting after 1h 5m idle…" },+ { kind: "working", compacting: true, createdAt: DateTime.formatIso(compactionStartedAt) },]);expect(liveRows("completed")).toMatchObject([{ kind: "context-compaction", title: "Context compacted after 1h 5m idle" },diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.tsindex 965a6a1218c..fe38e16bb78 100644--- a/apps/web/src/components/chat/MessagesTimeline.logic.ts+++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts@@ -527,7 +527,7 @@ type MessagesTimelineRowContent =id: string;createdAt: string | null;/** A running compaction owns the working row, so its divider appears only once it ends. */- compacting?: string;+ compacting?: true;}| {kind: "thinking";@@ -1569,28 +1569,28 @@ export function deriveMessagesTimelineRows(input: {activeRunIsCompaction && !compactionRunFinished ? unsettledRunId : null;// Compacting on return holds back the message the user just sent, so the working row says why// it is waiting. Any other compaction shows only its live divider, never both.- const activeCompactionRunId =- runningCompactionRunId !== null && compactionRuns.get(runningCompactionRunId) === "onReturn"- ? runningCompactionRunId- : activeCompactionEntry?.entry.runId != null &&- resumeCompactionAgeByEntryId.has(activeCompactionEntry.id)- ? activeCompactionEntry.entry.runId- : null;- const compactingLabel = (() => {- if (activeCompactionRunId === null) return undefined;- const age = activeCompactionEntry- ? resumeCompactionAgeByEntryId.get(activeCompactionEntry.id)+ const compactsOnReturn =+ runningCompactionRunId !== null && compactionRuns.get(runningCompactionRunId) === "onReturn";+ // The question is answered mid-turn, so the row times this compaction, not the turn.+ const resumeCompactionEntry =+ activeCompactionEntry?.entry.runId != null &&+ resumeCompactionAgeByEntryId.has(activeCompactionEntry.id)+ ? activeCompactionEntry: undefined;- return age ? `Compacting after ${age} idle…` : IDLE_COMPACTING_LABELS.onReturn;- })();+ const activeCompactionRunId = compactsOnReturn+ ? runningCompactionRunId+ : (resumeCompactionEntry?.entry.runId ?? null);const appendWorkingRow = () => {if (compactionOnlyRunFinished) return;if (runningCompactionRunId !== null && activeCompactionRunId === null) return;nextRows.push({kind: "working",id: "working-indicator-row",- createdAt: input.activeTurnStartedAt ?? null,- ...(compactingLabel ? { compacting: compactingLabel } : {}),+ createdAt:+ (compactsOnReturn ? undefined : resumeCompactionEntry?.entry.createdAt) ??+ input.activeTurnStartedAt ??+ null,+ ...(activeCompactionRunId !== null ? { compacting: true as const } : {}),});};let hasActivityRow = false;diff --git a/apps/web/src/components/chat/TimelineWorkGroupRows.tsx b/apps/web/src/components/chat/TimelineWorkGroupRows.tsxindex 1cbb5b818c0..22d17e5e748 100644--- a/apps/web/src/components/chat/TimelineWorkGroupRows.tsx+++ b/apps/web/src/components/chat/TimelineWorkGroupRows.tsx@@ -271,12 +271,12 @@ const workEntryKey = (entry: TimelineWorkEntry) => entry.id;export function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "working" }> }) {const { isCompacting, isPreparingWorktree, backgroundWorktreeSetup } =use(TimelineRowActivityCtx);- const compacting = row.compacting ?? (isCompacting ? "Compacting…" : undefined);- const shimmer = isPreparingWorktree || compacting !== undefined;+ const compacting = row.compacting === true || isCompacting;+ const shimmer = isPreparingWorktree || compacting;const label = isPreparingWorktree ? ("Setting up worktree…"- ) : compacting !== undefined ? (- <CompactingLabel label={compacting} />+ ) : compacting ? (+ <CompactingLabel createdAt={row.createdAt} />) : row.createdAt ? (<>Working for <WorkingTimer createdAt={row.createdAt} />@@ -336,11 +336,17 @@ function BackgroundWorktreeSetupChip({ snapshot }: { snapshot: WorktreeSetupSnap);}-function CompactingLabel({ label }: { label: string }) {+function CompactingLabel({ createdAt }: { createdAt: string | null }) {return (<span className="inline-flex items-center gap-1.5"><Minimize2Icon aria-hidden="true" className="size-3" />- {label}+ {createdAt ? (+ <span>+ Compacting for <WorkingTimer createdAt={createdAt} />+ </span>+ ) : (+ "Compacting…"+ )}</span>);}diff --git a/packages/client-runtime/src/userMessage.ts b/packages/client-runtime/src/userMessage.tsindex 99e9841faaa..d5d7c5ac089 100644--- a/packages/client-runtime/src/userMessage.ts+++ b/packages/client-runtime/src/userMessage.ts@@ -9,13 +9,13 @@ import {/** The working row while T3 Code's own compaction runs. */export const IDLE_COMPACTING_LABELS = {beforeCacheExpires: "Compacting before the cache expires…",- onReturn: "Compacting after being idle…",+ onReturn: "Compacting…",} satisfies Record<OrchestrationV2IdleCompaction, string>;/** Leads the finished compaction's token counts, in place of "Context compacted". */export const IDLE_COMPACTION_TITLES = {beforeCacheExpires: "Context automatically compacted before cache expiry",- onReturn: "Context compacted after being idle",+ onReturn: "Context compacted before sending",} satisfies Record<OrchestrationV2IdleCompaction, string>;const LEGACY_AUTOMATION_PREFIX = /^\[Triggered by schedule task: [^\r\n]+\]\r?\n\r?\n/;