fix(workbench): keep projected trace times monotonic (#2054)

This commit is contained in:
Lyon
2026-06-24 17:49:04 +08:00
committed by GitHub
parent 6c253b97d5
commit e390becd72
@@ -110,13 +110,14 @@ export async function writeWorkbenchProjectionEvent({ runtimeStore = null, event
if (!traceId) return null;
const projectedAt = new Date().toISOString();
const sourceSeq = nonNegativeInteger(event.sourceSeq ?? event.seq);
const occurredAt = timestampValue(event.createdAt ?? event.occurredAt ?? event.updatedAt ?? projectedAt);
const sessionId = textValue(event.sessionId ?? requestMeta.sessionId) || null;
const turnId = textValue(event.turnId) || traceId;
const terminal = event.terminal === true || TERMINAL_STATUSES.has(normalizeWorkbenchStatus(event.status));
const status = terminal ? normalizeWorkbenchStatus(event.status) : "running";
const previousCheckpoint = await latestWorkbenchCheckpoint(runtimeStore, traceId);
const previousTiming = normalizeTimingProjection(previousCheckpoint?.timing) ?? normalizeTimingProjection(previousCheckpoint);
const sourceOccurredAt = timestampValue(event.createdAt ?? event.occurredAt ?? event.updatedAt ?? projectedAt);
const occurredAt = latestTimestamp(previousTiming?.lastEventAt, sourceOccurredAt) ?? sourceOccurredAt;
const previousTerminal = checkpointIsTerminal(previousCheckpoint);
const suppressedAfterSeal = previousTerminal && !terminal;
const explicitEventTiming = normalizeTimingProjection(event.timing) ?? normalizeTimingProjection(event);
@@ -222,6 +223,8 @@ export async function writeWorkbenchProjectionEvent({ runtimeStore = null, event
finishedAt: eventTiming?.finishedAt ?? null,
durationMs: eventTiming?.durationMs ?? null,
suppressedAfterSeal,
sourceOccurredAt: sourceOccurredAt !== occurredAt ? sourceOccurredAt : null,
createdAt: occurredAt,
occurredAt,
updatedAt: projectedAt
}],