perf(ui): swap the session activity spinner for a dot and a turn timer

The spinner ran a CSS animation on every active row for the whole turn,
repainting a composited layer at frame rate. Rows now carry a static dot —
primary while running, info while unread — and the metadata slot on the right
shows how long the turn has been going, updating once per second in the dot's
colour. The counter is the motion the spinner used to provide, at 1 fps.
Collapsed groups, folders and projects take the dot only, since one counter
cannot speak for several running turns.

Elapsed time is measured client-side because SessionStatus carries no
timestamps, and starts are persisted so a reload resumes the same count. Two
rules keep that honest. Only a liveness stamp — refreshed while a session is
observed active, stamped as the page hides, and compared against the page's
navigation start so a slow bootstrap is not charged to the absence — and a 90s
adoption window may expire a record; a snapshot that cannot yet see a session
is not evidence its turn ended. And a busy event is never read as a turn
boundary, because OpenCode republishes busy at every step of the agent loop, so
after a reload one of those repeats normally beats the first status snapshot.
Idle and error events do end a turn, and retire the record with it.

Snapshot reconciliation walks the running turns and asks whether the snapshot
covers each one, rather than being handed everything it covers: only a live
start can settle, so the pass scales with timing work instead of with the
directory's session list, and allocates nothing per poll.

Also applied to the mobile sessions sheet and session switcher. The shared
duration ticker moves to hooks/ now that it has a second consumer.
This commit is contained in:
Bohdan Triapitsyn
2026-08-05 03:06:35 +03:00
parent ce0e1cea27
commit 094f728777
27 changed files with 1094 additions and 66 deletions
+26 -4
View File
@@ -6,6 +6,11 @@ import {
reconcileSessionActivitySnapshot,
removeSessionOrdering,
} from './session-ordering';
import {
observeSessionActivityTiming,
reconcileSessionActivityTiming,
removeSessionActivityTiming,
} from './session-activity-timing';
// Shared live busy/retry index for every directory. Global events update it
// incrementally and authoritative directory snapshots reconcile it, so each
@@ -74,6 +79,8 @@ export const applyGlobalSessionStatusEvent = (directory: string, payload: Event)
type === 'idle' ? { type: 'idle' } : { ...(props.status ?? {}), type } as SessionStatus,
);
observeSessionActivityEvent(props.sessionID, type === 'idle' ? 'settled' : 'active');
// `retry` is still a running turn, so the elapsed counter keeps going.
observeSessionActivityTiming(props.sessionID, type === 'idle' ? 'settled' : 'active');
return;
}
case 'session.idle':
@@ -82,13 +89,17 @@ export const applyGlobalSessionStatusEvent = (directory: string, payload: Event)
if (typeof props?.sessionID === 'string' && props.sessionID) {
setStatus(props.sessionID, normalizeDirectory(directory), { type: 'idle' });
observeSessionActivityEvent(props.sessionID, 'settled');
observeSessionActivityTiming(props.sessionID, 'settled');
}
return;
}
case 'session.deleted': {
const props = payload.properties as { sessionID?: string; info?: { id?: string } } | undefined;
const sessionId = props?.sessionID ?? props?.info?.id;
if (sessionId) removeSessionOrdering(sessionId);
if (sessionId) {
removeSessionOrdering(sessionId);
removeSessionActivityTiming(sessionId);
}
return;
}
default:
@@ -108,10 +119,21 @@ export const applyGlobalSessionStatusSnapshot = (
): void => {
const directory = normalizeDirectory(rawDirectory);
const known = new Set(knownSessionIds ?? []);
const activeSessionIds = Object.entries(raw)
.filter(([, status]) => normalizeStatusType(status?.type) !== 'idle')
.map(([sessionId]) => sessionId);
// Built once as a set and shared by both consumers below; only non-idle
// sessions land here, so it stays small however long the directory's list is.
const activeSessionIds = new Set<string>();
for (const [sessionId, status] of Object.entries(raw)) {
if (normalizeStatusType(status?.type) !== 'idle') activeSessionIds.add(sessionId);
}
reconcileSessionActivitySnapshot(activeSessionIds, known);
// Timing asks the coverage question instead of being handed a list: a snapshot
// authoritatively covers the caller's session list plus every id it reports
// itself, and only the handful of sessions actually being timed need an
// answer. Reuses the sets already built above, so this allocates nothing.
reconcileSessionActivityTiming(
activeSessionIds,
(sessionId) => known.has(sessionId) || sessionId in raw,
);
useGlobalSessionStatusStore.setState((state) => {
let changed = false;
const next = new Map(state.statusById);