Fix live activity timer
This commit is contained in:
@@ -485,6 +485,7 @@ class RunManager:
|
||||
'current_stage': record.current_stage,
|
||||
'started_at': record.started_at,
|
||||
'updated_at': record.updated_at,
|
||||
'elapsed_ms': max(0, int((time.time() - record.started_at) * 1000)),
|
||||
'pending_prompt': record.pending_prompt,
|
||||
'error': record.error,
|
||||
'events': [dict(event) for event in record.events],
|
||||
@@ -1612,7 +1613,10 @@ def create_app(state: AgentState) -> FastAPI:
|
||||
merged['events'] = stored_snapshot.get('events')
|
||||
if memory_snapshot.get('current_stage'):
|
||||
merged['current_stage'] = memory_snapshot.get('current_stage')
|
||||
if stored_snapshot.get('elapsed_ms') is not None:
|
||||
if (
|
||||
memory_snapshot.get('status') not in ACTIVE_RUN_STATUSES
|
||||
and stored_snapshot.get('elapsed_ms') is not None
|
||||
):
|
||||
merged['elapsed_ms'] = stored_snapshot.get('elapsed_ms')
|
||||
if stored_snapshot.get('finished_at') is not None:
|
||||
merged['finished_at'] = stored_snapshot.get('finished_at')
|
||||
|
||||
@@ -2014,6 +2014,7 @@ const ActivityChainSummary: FC<{
|
||||
});
|
||||
const initialStartedAtMs =
|
||||
metadataRunStartedAtMs ?? contentRunStartedAtMs ?? messageCreatedAtMs;
|
||||
const liveStartedAtRef = useRef<number | null>(initialStartedAtMs);
|
||||
const [elapsedMs, setElapsedMs] = useState<number | null>(() => {
|
||||
if (storedElapsedMs !== null) return storedElapsedMs;
|
||||
if (initialStartedAtMs !== null) {
|
||||
@@ -2041,11 +2042,14 @@ const ActivityChainSummary: FC<{
|
||||
setElapsedMs(storedElapsedMs);
|
||||
return;
|
||||
}
|
||||
const startedAt =
|
||||
metadataRunStartedAtMs ??
|
||||
contentRunStartedAtMs ??
|
||||
messageCreatedAtMs ??
|
||||
(storedElapsedMs === null ? null : Date.now() - storedElapsedMs);
|
||||
const explicitStartedAt =
|
||||
metadataRunStartedAtMs ?? contentRunStartedAtMs ?? messageCreatedAtMs;
|
||||
if (explicitStartedAt !== null) {
|
||||
liveStartedAtRef.current = explicitStartedAt;
|
||||
} else if (liveStartedAtRef.current === null && storedElapsedMs !== null) {
|
||||
liveStartedAtRef.current = Date.now() - storedElapsedMs;
|
||||
}
|
||||
const startedAt = liveStartedAtRef.current;
|
||||
if (startedAt === null) {
|
||||
setElapsedMs(storedElapsedMs);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user