fix(@effect/ai-openai): map max_output_tokens finish reason to length#6297
Merged
IMax153 merged 2 commits intoJun 29, 2026
Merged
Conversation
The OpenAI Responses API reports a budget/output-length truncation as response.incomplete with incomplete_details.reason "max_output_tokens" (distinct from Chat Completions finish_reason "length"). That key was missing from finishReasonMap, so resolveFinishReason fell through to "unknown" for a genuinely length-truncated response instead of the portable "length" finish reason. Map max_output_tokens to "length" so a truncated turn surfaces a meaningful finish reason. content_filter was already mapped.
🦋 Changeset detectedLatest commit: 8d9a23c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
IMax153
requested changes
Jun 29, 2026
|
|
||
| Map the OpenAI Responses `max_output_tokens` finish reason to `"length"`. | ||
|
|
||
| The OpenAI Responses API reports a budget/output-length truncation as |
Member
There was a problem hiding this comment.
Can we create a more succinct change here? This is overly verbose.
Then this looks good to merge
Contributor
Author
|
Thanks for the review! Shortened the changeset to a single line. |
IMax153
approved these changes
Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
@effect/ai-openai's internalfinishReasonMap(packages/ai/openai/src/internal/utilities.ts) was missing the OpenAI Responses API truncation reasonmax_output_tokens.The Responses API reports a budget/output-length truncation as a
response.incompletelifecycle terminal withincomplete_details.reason: "max_output_tokens"— distinct from the Chat Completionsfinish_reason: "length".resolveFinishReasonreadsresponse.incomplete_details?.reasonand looks it up infinishReasonMap; withmax_output_tokensabsent, it fell through to:So a genuinely length-truncated Responses turn surfaced
finishReason: "unknown"instead of the portable"length". Consumers that treat"unknown"as a transport-level / no-terminal-finish failure (rather than a real, recoverable budget truncation) then mis-handle a perfectly valid truncated response.Change
Add
max_output_tokens: "length"tofinishReasonMap(one line).content_filterwas already mapped ("content-filter"); onlymax_output_tokenswas missing. After this, both the streamingresponse.incompleteevent handler and the non-streaming terminal resolve a budget truncation tofinishReason: "length".A changeset is included (
@effect/ai-openaipatch).Notes
"max_output_tokens" → "length"is the semantically correct mapping in the@effect/aiFinishReasoncontract (both denote "ran out of output budget"); no new finish-reason variant is needed.packages/ai/openaipackage has no existing unit-test suite for these internal helpers, so this follows the same fix-plus-changeset shape as comparable small provider-adapter corrections.