fix(workbench): hydrate active session on new realtime trace (#1964)
This commit is contained in:
@@ -76,6 +76,7 @@ export const useWorkbenchStore = defineStore("workbench", () => {
|
|||||||
const traceHydrationQueue: ChatMessage[] = [];
|
const traceHydrationQueue: ChatMessage[] = [];
|
||||||
let traceHydrationPumpActive = false;
|
let traceHydrationPumpActive = false;
|
||||||
const terminalRealtimeRefreshInFlight = new Set<string>();
|
const terminalRealtimeRefreshInFlight = new Set<string>();
|
||||||
|
const realtimeSessionRefreshInFlight = new Set<string>();
|
||||||
let realtimeStream: WorkbenchEventStream | null = null;
|
let realtimeStream: WorkbenchEventStream | null = null;
|
||||||
let realtimeKey = "";
|
let realtimeKey = "";
|
||||||
const sessionListRefreshInFlight = new Map<string, Promise<void>>();
|
const sessionListRefreshInFlight = new Map<string, Promise<void>>();
|
||||||
@@ -1248,8 +1249,10 @@ function nonBlockingProjection(projection: ProjectionDiagnostic | null): Project
|
|||||||
const authoritySessionId = traceResultSessionId(trace) ?? traceResultSessionId(snapshot);
|
const authoritySessionId = traceResultSessionId(trace) ?? traceResultSessionId(snapshot);
|
||||||
const ownerSessionId = traceOwnerSessionId(traceId, authoritySessionId);
|
const ownerSessionId = traceOwnerSessionId(traceId, authoritySessionId);
|
||||||
if (!ownerSessionId) return;
|
if (!ownerSessionId) return;
|
||||||
|
let matchedMessage = false;
|
||||||
updateSessionMessages(ownerSessionId, (source) => source.map((message) => {
|
updateSessionMessages(ownerSessionId, (source) => source.map((message) => {
|
||||||
if (!messageMatchesTraceAuthority(message, traceId, authoritySessionId, ownerSessionId)) return message;
|
if (!messageMatchesTraceAuthority(message, traceId, authoritySessionId, ownerSessionId)) return message;
|
||||||
|
matchedMessage = true;
|
||||||
const mergedRunnerTrace = mergeRunnerTrace(message.runnerTrace, trace);
|
const mergedRunnerTrace = mergeRunnerTrace(message.runnerTrace, trace);
|
||||||
const traceStatus = normalizedStatusText(trace.status ?? snapshot.status) ?? null;
|
const traceStatus = normalizedStatusText(trace.status ?? snapshot.status) ?? null;
|
||||||
const clearCompletedDiagnostics = shouldClearCompletedTurnDiagnostics(traceStatus, 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;
|
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() };
|
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);
|
markWorkbenchTraceProjected(traceId);
|
||||||
scheduleSessionListRefresh(ownerSessionId, SESSION_LIST_REALTIME_REFRESH_DELAY_MS);
|
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 {
|
function completeTrace(traceId: string, result: AgentChatResultResponse): void {
|
||||||
const authoritySessionId = traceResultSessionId(result);
|
const authoritySessionId = traceResultSessionId(result);
|
||||||
const ownerSessionId = traceOwnerSessionId(traceId, authoritySessionId);
|
const ownerSessionId = traceOwnerSessionId(traceId, authoritySessionId);
|
||||||
|
|||||||
Reference in New Issue
Block a user