Skip to content

fix(proxy): strip cache_control from OpenAI conversion, guard tool_choice, handle truncated streams#262

Open
thedavidweng wants to merge 4 commits into
SaladDay:mainfrom
thedavidweng:fix/257-proxy-format-conversion
Open

fix(proxy): strip cache_control from OpenAI conversion, guard tool_choice, handle truncated streams#262
thedavidweng wants to merge 4 commits into
SaladDay:mainfrom
thedavidweng:fix/257-proxy-format-conversion

Conversation

@thedavidweng

Copy link
Copy Markdown
Contributor

Summary

  • Strip cache_control fields from Anthropic→OpenAI format conversion (system messages, text blocks, tools) 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
  • 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

Changes

src-tauri/src/proxy/providers/transform.rs

  • Remove cache_control passthrough from system message construction, text block construction, and tool construction
  • Remove cache_control inheritance logic from normalize_openai_system_messages
  • Simplify single text block content to always use plain string format

src-tauri/src/proxy/providers/transform_codex_chat.rs

  • Wrap tool_choice assignment inside the if !tools.is_empty() guard

src-tauri/src/proxy/providers/streaming_codex_chat.rs

  • Add three-way guard in finalize() for truncated streams: when finish_reason is absent, check if output exists and emit either response.completed with incomplete status or response.failed with stream_truncated error type

Closes #257

@thedavidweng thedavidweng marked this pull request as ready for review June 10, 2026 03:15
…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.
@thedavidweng thedavidweng force-pushed the fix/257-proxy-format-conversion branch from 6462d06 to 84cc0c0 Compare June 10, 2026 21:17
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.
@thedavidweng thedavidweng force-pushed the fix/257-proxy-format-conversion branch from 84cc0c0 to 590e3e3 Compare June 10, 2026 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(proxy): Responses→Chat format conversion issues (cache_control, tool_choice, stream truncation)

1 participant