Skip to content

fix(proxy): strip cache_control from OpenAI format conversion#3841

Merged
farion1231 merged 2 commits into
farion1231:mainfrom
cc10143:feat/capability-injection
Jun 8, 2026
Merged

fix(proxy): strip cache_control from OpenAI format conversion#3841
farion1231 merged 2 commits into
farion1231:mainfrom
cc10143:feat/capability-injection

Conversation

@cc10143

@cc10143 cc10143 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes two format conversion bugs in anthropic_to_openai that cause 400 errors when routing Anthropic requests to strict OpenAI-compatible endpoints (GLM, Qwen, etc.):

Bug 1: cache_control field leaks to OpenAI output

Anthropic's cache_control field (e.g. {"type": "ephemeral"}) was being passed through to OpenAI-format messages, content blocks, and tools. Strict API validators reject unknown fields with 400 Extra inputs are not permitted.

Fix: Remove cache_control passthrough from:

  • System message array items
  • Text content blocks within messages
  • Tool definitions
  • System message merge logic in normalize_openai_system_messages

Bug 2: Content array not simplified to string for single text blocks

When a message contains a single text block ([{"type": "text", "text": "Hello"}]), some strict backends expect "content": "Hello" (string) instead of "content": [{"type": "text", "text": "Hello"}] (array). The previous code kept array format when cache_control was present, which prevented simplification.

Fix: Always simplify single text block content to plain string, regardless of cache_control presence.

Related Issue

Closes #3805

Test Plan

  • 57 transform tests pass (1539 total lib tests)
  • New regression test test_regression_gh3805_no_cache_control_leak_to_openai validates:
    • No cache_control in any message
    • No cache_control in content parts
    • system content is plain string
    • user content is plain string
    • No cache_control in tools

@cc10143
cc10143 force-pushed the feat/capability-injection branch from 377b5d7 to 6bb3e62 Compare June 7, 2026 13:23
cc10143 added 2 commits June 7, 2026 21:32
…1231#3805)

- Remove cache_control passthrough from system messages, text blocks,
  and tools to prevent 400 errors on strict OpenAI-compatible endpoints
- Always simplify single text block content to plain string format
- Fixes two format conversion bugs reported in issue farion1231#3805
@cc10143
cc10143 force-pushed the feat/capability-injection branch from 6bb3e62 to 7f01ef1 Compare June 7, 2026 13:32
@farion1231

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@farion1231
farion1231 merged commit 4f5250f into farion1231:main Jun 8, 2026
2 checks passed
AnXiYiZhi pushed a commit to AnXiYiZhi/DevCLaw-old that referenced this pull request Jun 9, 2026
…1231#3841)

* fix(proxy): strip cache_control from OpenAI format conversion (farion1231#3805)

- Remove cache_control passthrough from system messages, text blocks,
  and tools to prevent 400 errors on strict OpenAI-compatible endpoints
- Always simplify single text block content to plain string format
- Fixes two format conversion bugs reported in issue farion1231#3805

* fix(proxy): apply cargo fmt to fix CI formatting check
gfunc pushed a commit to gfunc/cc-switch that referenced this pull request Jun 19, 2026
…1231#3841)

* fix(proxy): strip cache_control from OpenAI format conversion (farion1231#3805)

- Remove cache_control passthrough from system messages, text blocks,
  and tools to prevent 400 errors on strict OpenAI-compatible endpoints
- Always simplify single text block content to plain string format
- Fixes two format conversion bugs reported in issue farion1231#3805

* fix(proxy): apply cargo fmt to fix CI formatting check
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.

[Feature Request] 代理层自动注入模型能力声明 (Model Capability Injection)

2 participants