From f9ac6f31714bf29b7b7767ff3d3ca3c2dc2cf3c4 Mon Sep 17 00:00:00 2001 From: "opencode-agent[bot]" <219766164+opencode-agent[bot]@users.noreply.github.com> Date: Tue, 4 Aug 2026 20:46:51 -0500 Subject: [PATCH] fix(ai): restore Responses tool input semantics (#40553) Co-authored-by: Aiden Cline --- packages/ai/src/protocols/open-responses.ts | 16 +++++++--------- .../ai/test/provider/openai-responses.test.ts | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/ai/src/protocols/open-responses.ts b/packages/ai/src/protocols/open-responses.ts index ef54126e47a..c34f509bbb8 100644 --- a/packages/ai/src/protocols/open-responses.ts +++ b/packages/ai/src/protocols/open-responses.ts @@ -264,7 +264,6 @@ export interface ParserState { readonly providerMetadataKey: string readonly tools: ToolStream.State readonly hasFunctionCall: boolean - readonly hasFunctionCallError: boolean readonly lifecycle: Lifecycle.State readonly messageItems: ReadonlySet readonly messagePhase: (value: unknown) => MessagePhase | null | undefined @@ -609,16 +608,15 @@ const mapUsage = (usage: OpenResponsesUsage | null | undefined, providerMetadata }) } -const mapFinishReason = (event: Event, hasFunctionCall: boolean, hasFunctionCallError: boolean): FinishReason => { +const mapFinishReason = (event: Event, hasFunctionCall: boolean): FinishReason => { const reason = event.response?.incomplete_details?.reason - if (reason === "max_output_tokens") return "length" - if (reason === "content_filter") return "content-filter" - if (hasFunctionCallError) return "error" if (reason === undefined || reason === null) { if (hasFunctionCall) return "tool-calls" if (event.type === "response.incomplete") return "unknown" return "stop" } + if (reason === "max_output_tokens") return "length" + if (reason === "content_filter") return "content-filter" return hasFunctionCall ? "tool-calls" : "unknown" } @@ -898,8 +896,9 @@ const onOutputItemDone = Effect.fn("OpenResponses.onOutputItemDone")(function* ( { ...state, lifecycle, - hasFunctionCall: resultEvents.some(LLMEvent.is.toolCall) || state.hasFunctionCall, - hasFunctionCallError: resultEvents.some(LLMEvent.is.toolInputError) || state.hasFunctionCallError, + hasFunctionCall: + resultEvents.some((event) => LLMEvent.is.toolCall(event) || LLMEvent.is.toolInputError(event)) || + state.hasFunctionCall, tools: result.tools, }, events, @@ -939,7 +938,7 @@ const onResponseFinish = (state: ParserState, event: Event): StepResult => { const events: LLMEvent[] = [] const lifecycle = Lifecycle.finish(state.lifecycle, events, { reason: { - normalized: mapFinishReason(event, state.hasFunctionCall, state.hasFunctionCallError), + normalized: mapFinishReason(event, state.hasFunctionCall), raw: event.response?.incomplete_details?.reason, }, usage: mapUsage(event.response?.usage, state.providerMetadataKey), @@ -1032,7 +1031,6 @@ export const initial = (request: LLMRequest, extension: Extension = BASE): Parse name: extension.name, providerMetadataKey: request.model.route.providerMetadataKey ?? "openresponses", hasFunctionCall: false, - hasFunctionCallError: false, tools: ToolStream.empty(), lifecycle: Lifecycle.initial(), messageItems: new Set(), diff --git a/packages/ai/test/provider/openai-responses.test.ts b/packages/ai/test/provider/openai-responses.test.ts index fa807804fe5..02722c5cc98 100644 --- a/packages/ai/test/provider/openai-responses.test.ts +++ b/packages/ai/test/provider/openai-responses.test.ts @@ -1599,7 +1599,7 @@ describe("OpenAI Responses route", () => { name: "lookup", raw: '{"query":"partial', }) - expect(response.finishReason.normalized).toBe("error") + expect(response.finishReason.normalized).toBe("tool-calls") expect(response.events.some(LLMEvent.is.toolCall)).toBeFalse() }), ) @@ -1626,7 +1626,7 @@ describe("OpenAI Responses route", () => { name: "lookup", raw: '{"query":"partial', }) - expect(response.finishReason.normalized).toBe("error") + expect(response.finishReason.normalized).toBe("tool-calls") }), )