Repository navigation
fix(translation): report truncation from response.incomplete as max_tokens/refusal - #877
Merged
Merged
Conversation
…okens/refusal response.incomplete is a terminal event, but the Anthropic translator never handled it: usage was dropped, the stream closed via the generic path, and a truncated answer was reported as a clean end_turn — the client believes the model finished on its own. - extract incomplete_details.reason from response.incomplete (official values: max_output_tokens, content_filter) - map it via a dedicated pure helper (incompleteReasonToAnthropicStopReason): max_output_tokens -> max_tokens, content_filter -> refusal - apply in both streaming (final message_delta) and non-streaming (response body) paths; truncation wins over the tool_use/end_turn priority - add the same empty-stream guard as response.completed - accept refusal in AnthropicMessagesResponse stop_reason type - unit tests for the pure mapping (5 cases)
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.
Summary
response.incompleteis a terminal event, but the Anthropic Messages translator never handled it: usage was dropped, the stream closed via the generic close path, and a truncated answer was reported as a cleanend_turn— the client believes the model finished on its own.Changes
incomplete_details.reasonfromresponse.incomplete(official values:max_output_tokens,content_filter) asincompleteReason.max_output_tokens -> max_tokens,content_filter -> refusal, unknown/missing -> null (callers keep their existingtool_use/end_turnpriority).response.incompletein both streaming (finalmessage_deltastop_reason + usage) and non-streaming (response body) paths; truncation/filter wins over the tool_use/end_turn priority; reuse the sharedcaptureUsageclosure; same empty-stream guard asresponse.completed.refusalinAnthropicMessagesResponse.stop_reason; parseincomplete_detailsinCodexResponseData.Verification
npx vitest run tests/unit/translation: 472/472 passed (incl. 5 new)npx tsc --noEmit: cleannpm run test:unit: 2944 passed / 0 test failures (2 pre-existing collection failures intests/unit/web/*reproduced on the clean base — they requirenpm run buildartifacts)Note
max_tokens -> max_output_tokensforwarding was deliberately not included: the existing testdoes not forward max_tokens to Codexpins that omission as intentional for the Codex backend.