Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

Console: a duration that rounds to sixty carries into the next unit (#413)

Jiaqiiii5234d059075e8f7
diff --git a/ui/src/app/(app)/harnesses/page.tsx b/ui/src/app/(app)/harnesses/page.tsx
index d4068aec..8ebf6c47 100644
--- a/ui/src/app/(app)/harnesses/page.tsx
+++ b/ui/src/app/(app)/harnesses/page.tsx
@@ -25,6 +25,7 @@ import { track } from '@/lib/analytics';
import { getCurrentWorkspaceRef } from '@/lib/workspace';
import { useEscape } from '@/lib/useEscape';
import { getConvState, type UserMsg } from '@/lib/conversation';
+import { latencyText } from '@/lib/duration';
type View = 'index' | 'chat' | 'settings';
type TaskState = 'done' | 'running' | 'failed' | 'cancelled' | 'incomplete';
@@ -45,12 +46,6 @@ function taskState(status?: string): TaskState {
/** A harness's loaded tasks: the pages read so far, the cursor for the next, and whether one is in flight. */
interface TaskSlice { list: TraceCard[]; cursor: string; pages: number; loading: boolean }
-/** "4.2s" under a minute, "1m 12s" past it. */
-function fmtLatency(s: number): string {
- if (s < 60) return `${s < 10 ? s.toFixed(1) : Math.round(s)}s`;
- const m = Math.floor(s / 60);
- return `${m}m ${Math.round(s - m * 60)}s`;
-}
/** "Codex · gpt-5.4" for a row, from the same fields the old list read. */
function runtimeOf(r: HarnessRow): { baseId: string; name: string; model: string } {
@@ -332,7 +327,7 @@ export default function HarnessesPage() {
<span className="hx-badges" aria-label="Task totals">
{latency != null && (
<span className="hx-badge" title={`Total latency${latencyPartial ? `, from ${totals!.timed} of ${totals!.finished} turns` : ''}`}>
- <iconify-icon icon="tabler:clock"></iconify-icon>{latencyPartial ? '≥ ' : ''}{fmtLatency(latency)}
+ <iconify-icon icon="tabler:clock"></iconify-icon>{latencyPartial ? '≥ ' : ''}{latencyText(latency)}
</span>
)}
{credits != null && (
diff --git a/ui/src/app/share/[token]/page.tsx b/ui/src/app/share/[token]/page.tsx
index 87523b8f..8ba051de 100644
--- a/ui/src/app/share/[token]/page.tsx
+++ b/ui/src/app/share/[token]/page.tsx
@@ -10,6 +10,7 @@ import { useParams } from 'next/navigation';
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
import { FileTypeIcon } from '@/components/FileTypeIcon';
+import { minutesAndSeconds } from '@/lib/duration';
interface ShareMeta { session_id?: string; title?: string; status?: string; model?: string;
backend?: string; harness_id?: string; harness_name?: string; event_count?: number; elapsed?: number; finished_at?: number }
@@ -19,7 +20,7 @@ interface ShareFile { path: string; bytes?: number; media_type?: string }
function fmtDur(s?: number): string {
if (!s) return '';
- const m = Math.floor(s / 60), sec = Math.round(s % 60);
+ const [m, sec] = minutesAndSeconds(s);
return m ? `${m}m ${String(sec).padStart(2, '0')}s` : `${sec}s`;
}
function fmtBytes(n?: number): string {
diff --git a/ui/src/components/TaskChat.tsx b/ui/src/components/TaskChat.tsx
index 9d072a8b..7a879d0d 100644
--- a/ui/src/components/TaskChat.tsx
+++ b/ui/src/components/TaskChat.tsx
@@ -14,6 +14,7 @@ import { track } from '@/lib/analytics';
import { InsufficientCreditsModal } from '@/components/InsufficientCreditsModal';
import { billing } from '@/app/(app)/billing/lib';
import { statusChip, timeAgo } from '@/lib/revamp-data';
+import { minutesAndSeconds } from '@/lib/duration';
// Shared Conversational Agent surface (UI Core), extracted from this page; see
// frontend-ui-core/README.md for the token/transport/slot contracts.
import { Svg, Chevron, IcPlug, IcSkill } from 'reifyui';
@@ -366,7 +367,7 @@ export function ConfigChat({ oob, ch, harnessId, harnessName, deepSid, onClearDe
}, [shownSid, taskModel]); // eslint-disable-line react-hooks/exhaustive-deps
const fmtDur = (s?: number) => {
if (!s) return '';
- const m = Math.floor(s / 60), sec = Math.round(s % 60);
+ const [m, sec] = minutesAndSeconds(s);
return m ? `${m}m ${sec}s` : `${sec}s`;
};
diff --git a/ui/src/lib/duration.test.ts b/ui/src/lib/duration.test.ts
new file mode 100644
index 00000000..3f50d94a
--- /dev/null
+++ b/ui/src/lib/duration.test.ts
@@ -0,0 +1,47 @@
+import { readFileSync, readdirSync, statSync } from 'node:fs';
+import { join } from 'node:path';
+import { latencyText, minutesAndSeconds, traceDurationText } from '@/lib/duration';
+
+test('sixty seconds that have a minute beside them become one of it', () => {
+ expect(minutesAndSeconds(119.7)).toEqual([2, 0]);
+ expect(minutesAndSeconds(59.7)).toEqual([1, 0]);
+ expect(minutesAndSeconds(90)).toEqual([1, 30]);
+ expect(minutesAndSeconds(12.4)).toEqual([0, 12]);
+});
+
+test('the harness list latency carries at each of its edges', () => {
+ // it read `1m 60s` at 119.7 and `60s` at 59.7, from Math.round(s - m * 60)
+ expect(latencyText(119.7)).toBe('2m 0s');
+ expect(latencyText(59.7)).toBe('1m 0s');
+ expect(latencyText(9.96)).toBe('10s');
+ expect(latencyText(4.24)).toBe('4.2s');
+ expect(latencyText(42.4)).toBe('42s');
+ expect(latencyText(72)).toBe('1m 12s');
+});
+
+test('a trace span duration carries at each of its edges', () => {
+ expect(traceDurationText(0.9996)).toBe('1.0s');
+ expect(traceDurationText(0.42)).toBe('420ms');
+ expect(traceDurationText(59.96)).toBe('1m 0s');
+ expect(traceDurationText(4.24)).toBe('4.2s');
+ expect(traceDurationText(119.6)).toBe('2m 0s');
+});
+
+/** Every file under src, as the rule is repo-wide rather than one module's. */
+function sources(dir: string): string[] {
+ return readdirSync(dir).flatMap((name) => {
+ const path = join(dir, name);
+ if (statSync(path).isDirectory()) return sources(path);
+ return /\.(ts|tsx|js|jsx)$/.test(name) && !name.includes('.test.') ? [path] : [];
+ });
+}
+
+test('no duration in the console rounds its seconds half out of the minute it is in', () => {
+ // `Math.round(s % 60)` can name sixty seconds, and it does not have to sit on the same line as
+ // the `Math.floor(s / 60)` it is paired with to do it; nor does it have to be spelled with `%`
+ // (`Math.round(s - m * 60)` is the same remainder). `minutesAndSeconds` is the one owner.
+ const offenders = sources(join(__dirname, '..'))
+ .filter((file) => !file.endsWith('lib/duration.ts'))
+ .filter((file) => /Math\.round\([^)]*(%\s*60|-\s*\w+\s*\*\s*60)/.test(readFileSync(file, 'utf8')));
+ expect(offenders).toEqual([]);
+});
diff --git a/ui/src/lib/duration.ts b/ui/src/lib/duration.ts
new file mode 100644
index 00000000..288b6f48
--- /dev/null
+++ b/ui/src/lib/duration.ts
@@ -0,0 +1,30 @@
+/** The console's duration rule: sixty of a unit that has a next one is one of that next unit.
+ *
+ * Each place that renders an elapsed time rounds it, and rounding the seconds half on its own let
+ * 119.7 s read as `1m 60s` and 59.7 s as `60s`. The strings the console prints are not one string —
+ * one pads the seconds, one does not, one starts in milliseconds — so only the split is owned here,
+ * and each caller keeps its own rendering. */
+export function minutesAndSeconds(seconds: number): [number, number] {
+ const total = Math.round(seconds);
+ return [Math.floor(total / 60), total % 60];
+}
+
+/** The harness list's latency: "4.2s" under ten seconds, "42s" under a minute, "1m 12s" past it.
+ * A band is chosen on the ROUNDED value, so 9.96 s is "10s", not "10.0s", and 59.7 s is "1m 0s". */
+export function latencyText(s: number): string {
+ const tenths = Math.round(s * 10) / 10;
+ if (tenths < 10) return `${tenths.toFixed(1)}s`;
+ const [m, sec] = minutesAndSeconds(s);
+ return m ? `${m}m ${sec}s` : `${sec}s`;
+}
+
+/** A trace span's duration: "420ms" under a second, "4.2s" under a minute, "1m 12s" past it. The
+ * same carry at each edge: 0.9996 s is "1.0s", not "1000ms", and 59.96 s is "1m 0s", not "60.0s". */
+export function traceDurationText(s: number): string {
+ const ms = Math.round(s * 1000);
+ if (ms < 1000) return `${ms}ms`;
+ const tenths = Math.round(s * 10) / 10;
+ if (tenths < 60) return `${tenths.toFixed(1)}s`;
+ const [m, sec] = minutesAndSeconds(s);
+ return `${m}m ${sec}s`;
+}
diff --git a/ui/src/lib/revamp-data.test.ts b/ui/src/lib/revamp-data.test.ts
new file mode 100644
index 00000000..4621a788
--- /dev/null
+++ b/ui/src/lib/revamp-data.test.ts
@@ -0,0 +1,26 @@
+import { p95Of, timeAgo, type TraceCard } from '@/lib/revamp-data';
+
+// The gateway stamps `elapsed` to one decimal (app.py rounds the turn's seconds), so a value like
+// 119.7 is the normal case rather than a corner: the p95 column read it as "1m 60s".
+const cards = (...elapsed: number[]): TraceCard[] => elapsed.map((e) => ({ session_id: 's', elapsed: e }));
+
+test('a p95 whose seconds round up carries into the minutes', () => {
+ expect(p95Of(cards(5, 9, 119.7))).toBe('2m 00s');
+ expect(p95Of(cards(5, 9, 59.7))).toBe('1m 00s');
+});
+
+test('a p95 that needs no carry reads exactly as it did', () => {
+ expect(p95Of(cards(5, 9, 90))).toBe('1m 30s');
+ expect(p95Of(cards(5, 9, 12.4))).toBe('12s');
+ expect(p95Of(cards(5, 9, 61))).toBe('1m 01s');
+});
+
+test('a minute that rounds to sixty is an hour, and an hour that rounds to twenty-four is a day', () => {
+ const MIN = 60_000, DAY = 86_400_000;
+ expect(timeAgo(Date.now() - 59.5 * MIN)).toBe('1 hr ago');
+ expect(timeAgo(Date.now() - (DAY - 1))).toBe('1d ago');
+ expect(timeAgo(Date.now() - 30 * MIN)).toBe('30 min ago');
+ expect(timeAgo(Date.now() - 90 * MIN)).toBe('2 hr ago');
+ expect(timeAgo(Date.now() - 3 * DAY)).toBe('3d ago');
+ expect(timeAgo(Date.now() - 10_000)).toBe('just now');
+});
diff --git a/ui/src/lib/revamp-data.ts b/ui/src/lib/revamp-data.ts
index 231f5688..6ab83f5b 100644
--- a/ui/src/lib/revamp-data.ts
+++ b/ui/src/lib/revamp-data.ts
@@ -8,6 +8,7 @@ import { harnessFetch } from '@/lib/hfetch';
import { getSession } from '@/lib/auth';
import { OOB, listCustom, type CustomHarness, type OobHarness } from '@/lib/harness';
import { appendWorkspaceQuery } from '@/lib/workspace';
+import { minutesAndSeconds } from '@/lib/duration';
export interface TraceCard {
session_id: string;
@@ -91,7 +92,7 @@ export function p95Of(cards: TraceCard[] | undefined): string | null {
const el = (cards || []).map((c) => c.elapsed || 0).filter((x) => x > 0).sort((a, b) => a - b);
if (el.length < 3) return null;
const v = el[Math.min(el.length - 1, Math.floor(el.length * 0.95))];
- const m = Math.floor(v / 60), s = Math.round(v % 60);
+ const [m, s] = minutesAndSeconds(v);
return m ? `${m}m ${String(s).padStart(2, '0')}s` : `${s}s`;
}
@@ -188,8 +189,16 @@ export function timeAgo(ts: number | null): string {
if (!ts) return '—';
const s = Math.max(0, (Date.now() - ts) / 1000);
if (s < 60) return 'just now';
- if (s < 3600) return `${Math.round(s / 60)} min ago`;
- if (s < 86400) return `${Math.round(s / 3600)} hr ago`;
+ // Each band rounds, so a value can round up out of it: 59.5 minutes printed "60 min ago" and
+ // 23.99 hours printed "24 hr ago". Carrying is what the reader expects of the next band.
+ if (s < 3600) {
+ const m = Math.round(s / 60);
+ return m >= 60 ? '1 hr ago' : `${m} min ago`;
+ }
+ if (s < 86400) {
+ const h = Math.round(s / 3600);
+ return h >= 24 ? '1d ago' : `${h} hr ago`;
+ }
return `${Math.round(s / 86400)}d ago`;
}
diff --git a/ui/src/studio/traces/TracesMain.jsx b/ui/src/studio/traces/TracesMain.jsx
index 200a7225..8e3bce11 100644
--- a/ui/src/studio/traces/TracesMain.jsx
+++ b/ui/src/studio/traces/TracesMain.jsx
@@ -4,6 +4,7 @@ import { IconByName } from '@/studio/lib/iconCatalog.jsx';
import { Markdown } from '@/studio/lib/markdown.jsx';
import { tracesApi } from './api';
import { flatten, lanes, fmtK } from './flatten';
+import { traceDurationText } from '@/lib/duration';
import { useTraces } from './store';
const clip = (s, n) => (s && s.length > n ? s.slice(0, n) + '…' : s || '');
@@ -16,13 +17,7 @@ const fmtClock = (s) => {
const t = Math.max(0, Math.round(s));
return `${Math.floor(t / 3600)}:${String(Math.floor((t % 3600) / 60)).padStart(2, '0')}:${String(t % 60).padStart(2, '0')}`;
};
-const fmtDur = (sec) => {
- if (sec == null) return '';
- const s = Number(sec);
- if (s < 1) return `${Math.round(s * 1000)}ms`;
- if (s < 60) return `${s.toFixed(1)}s`;
- return `${Math.floor(s / 60)}m ${Math.round(s % 60)}s`;
-};
+const fmtDur = (sec) => (sec == null ? '' : traceDurationText(Number(sec)));
const fmtAgo = (sec) => {
if (!sec) return '';
const d = Math.max(0, Date.now() / 1000 - Number(sec));