fix: release completed agentrun workspace turns

This commit is contained in:
Codex
2026-06-02 00:49:48 +08:00
parent 21cf7efe52
commit 90f030e8f7
2 changed files with 177 additions and 1 deletions
+24 -1
View File
@@ -850,7 +850,7 @@ async function claimWorkbenchWorkspaceTurn({ params = {}, options = {}, traceId,
return { blocked: true };
}
const activeTraceId = safeTraceId(workspace.activeTraceId);
const activeResult = activeTraceId ? options.codeAgentChatResults?.get(activeTraceId) ?? null : null;
const activeResult = activeTraceId ? await resolveWorkbenchActiveTraceResult(activeTraceId, options) : null;
if (activeTraceId && (!activeResult || activeResult.status === "running")) {
sendJson(response, 409, {
ok: false,
@@ -890,6 +890,29 @@ async function claimWorkbenchWorkspaceTurn({ params = {}, options = {}, traceId,
return { workspace: updated ?? workspace };
}
async function resolveWorkbenchActiveTraceResult(traceId, options = {}) {
if (!safeTraceId(traceId)) return null;
const cached = options.codeAgentChatResults?.get?.(traceId) ?? null;
if (cached?.agentRun?.runId && cached.status === "running") {
try {
const synced = await syncAgentRunChatResult({ traceId, currentResult: cached, options, traceStore: options.traceStore ?? defaultCodeAgentTraceStore });
return synced.result ?? cached;
} catch {
return cached;
}
}
if (cached) return cached;
if (!codeAgentAgentRunAdapterEnabled(options.env ?? process.env)) return null;
try {
const persisted = await loadPersistedAgentRunResult(traceId, options);
if (!persisted?.agentRun?.runId) return persisted;
const synced = await syncAgentRunChatResult({ traceId, currentResult: persisted, options, traceStore: options.traceStore ?? defaultCodeAgentTraceStore });
return synced.result ?? persisted;
} catch {
return null;
}
}
function safeWorkspaceId(value) {
const text = textValue(value);
return /^wsp_[A-Za-z0-9_.:-]+$/u.test(text) ? text : "";