fix(workbench): hydrate active session on new realtime trace (#1964)

This commit is contained in:
Lyon
2026-06-23 10:46:40 +08:00
committed by GitHub
parent 8aa8a9cf61
commit ce4b3333ce
@@ -76,6 +76,7 @@ export const useWorkbenchStore = defineStore("workbench", () => {
const traceHydrationQueue: ChatMessage[] = [];
let traceHydrationPumpActive = false;
const terminalRealtimeRefreshInFlight = new Set<string>();
const realtimeSessionRefreshInFlight = new Set<string>();
let realtimeStream: WorkbenchEventStream | null = null;
let realtimeKey = "";
const sessionListRefreshInFlight = new Map<string, Promise<void>>();
@@ -1248,8 +1249,10 @@ function nonBlockingProjection(projection: ProjectionDiagnostic | null): Project
const authoritySessionId = traceResultSessionId(trace) ?? traceResultSessionId(snapshot);
const ownerSessionId = traceOwnerSessionId(traceId, authoritySessionId);
if (!ownerSessionId) return;
let matchedMessage = false;
updateSessionMessages(ownerSessionId, (source) => source.map((message) => {
if (!messageMatchesTraceAuthority(message, traceId, authoritySessionId, ownerSessionId)) return message;
matchedMessage = true;
const mergedRunnerTrace = mergeRunnerTrace(message.runnerTrace, trace);
const traceStatus = normalizedStatusText(trace.status ?? snapshot.status) ?? null;
const clearCompletedDiagnostics = shouldClearCompletedTurnDiagnostics(traceStatus, null);
@@ -1259,10 +1262,25 @@ function nonBlockingProjection(projection: ProjectionDiagnostic | null): Project
const projection = clearCompletedDiagnostics ? nonBlockingProjection(trace.projection ?? null) : trace.projection ?? runnerTrace.projection ?? message.projection ?? null;
return { ...message, ...messageTimingPatchForMerge(message, trace), runnerTrace, error: clearCompletedDiagnostics ? null : error ?? message.error ?? null, projection, projectionStatus: projection?.projectionStatus ?? null, projectionHealth: projection?.projectionHealth ?? null, blocker: projection?.blocker ?? null, updatedAt: new Date().toISOString() };
}));
if (!matchedMessage && ownerSessionId === activeSessionId.value) void refreshRealtimeSessionFromRest(ownerSessionId, `realtime-trace-snapshot:${traceId}`);
markWorkbenchTraceProjected(traceId);
scheduleSessionListRefresh(ownerSessionId, SESSION_LIST_REALTIME_REFRESH_DELAY_MS);
}
async function refreshRealtimeSessionFromRest(sessionId: string, reason: string): Promise<void> {
const id = normalizeWorkbenchSessionId(sessionId);
if (!id || id !== activeSessionId.value || realtimeSessionRefreshInFlight.has(id)) return;
realtimeSessionRefreshInFlight.add(id);
try {
recordActivity(reason);
const existing = sessions.value.find((item) => item.sessionId === id) ?? null;
const selected = await loadWorkbenchSession(id, existing);
if (selected && activeSessionId.value === id) applySelectedSessionDetail(selected, "system");
} finally {
realtimeSessionRefreshInFlight.delete(id);
}
}
function completeTrace(traceId: string, result: AgentChatResultResponse): void {
const authoritySessionId = traceResultSessionId(result);
const ownerSessionId = traceOwnerSessionId(traceId, authoritySessionId);