Skip to content
Source
Sign inSign up
TanStack/ai

fix(openai-base): ignore arguments deltas after a tool call ended #2264

Mergedcanblmz1(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/2264/headmerged by AlemTuzlak View on GitHub

Showing 6 changed files with 135 additions and 0 deletions (loading 2).

x
0 of 6 viewed, 6 left
5 additions and 0 deletions.changeset/openai-responses-late-args-delta.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/openai-base': patch
+---
+​
+Drop a `response.function_call_arguments.delta` that arrives after the call already ended (via `function_call_arguments.done` or `output_item.done`). It was emitted as `TOOL_CALL_ARGS` after `TOOL_CALL_END`, so the extra text was appended to the finalized arguments, parsing failed, and the tool did not run. The late delta is now logged and ignored.
16 additions and 0 deletionspackages/openai-base/src/adapters/responses-text.tsModified
View file
@@ -2281,6 +2281,22 @@
continue
+ // A delta after this call's END (from args.done or the
+ // output_item.done backstop) would reach consumers as ARGS after
+ // END, and they would append it to arguments that END already
+ // reported as complete. Drop it so the finalized arguments stand.
+ if (metadata.ended) {
+ options.logger.errors(
+ `${this.name}.processStreamChunks late function_call_arguments.delta after TOOL_CALL_END`,
+ {
+ source: `${this.name}.processStreamChunks`,
+ toolCallId: metadata.callId,
+ itemId: chunk.item_id,
+ rawDelta: chunk.delta,
+ },
+ )
+ continue
+ }
yield {
type: EventType.TOOL_CALL_ARGS,