mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 03:31:23 +00:00
fix(agents): enforce single-writer session files
This commit is contained in:
@@ -90,11 +90,10 @@ export function sanitizeToolUseResultPairing(
|
||||
|
||||
const role = (msg as { role?: unknown }).role;
|
||||
if (role !== "assistant") {
|
||||
if (role === "toolResult") {
|
||||
pushToolResult(msg as Extract<AgentMessage, { role: "toolResult" }>);
|
||||
} else {
|
||||
out.push(msg);
|
||||
}
|
||||
// Tool results must only appear directly after the matching assistant tool call turn.
|
||||
// Any "free-floating" toolResult entries in session history can make strict providers
|
||||
// (Anthropic-compatible APIs, MiniMax, Cloud Code Assist) reject the entire request.
|
||||
if (role !== "toolResult") out.push(msg);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -141,7 +140,8 @@ export function sanitizeToolUseResultPairing(
|
||||
}
|
||||
}
|
||||
|
||||
remainder.push(next);
|
||||
// Drop tool results that don't match the current assistant tool calls.
|
||||
if (nextRole !== "toolResult") remainder.push(next);
|
||||
}
|
||||
|
||||
out.push(msg);
|
||||
@@ -159,11 +159,6 @@ export function sanitizeToolUseResultPairing(
|
||||
out.push(rem);
|
||||
continue;
|
||||
}
|
||||
const remRole = (rem as { role?: unknown }).role;
|
||||
if (remRole === "toolResult") {
|
||||
pushToolResult(rem as Extract<AgentMessage, { role: "toolResult" }>);
|
||||
continue;
|
||||
}
|
||||
out.push(rem);
|
||||
}
|
||||
i = j - 1;
|
||||
|
||||
Reference in New Issue
Block a user