From 28a7eaadfae21074e968e82bedbfbebdb90bdc19 Mon Sep 17 00:00:00 2001 From: lyon Date: Sat, 20 Jun 2026 10:19:36 +0800 Subject: [PATCH] fix: ignore poisoned AgentRun session thread after resume failure --- internal/cloud/code-agent-agentrun-adapter.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/internal/cloud/code-agent-agentrun-adapter.ts b/internal/cloud/code-agent-agentrun-adapter.ts index df064204..06d8ee5d 100644 --- a/internal/cloud/code-agent-agentrun-adapter.ts +++ b/internal/cloud/code-agent-agentrun-adapter.ts @@ -1003,7 +1003,23 @@ function agentRunSessionRecordFromEnsure(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) {