fix: ignore poisoned AgentRun session thread after resume failure

This commit is contained in:
lyon
2026-06-20 10:19:36 +08:00
parent f07d8340a0
commit 28a7eaadfa
+17 -1
View File
@@ -1003,7 +1003,23 @@ function agentRunSessionRecordFromEnsure(value = null) {
} }
function agentRunSessionThreadIdFromEnsure(value = null) { function agentRunSessionThreadIdFromEnsure(value = null) {
return safeOpaqueId(agentRunSessionRecordFromEnsure(value)?.threadId) || null; const record = agentRunSessionRecordFromEnsure(value);
if (agentRunSessionThreadInvalidated(record)) return null;
return safeOpaqueId(record?.threadId) || null;
}
function agentRunSessionThreadInvalidated(record = null) {
if (!record || typeof record !== "object") return false;
const failureMessage = firstNonEmpty(
record.failureMessage,
record.blocker?.message,
record.liveness?.terminalClassification?.reason,
record.supervisor?.terminalClassification?.reason
);
if (!agentRunFailureRequiresFreshSession(record.failureKind, failureMessage)) return false;
const terminalStatus = normalizeAgentRunStatus(record.terminalStatus ?? record.status);
const executionState = String(record.executionState ?? "").trim().toLowerCase();
return terminalStatus === "failed" || terminalStatus === "blocked" || executionState === "terminal";
} }
function paramsWithAgentRunSessionThread(params = {}, threadId = null) { function paramsWithAgentRunSessionThread(params = {}, threadId = null) {