Repository navigation
feat(responses): complete gracefully on max_output_tokens #7770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lidge-jun
merged 10 commits into
lidge-jun:dev
from
omar391:fix/graceful-max-output-tokens
Oct 29, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6bf5795
feat(responses): complete gracefully on max_output_tokens
omar391 5f15e26
test(responses): remove empty catch in graceful max output tokens test
omar391 eb0b09b
fix(config): default completeOnMaxOutputTokens to false to preserve s…
omar391 52d2abd
fix(responses): narrow opted-in token-limit completion to plain text
lidge-jun 6ddde6d
docs(responses): document narrowed token-limit completion policy
lidge-jun b843580
Merge origin/dev into PR #7770 readiness carry
lidge-jun 8b26d10
docs(responses): index token-limit setting and bridge ownership
lidge-jun a9a99cc
Merge remote-tracking branch 'origin/dev' into merge-7770
lidge-jun 50ffb5f
Merge remote-tracking branch 'origin/dev' into merge-7770b
lidge-jun 1fee7a6
Merge origin/dev into fix/graceful-max-output-tokens
lidge-jun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import type { AdapterEvent, OcxRequestOptions } from "../types"; | ||
|
|
||
| export interface MaxOutputCompletionOptions { | ||
| /** Set only for an explicitly opted-in Responses inbound request. */ | ||
| completeOnMaxOutputTokens?: boolean; | ||
| textFormat?: OcxRequestOptions["textFormat"]; | ||
| compaction?: boolean; | ||
| } | ||
|
|
||
| /** Track the original event stream: bridge cleanup must not erase an unfinished operation. */ | ||
| export function createMaxOutputCompletion(options?: MaxOutputCompletionOptions) { | ||
| let textOnly = options?.completeOnMaxOutputTokens === true && !options.compaction && !options.textFormat; | ||
| let hasText = false; | ||
| let completed = false; | ||
| return { | ||
| observe(event: AdapterEvent): void { | ||
| switch (event.type) { | ||
| case "text_delta": | ||
| if (event.anthropicThinkingSignature !== undefined) textOnly = false; | ||
| if (event.text.length > 0) hasText = true; | ||
| break; | ||
| case "heartbeat": | ||
| case "assistant_boundary": | ||
| break; | ||
| case "done": | ||
| case "incomplete": { | ||
| const reason = event.type === "done" ? event.stopReason : event.reason; | ||
| completed = textOnly && hasText && event.endTurn !== false | ||
| && (event.type !== "done" || event.compactionEncryptedContent === undefined) | ||
| && (reason === "max_tokens" || reason === "length" || reason === "max_output_tokens"); | ||
| break; | ||
| } | ||
| default: | ||
| // All non-text output and unknown future operations are excluded, even if hidden or closed. | ||
| textOnly = false; | ||
| completed = false; | ||
| } | ||
| }, | ||
| get completed(): boolean { return completed; }, | ||
| }; | ||
| } |
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.