mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:30:42 +00:00
fix: preserve signed thinking turns during replay normalization
This commit is contained in:
@@ -946,6 +946,37 @@ describe("wrapStreamFnSanitizeMalformedToolCalls", () => {
|
||||
expect(seenContext.messages).toBe(messages);
|
||||
});
|
||||
|
||||
it("preserves signed thinking turns when replayed tool calls would otherwise be sanitized", async () => {
|
||||
const messages = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "thinking", thinking: "internal", thinkingSignature: "sig_1" },
|
||||
{ type: "toolCall", id: "toolu_legacy", name: "gateway", arguments: {} },
|
||||
],
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: [{ type: "text", text: "retry" }],
|
||||
},
|
||||
];
|
||||
const baseFn = vi.fn((_model, _context) =>
|
||||
createFakeStream({ events: [], resultMessage: { role: "assistant", content: [] } }),
|
||||
);
|
||||
|
||||
const wrapped = wrapStreamFnSanitizeMalformedToolCalls(baseFn as never, new Set(["read"]));
|
||||
const stream = wrapped(
|
||||
{ api: "anthropic-messages" } as never,
|
||||
{ messages } as never,
|
||||
{} as never,
|
||||
) as FakeWrappedStream | Promise<FakeWrappedStream>;
|
||||
await Promise.resolve(stream);
|
||||
|
||||
expect(baseFn).toHaveBeenCalledTimes(1);
|
||||
const seenContext = baseFn.mock.calls[0]?.[1] as { messages: unknown[] };
|
||||
expect(seenContext.messages).toBe(messages);
|
||||
});
|
||||
|
||||
it("preserves sessions_spawn attachment payloads on replay", async () => {
|
||||
const attachmentContent = "INLINE_ATTACHMENT_PAYLOAD";
|
||||
const messages = [
|
||||
|
||||
@@ -229,6 +229,14 @@ type AnthropicToolResultContentBlock = {
|
||||
toolUseId?: unknown;
|
||||
};
|
||||
|
||||
function isThinkingLikeReplayBlock(block: unknown): boolean {
|
||||
if (!block || typeof block !== "object") {
|
||||
return false;
|
||||
}
|
||||
const type = (block as { type?: unknown }).type;
|
||||
return type === "thinking" || type === "redacted_thinking";
|
||||
}
|
||||
|
||||
function isReplayToolCallBlock(block: unknown): block is ReplayToolCallBlock {
|
||||
if (!block || typeof block !== "object") {
|
||||
return false;
|
||||
@@ -283,6 +291,10 @@ function sanitizeReplayToolCallInputs(
|
||||
out.push(message);
|
||||
continue;
|
||||
}
|
||||
if (message.content.some((block) => isThinkingLikeReplayBlock(block))) {
|
||||
out.push(message);
|
||||
continue;
|
||||
}
|
||||
|
||||
const nextContent: typeof message.content = [];
|
||||
let messageChanged = false;
|
||||
|
||||
Reference in New Issue
Block a user