Skip to content

Commit c8a606c

Browse files
authored
fix(shared): durations under 10s drop a trailing .0 (#27316)
1 parent 8970a32 commit c8a606c

7 files changed

Lines changed: 30 additions & 33 deletions

File tree

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ describe("buildThreadFeed", () => {
846846
expect(collapsed[1]).toMatchObject({
847847
type: "run-fold",
848848
createdAt: "2026-06-20T00:00:01.500Z",
849-
label: "Worked for 2.0s",
849+
label: "Worked for 2s",
850850
});
851851

852852
const expanded = deriveThreadFeedPresentation(feed, latestRun, new Set([runId]));
@@ -1100,10 +1100,10 @@ describe("buildThreadFeed", () => {
11001100
const settled = deriveThreadFeedPresentation(feed(false), null, new Set());
11011101
expect(shape(settled)).toEqual([
11021102
"user:launch",
1103-
"fold:Worked for 8.0s",
1103+
"fold:Worked for 8s",
11041104
"assistant:launch-answer",
11051105
"user:resume",
1106-
"fold:Worked for 8.0s",
1106+
"fold:Worked for 8s",
11071107
"assistant:resume-answer",
11081108
]);
11091109
const launchFold = settled.find((entry) => entry.type === "run-fold");
@@ -1112,11 +1112,11 @@ describe("buildThreadFeed", () => {
11121112
shape(deriveThreadFeedPresentation(feed(false), null, new Set([launchFold.runId]))),
11131113
).toEqual([
11141114
"user:launch",
1115-
"fold:Worked for 8.0s",
1115+
"fold:Worked for 8s",
11161116
"activity-group",
11171117
"assistant:launch-answer",
11181118
"user:resume",
1119-
"fold:Worked for 8.0s",
1119+
"fold:Worked for 8s",
11201120
"assistant:resume-answer",
11211121
]);
11221122

@@ -1133,7 +1133,7 @@ describe("buildThreadFeed", () => {
11331133
),
11341134
).toEqual([
11351135
"user:launch",
1136-
"fold:Worked for 8.0s",
1136+
"fold:Worked for 8s",
11371137
"assistant:launch-answer",
11381138
"user:resume",
11391139
"activity-group",

‎apps/server/src/cli/trace.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function makeTraceSpanSummary(sinceMs = -Infinity) {
100100
}
101101

102102
const formatMs = (ms: number) =>
103-
ms < 1_000 ? `${Math.round(ms)}ms` : `${(ms / 1_000).toFixed(1)}s`;
103+
ms < 1_000 ? `${Math.round(ms)}ms` : `${Math.round(ms / 100) / 10}s`;
104104

105105
function formatTraceSummary(
106106
summary: ReturnType<ReturnType<typeof makeTraceSpanSummary>["finish"]>,
@@ -127,7 +127,7 @@ function formatTraceSummary(
127127
const widths = header.map((_, column) => Math.max(...table.map((row) => row[column]!.length)));
128128
const formatIso = (ms: number) => DateTime.formatIso(DateTime.makeUnsafe(ms));
129129
return [
130-
`${summary.spanCount} spans ended from ${formatIso(summary.firstEndMs)} to ${formatIso(summary.lastEndMs)} (${summary.minutes.toFixed(1)} min).`,
130+
`${summary.spanCount} spans ended from ${formatIso(summary.firstEndMs)} to ${formatIso(summary.lastEndMs)} (${summary.minutes.toFixed(1).replace(/\.0+$/, "")} min).`,
131131
...(summary.skippedLineCount > 0
132132
? [`Skipped ${summary.skippedLineCount} lines that are not spans.`]
133133
: []),

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,10 +1841,10 @@ describe("deriveMessagesTimelineRows", () => {
18411841
const settled = rows({ resume: "completed", working: false });
18421842
expect(shape(settled)).toEqual([
18431843
"user:launch",
1844-
"fold:Worked for 8.0s",
1844+
"fold:Worked for 8s",
18451845
"assistant:launch-answer",
18461846
"user:resume",
1847-
"fold:Worked for 8.0s",
1847+
"fold:Worked for 8s",
18481848
"assistant:resume-answer",
18491849
]);
18501850

@@ -1857,17 +1857,17 @@ describe("deriveMessagesTimelineRows", () => {
18571857
});
18581858
expect(shape(expanded)).toEqual([
18591859
"user:launch",
1860-
"fold:Worked for 8.0s",
1860+
"fold:Worked for 8s",
18611861
"work-toggle",
18621862
"assistant:launch-answer",
18631863
"user:resume",
1864-
"fold:Worked for 8.0s",
1864+
"fold:Worked for 8s",
18651865
"assistant:resume-answer",
18661866
]);
18671867

18681868
expect(shape(rows({ resume: "running", working: true }))).toEqual([
18691869
"user:launch",
1870-
"fold:Worked for 8.0s",
1870+
"fold:Worked for 8s",
18711871
"assistant:launch-answer",
18721872
"user:resume",
18731873
"working",
@@ -1876,7 +1876,7 @@ describe("deriveMessagesTimelineRows", () => {
18761876

18771877
expect(shape(rows({ resume: "failed", working: false }))).toEqual([
18781878
"user:launch",
1879-
"fold:Worked for 8.0s",
1879+
"fold:Worked for 8s",
18801880
"assistant:launch-answer",
18811881
"user:resume",
18821882
"work",

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ it("ticks the running stage while finished stages keep their duration", async ()
5353
// Assert synchronously: expect.element polls on timers these tests fake.
5454
const section = screen.getByRole("region", { name: "Worktree setup" });
5555

56-
expect(section.element().textContent).toContain("Fetch base branch3.0s");
57-
expect(section.element().textContent).toContain("Check out files7.0s");
56+
expect(section.element().textContent).toContain("Fetch base branch3s");
57+
expect(section.element().textContent).toContain("Check out files7s");
5858

5959
await act(async () => {
6060
await vi.advanceTimersByTimeAsync(5_000);
6161
});
62-
expect(section.element().textContent).toContain("Fetch base branch3.0s");
62+
expect(section.element().textContent).toContain("Fetch base branch3s");
6363
expect(section.element().textContent).toContain("Check out files12s");
6464
});
6565

@@ -70,9 +70,9 @@ it("stops a stage interrupted by the setup ending at the setup's end", async ()
7070
await using screen = await render(card(failed));
7171
const section = screen.getByRole("region", { name: "Worktree setup" });
7272

73-
expect(section.element().textContent).toContain("Check out files2.0s");
73+
expect(section.element().textContent).toContain("Check out files2s");
7474
await act(async () => {
7575
await vi.advanceTimersByTimeAsync(5_000);
7676
});
77-
expect(section.element().textContent).toContain("Check out files2.0s");
77+
expect(section.element().textContent).toContain("Check out files2s");
7878
});

‎apps/web/src/components/settings/DiagnosticsSettings.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function formatCount(value: number): string {
4848

4949
function formatDuration(value: number): string {
5050
if (value < 1_000) return `${Math.round(value)} ms`;
51-
return `${(value / 1_000).toFixed(value >= 10_000 ? 1 : 2)} s`;
51+
return `${(value / 1_000).toFixed(value >= 10_000 ? 1 : 2).replace(/\.0+$/, "")} s`;
5252
}
5353

5454
function formatBytes(value: number): string {
@@ -438,10 +438,10 @@ const RESOURCE_HISTORY_WINDOWS = [
438438
] as const;
439439

440440
function formatCpuTime(seconds: number): string {
441-
if (seconds < 60) return `${seconds.toFixed(seconds >= 10 ? 1 : 2)}s`;
441+
if (seconds < 60) return `${seconds.toFixed(seconds >= 10 ? 1 : 2).replace(/\.0+$/, "")}s`;
442442
const minutes = seconds / 60;
443-
if (minutes < 60) return `${minutes.toFixed(minutes >= 10 ? 1 : 2)}m`;
444-
return `${(minutes / 60).toFixed(2)}h`;
443+
if (minutes < 60) return `${minutes.toFixed(minutes >= 10 ? 1 : 2).replace(/\.0+$/, "")}m`;
444+
return `${(minutes / 60).toFixed(2).replace(/\.0+$/, "")}h`;
445445
}
446446

447447
function formatShortProcessName(command: string): string {

‎apps/web/src/components/settings/ResourceTelemetryDiagnostics.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ function formatRate(value: number): string {
7474

7575
function formatCpuTime(valueMs: number): string {
7676
const seconds = valueMs / 1_000;
77-
if (seconds < 60) return `${seconds.toFixed(seconds >= 10 ? 1 : 2)}s`;
77+
if (seconds < 60) return `${seconds.toFixed(seconds >= 10 ? 1 : 2).replace(/\.0+$/, "")}s`;
7878
const minutes = seconds / 60;
79-
if (minutes < 60) return `${minutes.toFixed(minutes >= 10 ? 1 : 2)}m`;
80-
return `${(minutes / 60).toFixed(2)}h`;
79+
if (minutes < 60) return `${minutes.toFixed(minutes >= 10 ? 1 : 2).replace(/\.0+$/, "")}m`;
80+
return `${(minutes / 60).toFixed(2).replace(/\.0+$/, "")}h`;
8181
}
8282

8383
function formatDurationMicros(value: number): string {
8484
if (value < 1_000) return `${Math.round(value)} µs`;
85-
if (value < 1_000_000) return `${(value / 1_000).toFixed(2)} ms`;
86-
return `${(value / 1_000_000).toFixed(2)} s`;
85+
if (value < 1_000_000) return `${(value / 1_000).toFixed(2).replace(/\.0+$/, "")} ms`;
86+
return `${(value / 1_000_000).toFixed(2).replace(/\.0+$/, "")} s`;
8787
}
8888

8989
function formatSampleInterval(valueMs: number): string {
@@ -788,7 +788,7 @@ function AttributionTable({ entries }: { entries: ReadonlyArray<ResourceAttribut
788788
</td>
789789
<td className="px-3 py-2 text-right font-mono tabular-nums">{entry.count}</td>
790790
<td className="px-3 py-2 text-right font-mono tabular-nums text-muted-foreground sm:pr-5">
791-
{(entry.durationMs / 1_000).toFixed(2)}s
791+
{(entry.durationMs / 1_000).toFixed(2).replace(/\.0+$/, "")}s
792792
</td>
793793
</tr>
794794
))}

‎packages/shared/src/orchestrationTiming.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ export function deriveSubagentElapsedMs(
2222
export function formatDuration(durationMs: number): string {
2323
if (!Number.isFinite(durationMs) || durationMs < 0) return "0ms";
2424
if (durationMs < 1_000) return `${Math.max(1, Math.round(durationMs))}ms`;
25-
if (durationMs < 10_000) {
26-
const tenths = Math.round(durationMs / 100) / 10;
27-
return tenths >= 10 ? "10s" : `${tenths.toFixed(1)}s`;
28-
}
25+
if (durationMs < 10_000) return `${Math.round(durationMs / 100) / 10}s`;
2926
const totalSeconds = Math.round(durationMs / 1_000);
3027
// Choose the unit after rounding so 59.5 seconds never renders as "60s".
3128
if (totalSeconds < 60) return `${totalSeconds}s`;

0 commit comments

Comments
 (0)