fix(proxy): strip cache_control from OpenAI conversion, guard tool_choice, handle truncated streams#262
Open
thedavidweng wants to merge 4 commits into
Open
Conversation
…oice, handle truncated streams - Remove cache_control passthrough from system messages, text blocks, and tools during Anthropic→OpenAI format conversion to prevent 400 errors on strict OpenAI-compatible endpoints - Always simplify single text block content to plain string format - Move tool_choice inside the tools guard so it is omitted when tools is empty, preventing upstream errors - Handle truncated chat streams with a three-way guard: complete normally when finish_reason is present, emit incomplete response when output exists without finish_reason, emit failed event for empty truncation instead of masking as completed Closes SaladDay#257
- Update 5 transform tests to assert cache_control is stripped (not preserved) since the PR intentionally removes cache_control from Anthropic→OpenAI conversion - Simplify text block test to reflect single-block-to-string optimization - Fix multiline assignment formatting in streaming_codex_chat.rs
The PR moved tool_choice inside the tools guard so it is omitted when no tools are provided. Add a test verifying this behavior to prevent regression and upstream 400 errors on strict endpoints.
6462d06 to
84cc0c0
Compare
The test on main asserted cache_control was preserved during Anthropic→OpenAI conversion, but this branch strips it to prevent 400 errors on strict OpenAI-compatible endpoints.
84cc0c0 to
590e3e3
Compare
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
cache_controlfields from Anthropic→OpenAI format conversion (system messages, text blocks, tools) to prevent 400 errors on strict OpenAI-compatible endpointstool_choiceinside thetoolsguard so it is omitted when tools is emptyfinish_reasonis present, emit incomplete response when output exists withoutfinish_reason, emit failed event for empty truncationChanges
src-tauri/src/proxy/providers/transform.rscache_controlpassthrough from system message construction, text block construction, and tool constructioncache_controlinheritance logic fromnormalize_openai_system_messagessrc-tauri/src/proxy/providers/transform_codex_chat.rstool_choiceassignment inside theif !tools.is_empty()guardsrc-tauri/src/proxy/providers/streaming_codex_chat.rsfinalize()for truncated streams: whenfinish_reasonis absent, check if output exists and emit eitherresponse.completedwithincompletestatus orresponse.failedwithstream_truncatederror typeCloses #257