The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(conversations): split live elapsed timer into since and running hooks
Steven Enamakelbfeeadf167f2
diff --git a/app/src/features/conversations/aui/StallWarning.tsx b/app/src/features/conversations/aui/StallWarning.tsxnew file mode 100644index 0000000000..7effcad498--- /dev/null+++ b/app/src/features/conversations/aui/StallWarning.tsx@@ -0,0 +1,51 @@+/**+ * The "this turn has gone quiet" banner above the composer (after OpenClaw's+ * health chips): the phase-specific explanation, how long the turn has been+ * silent, and Stop right beside it so the user does not have to hunt for the+ * composer's stop button. Informational only — the turn keeps running and the+ * banner clears itself on the next inference signal.+ */+import { useT } from '../../../lib/i18n/I18nContext';+import { formatElapsed } from '../components/AssistantUiToolCall';+import { useLiveElapsed } from './useLiveElapsed';++export interface StallWarningProps {+ /** `inferenceStatusByThread.phase` of the quiet turn. */+ phase: string;+ /** Epoch ms of the turn's last inference signal. */+ quietSince: number;+ onStop: () => void;+}++/** `75_000` → "1m 15s", rounded to whole seconds for a banner. */+function formatQuiet(ms: number): string {+ return formatElapsed(Math.round(ms / 1000) * 1000);+}++export function StallWarning({ phase, quietSince, onStop }: StallWarningProps) {+ const { t } = useT();+ const quietMs = useLiveElapsed(quietSince, true) ?? 0;+ return (+ <div className="mb-2 flex items-start justify-between gap-3" role="status">+ <p+ className="text-xs text-amber-700"+ data-testid="chat-stall-warning"+ data-chat-stall-phase={phase}>+ {t(phase === 'thinking' ? 'chat.stallWarning.thinking' : 'chat.stallWarning.working')}{' '}+ <span data-testid="chat-stall-quiet" className="tabular-nums font-medium">+ {t('chat.status.quietFor').replace('{duration}', formatQuiet(quietMs))}+ </span>+ </p>+ <button+ type="button"+ data-analytics-id="chat-stall-stop"+ data-testid="chat-stall-stop"+ onClick={onStop}+ className="flex-none rounded-md border border-amber-600/40 px-2 py-0.5 text-xs font-medium text-amber-700 transition-colors hover:bg-amber-500/10">+ {t('chat.status.stop')}+ </button>+ </div>+ );+}++export default StallWarning;diff --git a/app/src/features/conversations/aui/useLiveElapsed.ts b/app/src/features/conversations/aui/useLiveElapsed.tsindex 3f28784344..d9ae5440f8 100644--- a/app/src/features/conversations/aui/useLiveElapsed.ts+++ b/app/src/features/conversations/aui/useLiveElapsed.ts@@ -1,55 +1,38 @@import { useEffect, useState } from 'react';/**- * Elapsed time for a sub-agent delegation that ticks every second while it- * works, after OpenClaw's live subagent timers.- *- * The core reports a delegation's wall-clock `elapsedMs` only once it settles;- * a running row carries no start time. So the clock is anchored the first time- * this session sees the task running, in a module-scoped map that outlives- * assistant-ui's remounts (virtualised history, thread switches). After a- * reload mid-run the anchor is the reload, so the count restarts — the settled- * duration from the core replaces it as soon as the run finishes.+ * Milliseconds since `since` (epoch ms), re-rendering once a second while+ * `active`. Returns `undefined` when inactive or when `since` is unknown, so a+ * caller never shows a frozen clock.*/-const MAX_ANCHORS = 500;-const anchors = new Map<string, number>();--function anchorFor(key: string): number {- const existing = anchors.get(key);- if (existing !== undefined) return existing;- const now = Date.now();- anchors.set(key, now);- if (anchors.size > MAX_ANCHORS) {- const oldest = anchors.keys().next().value;- if (oldest !== undefined) anchors.delete(oldest);- }- return now;-}--/** Forget every anchor. Exposed for tests. */-export function resetLiveElapsedAnchors(): void {- anchors.clear();-}--/**- * `settledMs` once the run has finished, else live milliseconds since the run- * was first seen; `undefined` when neither is known (no key while running).- */-export function useLiveElapsed(- key: string | undefined,- running: boolean,- settledMs: number | undefined-): number | undefined {- const ticking = running && key !== undefined;+export function useLiveElapsed(since: number | undefined, active: boolean): number | undefined {+ const ticking = active && since !== undefined;const [now, setNow] = useState(() => Date.now());-+ const [wasTicking, setWasTicking] = useState(ticking);+ if (wasTicking !== ticking) {+ setWasTicking(ticking);+ if (ticking) setNow(Date.now());+ }useEffect(() => {if (!ticking) return undefined;- const id = setInterval(() => setNow(Date.now()), 1000);- return () => clearInterval(id);+ const id = window.setInterval(() => setNow(Date.now()), 1000);+ return () => window.clearInterval(id);}, [ticking]);+ if (!ticking || since === undefined) return undefined;+ return Math.max(0, now - since);+}- if (!running) return settledMs;- if (key === undefined) return undefined;- return Math.max(0, now - anchorFor(key));+/**+ * Epoch ms at which `running` last became true (or the component mounted+ * running), cleared when it stops. For live timers on rows that carry no+ * start timestamp of their own.+ */+export function useRunningSince(running: boolean): number | undefined {+ const [since, setSince] = useState<number | undefined>(() => (running ? Date.now() : undefined));+ const [wasRunning, setWasRunning] = useState(running);+ if (wasRunning !== running) {+ setWasRunning(running);+ setSince(running ? Date.now() : undefined);+ }+ return since;}