fix(workbench): avoid idle aborts for read hydration (#1940)

This commit is contained in:
Lyon
2026-06-23 03:01:42 +08:00
committed by GitHub
parent b095423532
commit 62fa3afc4c
+17 -4
View File
@@ -553,22 +553,35 @@ export const useWorkbenchStore = defineStore("workbench", () => {
return false;
}
function fetchWorkbenchTurnStatus(traceId: string): Promise<ApiResult<AgentChatResultResponse>> {
function fetchWorkbenchTurnStatus(traceId: string, useActivityTimeout = shouldUseActivityTimeoutForTrace(traceId)): Promise<ApiResult<AgentChatResultResponse>> {
const activitySource = useActivityTimeout ? () => activityRef.value : null;
return runWorkbenchReadHydration(
() => api.workbench.turn(traceId, 8000, () => activityRef.value),
() => api.workbench.turn(traceId, 8000, activitySource),
workbenchReadCooldownKey("turn", traceId),
{ minIntervalMs: WORKBENCH_TURN_STATUS_MIN_REFRESH_MS },
);
}
function fetchWorkbenchTraceEvents(traceId: string, afterProjectedSeq: number): Promise<ApiResult<AgentChatResultResponse>> {
function fetchWorkbenchTraceEvents(traceId: string, afterProjectedSeq: number, useActivityTimeout = shouldUseActivityTimeoutForTrace(traceId)): Promise<ApiResult<AgentChatResultResponse>> {
const activitySource = useActivityTimeout ? () => activityRef.value : null;
return runWorkbenchReadHydration(
() => api.workbench.traceEvents(traceId, WORKBENCH_TRACE_EVENTS_TIMEOUT_MS, () => activityRef.value, { afterProjectedSeq, limit: TRACE_HYDRATION_PAGE_LIMIT }),
() => api.workbench.traceEvents(traceId, WORKBENCH_TRACE_EVENTS_TIMEOUT_MS, activitySource, { afterProjectedSeq, limit: TRACE_HYDRATION_PAGE_LIMIT }),
workbenchReadCooldownKey("trace-events", traceId),
{ minIntervalMs: WORKBENCH_TRACE_EVENTS_MIN_REFRESH_MS },
);
}
function shouldUseActivityTimeoutForTrace(traceId: string | null | undefined): boolean {
const id = firstNonEmptyString(traceId);
if (!id) return false;
if (currentRequest.value?.traceId === id) return true;
const turn = turnStatusAuthority.value[id];
if (turn?.terminal === true || isTerminalMessageStatus(turn?.status)) return false;
const message = [...messages.value].reverse().find((item) => firstNonEmptyString(item.traceId, item.runnerTrace?.traceId) === id) ?? null;
if (isTerminalMessageStatus(message?.status) || isTerminalMessageStatus(message?.runnerTrace?.status)) return false;
return isTraceActiveStatus(turn?.status) || isTraceActiveStatus(message?.status) || isTraceActiveStatus(message?.runnerTrace?.status);
}
async function refreshSessionMessageProjectionPage(sessionId: string | null | undefined): Promise<void> {
const id = normalizeWorkbenchSessionId(sessionId);
if (!id) return;