From ee8094d843ae3467653fd8cbc1f4b6340e6a08be Mon Sep 17 00:00:00 2001 From: Claude Agent Date: Fri, 16 Jan 2026 20:09:37 +0100 Subject: [PATCH] fix: remove invalid step-start parts from UIMessage conversion The AI SDK's convertToModelMessages() does not accept 'step-start' as a valid UIMessagePart type. This caused AI_InvalidPromptError during session compaction. - Remove step-start from being added to UIMessage parts - Simplify the filter since step-start is no longer included - Fixes compaction breaking sessions with context overflow --- packages/opencode/src/session/message-v2.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/opencode/src/session/message-v2.ts b/packages/opencode/src/session/message-v2.ts index 4b081b5b44e..49ecebff818 100644 --- a/packages/opencode/src/session/message-v2.ts +++ b/packages/opencode/src/session/message-v2.ts @@ -504,10 +504,8 @@ export namespace MessageV2 { text: part.text, providerMetadata: part.metadata, }) - if (part.type === "step-start") - assistantMessage.parts.push({ - type: "step-start", - }) + // step-start parts are not added to UIMessage since "step-start" is not a valid + // UIMessagePart type in the AI SDK - they are only used internally for tracking if (part.type === "tool") { if (part.state.status === "completed") { assistantMessage.parts.push({ @@ -556,12 +554,9 @@ export namespace MessageV2 { } } - return convertToModelMessages( - result.filter((msg) => msg.parts.some((part) => part.type !== "step-start")), - { - tools: options?.tools, - }, - ) + return convertToModelMessages(result, { + tools: options?.tools, + }) } export const stream = fn(Identifier.schema("session"), async function* (sessionID) {