From 134d3300e4f57234ce1cff4c55257bb9900c2af1 Mon Sep 17 00:00:00 2001 From: Leon Shan Date: Mon, 25 May 2026 17:16:48 +0800 Subject: [PATCH] fix: downgrade reasoning parts to text when metadata is stripped MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When stripStaleMetadata removes provider metadata (including bedrock.signature) from reasoning parts after a model change, the parts were kept as type "reasoning". Switching back to a thinking-enabled model (e.g., Claude Opus 4-7) causes the AI SDK to create "{type: \"thinking\"}" blocks without the required signature field, resulting in API validation errors ("messages.N.content.0.thinking.signature: Field required"). Fix: when metadata is stripped from a reasoning part, downgrade it to type "text" — the thinking content is preserved as readable text, but the SDK won't construct invalid thinking blocks. --- lib/messages/reasoning-strip.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/messages/reasoning-strip.ts b/lib/messages/reasoning-strip.ts index d2c98620..dc4cf1e4 100644 --- a/lib/messages/reasoning-strip.ts +++ b/lib/messages/reasoning-strip.ts @@ -34,6 +34,12 @@ export function stripStaleMetadata(messages: WithParts[]): void { } const { metadata: _metadata, ...rest } = part + // Reasoning parts without metadata cannot produce valid `thinking` + // API blocks because the required `signature` lives in metadata. + // Downgrade to text to prevent `thinking.signature: Field required`. + if (part.type === "reasoning") { + return { ...rest, type: "text" } + } return rest }) })