From 1e484005c30e5c4c4660811074dc7adc6669966b Mon Sep 17 00:00:00 2001 From: lyon Date: Sat, 20 Jun 2026 10:40:32 +0800 Subject: [PATCH] fix: reset invalid AgentRun profile session before run create --- internal/cloud/code-agent-agentrun-adapter.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/cloud/code-agent-agentrun-adapter.ts b/internal/cloud/code-agent-agentrun-adapter.ts index 06d8ee5d..4e58e99b 100644 --- a/internal/cloud/code-agent-agentrun-adapter.ts +++ b/internal/cloud/code-agent-agentrun-adapter.ts @@ -392,6 +392,22 @@ export async function submitAgentRunChatTurn({ params = {}, options = {}, traceI } throw error; } + const ensuredSessionRecord = agentRunSessionRecordFromEnsure(ensuredSession); + if (attempt === 0 && agentRunSessionThreadInvalidated(ensuredSessionRecord)) { + sessionReset = true; + traceStore.append(traceId, agentRunTraceEvent({ + type: "backend", + status: "running", + label: "agentrun:profile-session-reset", + message: "AgentRun profile-scoped session " + sessionId + " is terminal after a thread/resume failure; hwlab-cloud-api will create a fresh profile sessionId instead of letting AgentRun manager backfill a stale threadId.", + sessionId, + previousSessionId: baseSessionId, + backendProfile, + waitingFor: "agentrun-session-reset", + valuesPrinted: false + }, backendProfile)); + continue; + } const profileThreadId = agentRunSessionThreadIdFromEnsure(ensuredSession); const dispatchParams = paramsWithAgentRunSessionThread(attemptParams, profileThreadId); if (safeOpaqueId(attemptParams.threadId) && !profileThreadId) {