Skip to content

Commit 0c2d7ec

Browse files
fix(web): show compaction elapsed time and slow warning in the timeline row
The standard timeline renders compaction work entries through ContextCompactionTimelineRow; the timer added to V2LifecycleRow never ran because compaction items are not standalone event rows. Carry the item's startedAt on the row, render the elapsed clock (120s warning) outside the shimmer overlay while active, and let long labels wrap.
1 parent 833f0fc commit 0c2d7ec

5 files changed

Lines changed: 109 additions & 29 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.browser.test.tsx‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ThreadId,
99
} from "@t3tools/contracts";
1010
import type { LegendListRef } from "@legendapp/list/react";
11+
import * as DateTime from "effect/DateTime";
1112
import { act, createRef, Profiler, useState, type ComponentProps, type ReactElement } from "react";
1213
import { createRoot, type Root } from "react-dom/client";
1314
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
@@ -319,6 +320,77 @@ describe("MessagesTimeline work rows", () => {
319320
expect(text()).toContain("Context compacted");
320321
});
321322

323+
it("ticks a running compaction and warns once it passes two minutes", async () => {
324+
const compaction = (
325+
id: string,
326+
status: string,
327+
label: string,
328+
fields: Record<string, unknown> = {},
329+
) =>
330+
work(id, {
331+
runId: "run-1",
332+
label,
333+
tone: "info",
334+
itemType: "compaction",
335+
sourceActivityKind: "context-compaction",
336+
toolLifecycleStatus: status === "running" ? "inProgress" : status,
337+
structuredPayload: {
338+
id,
339+
type: "compaction",
340+
status,
341+
startedAt: DateTime.makeUnsafe(Date.now() - 118_000),
342+
...fields,
343+
},
344+
});
345+
await renderTimeline(
346+
[
347+
compaction("compaction-done", "completed", "Context compacted", {
348+
beforeTokenCount: 180_000,
349+
afterTokenCount: 40_000,
350+
}),
351+
compaction("compaction-failed", "failed", "Context compaction failed", {
352+
beforeTokenCount: 180_000,
353+
afterTokenCount: 180_000,
354+
}),
355+
compaction("compaction-stopped", "interrupted", "Context compaction stopped"),
356+
compaction("compaction-running", "running", "Compacting context"),
357+
],
358+
{
359+
isWorking: true,
360+
activeTurnInProgress: true,
361+
latestRun: {
362+
runId: RunId.make("run-1"),
363+
status: "running",
364+
startedAt: CREATED_AT,
365+
completedAt: null,
366+
},
367+
},
368+
);
369+
const separator = (label: string) =>
370+
container.querySelector<HTMLElement>(`[role="separator"][aria-label="${label}"]`)!;
371+
await vi.waitFor(() => expect(separator("Compacting context")).not.toBeNull());
372+
373+
const running = separator("Compacting context");
374+
const timers = running.querySelectorAll(".tabular-nums");
375+
expect(timers).toHaveLength(1);
376+
expect(timers[0]!.closest("[aria-hidden]")).toBeNull();
377+
expect(timers[0]!.textContent).toBe("1m");
378+
expect(running.textContent).not.toContain("taking longer than expected");
379+
await vi.waitFor(() => expect(running.textContent).toContain("taking longer than expected"), {
380+
timeout: 5_000,
381+
});
382+
expect(running.textContent).toContain("2m");
383+
384+
for (const label of ["Context compaction failed", "Context compaction stopped"]) {
385+
const row = separator(label);
386+
expect(row.textContent).toBe(label);
387+
expect(row.querySelector(".tabular-nums")).toBeNull();
388+
}
389+
const done = separator("Context compacted");
390+
expect(done.textContent).toMatch(/^Context compacted 180K.*40K tokens$/);
391+
expect(done.querySelector(".tabular-nums")).toBeNull();
392+
});
393+
322394
it("formats changed file paths from the workspace root", async () => {
323395
await renderTimeline(
324396
[

‎apps/web/src/components/chat/MessagesTimeline.logic.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,7 @@ describe("deriveMessagesTimelineRows", () => {
10941094
kind: "context-compaction",
10951095
id: "compaction-entry",
10961096
createdAt: "2026-01-01T00:00:00Z",
1097+
startedAt: "2026-01-01T00:00:00Z",
10971098
label: "Compacted context 899K → 19K tokens",
10981099
tokenCounts: null,
10991100
active: false,

‎apps/web/src/components/chat/MessagesTimeline.logic.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ type MessagesTimelineRowContent =
554554
kind: "context-compaction";
555555
id: string;
556556
createdAt: string;
557+
startedAt: string;
557558
label: string;
558559
tokenCounts: ReturnType<typeof contextCompactionTokenCounts>;
559560
active: boolean;
@@ -1572,6 +1573,10 @@ export function deriveMessagesTimelineRows(input: {
15721573
kind: "context-compaction",
15731574
id: timelineEntry.id,
15741575
createdAt: timelineEntry.createdAt,
1576+
startedAt:
1577+
compaction?.type === "compaction" && compaction.startedAt !== null
1578+
? DateTime.formatIso(compaction.startedAt)
1579+
: timelineEntry.createdAt,
15751580
label: timelineEntry.entry.label,
15761581
tokenCounts:
15771582
compaction?.type === "compaction" ? contextCompactionTokenCounts(compaction) : null,
@@ -2170,7 +2175,12 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
21702175

21712176
case "context-compaction": {
21722177
const bc = b as typeof a;
2173-
return a.createdAt === bc.createdAt && a.label === bc.label && a.active === bc.active;
2178+
return (
2179+
a.createdAt === bc.createdAt &&
2180+
a.startedAt === bc.startedAt &&
2181+
a.label === bc.label &&
2182+
a.active === bc.active
2183+
);
21742184
}
21752185

21762186
case "proposed-plan":

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ import {
298298
V2LifecycleRow,
299299
type HandoffTimelineRun,
300300
} from "./V2LifecycleRow";
301+
import { AgentElapsed } from "./AgentElapsed";
301302
import { SecretRequestCard } from "./SecretRequestCard";
302303
import { TimelineSystemDivider } from "./TimelineSystemDivider";
303304
import { WorkflowOpeningBlock } from "./WorkflowOpeningBlock";
@@ -2039,15 +2040,25 @@ function ContextCompactionTimelineRow({
20392040
aria-label={row.label}
20402041
className="mx-auto flex w-full max-w-(--chat-content-max-width) items-center gap-3 py-1 text-muted-foreground text-xs"
20412042
>
2042-
<span className="h-px flex-1 bg-border/70" />
2043-
<span
2044-
ref={row.active ? observeVisibleAnimation : undefined}
2045-
className="relative shrink-0 overflow-hidden"
2046-
>
2047-
{content}
2048-
{row.active ? <ActivityShimmerOverlay>{content}</ActivityShimmerOverlay> : null}
2043+
<span className="h-px min-w-4 flex-1 bg-border/70" />
2044+
<span className="flex min-w-0 flex-wrap items-center justify-center gap-x-1.5 gap-y-0.5">
2045+
<span
2046+
ref={row.active ? observeVisibleAnimation : undefined}
2047+
className="relative min-w-0 overflow-hidden"
2048+
>
2049+
{content}
2050+
{row.active ? <ActivityShimmerOverlay>{content}</ActivityShimmerOverlay> : null}
2051+
</span>
2052+
{/* Outside the shimmer so the ticking clock is rendered once. */}
2053+
{row.active ? (
2054+
<AgentElapsed
2055+
agent={{ status: "running", startedAt: row.startedAt, completedAt: null }}
2056+
compact
2057+
warnAfterSeconds={120}
2058+
/>
2059+
) : null}
20492060
</span>
2050-
<span className="h-px flex-1 bg-border/70" />
2061+
<span className="h-px min-w-4 flex-1 bg-border/70" />
20512062
</div>
20522063
);
20532064
}

‎apps/web/src/components/chat/V2LifecycleRow.tsx‎

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,13 @@ export function V2LifecycleRow(props: {
113113
item.beforeTokenCount === undefined && item.afterTokenCount === undefined
114114
? null
115115
: `${item.beforeTokenCount ?? "?"} → ${item.afterTokenCount ?? "?"} tokens`;
116-
const label = contextCompactionStatusLabel(item);
117-
const detail = (
118-
<>
119-
{item.summary ?? tokenDetail}
120-
{item.status === "running" ? (
121-
<>
122-
{(item.summary ?? tokenDetail) ? " · " : null}
123-
<AgentElapsed
124-
agent={{
125-
status: "running",
126-
startedAt: item.startedAt === null ? null : DateTime.formatIso(item.startedAt),
127-
completedAt: null,
128-
}}
129-
compact
130-
warnAfterSeconds={120}
131-
/>
132-
</>
133-
) : null}
134-
</>
116+
return (
117+
<TimelineSystemDivider
118+
label={contextCompactionStatusLabel(item)}
119+
detail={item.summary ?? tokenDetail}
120+
icon={MinusIcon}
121+
/>
135122
);
136-
return <TimelineSystemDivider label={label} detail={detail} icon={MinusIcon} />;
137123
}
138124
if (item.type === "handoff") {
139125
return (

0 commit comments

Comments
 (0)