fix(workbench): reset thread on provider switch (#2037)

This commit is contained in:
Lyon
2026-06-24 10:25:47 +08:00
committed by GitHub
parent 808fddb976
commit 20bc5066c7
2 changed files with 6 additions and 2 deletions
@@ -442,7 +442,7 @@ export async function submitAgentRunChatTurn({ params = {}, options = {}, traceI
}, backendProfile));
continue;
}
const profileThreadId = agentRunSessionThreadIdFromEnsure(ensuredSession);
const profileThreadId = agentRunSessionThreadIdFromEnsure(ensuredSession, backendProfile);
const dispatchParams = paramsWithAgentRunSessionThread(attemptParams, profileThreadId);
if (safeOpaqueId(attemptParams.threadId) && !profileThreadId) {
traceStore.append(traceId, agentRunTraceEvent({
@@ -1263,9 +1263,11 @@ function agentRunSessionRecordFromEnsure(value = null) {
return session && typeof session === "object" ? session : null;
}
function agentRunSessionThreadIdFromEnsure(value = null) {
function agentRunSessionThreadIdFromEnsure(value = null, backendProfile = null) {
const record = agentRunSessionRecordFromEnsure(value);
if (agentRunSessionThreadInvalidated(record)) return null;
const existingProfile = firstNonEmpty(record?.backendProfile, record?.metadata?.agentRunSessionProfile);
if (existingProfile && backendProfile && existingProfile !== backendProfile) return null;
return safeOpaqueId(record?.threadId) || null;
}
+2
View File
@@ -1881,6 +1881,7 @@ test("cloud api AgentRun adapter keeps AgentRun sessions scoped to HWLAB session
if (request.method === "POST" && url.pathname === "/api/v1/runs") {
assert.equal(body.backendProfile, "minimax-m3");
assert.equal(body.sessionRef.sessionId, minimaxSessionId);
assert.equal(body.sessionRef.threadId, undefined);
assert.equal(body.sessionRef.metadata.hwlabSessionId, hwlabSessionId);
assert.equal(body.sessionRef.metadata.agentRunSessionProfile, "minimax-m3");
return send({ id: "run_hwlab_profile_switch_m3", status: "pending", backendProfile: "minimax-m3", sessionRef: body.sessionRef, resourceBundleRef: body.resourceBundleRef });
@@ -1889,6 +1890,7 @@ test("cloud api AgentRun adapter keeps AgentRun sessions scoped to HWLAB session
assert.equal(body.payload.providerProfile, "minimax-m3");
assert.equal(body.payload.sessionId, minimaxSessionId);
assert.equal(body.payload.hwlabSessionId, hwlabSessionId);
assert.equal(body.payload.threadId, null);
return send({ id: "cmd_hwlab_profile_switch_m3", runId: "run_hwlab_profile_switch_m3", state: "pending", type: "turn", seq: 1 });
}
if (request.method === "GET" && url.pathname === "/api/v1/runs/run_hwlab_profile_switch_m3/commands") {