Skip to content

fix(bifrost): 恢复兼容渠道的工具降级转发 - #653

Merged
tbphp merged 5 commits into
mainfrom
tbphp/cross-protocol-tool-compatibility
Sep 14, 2026
Merged

tbphp merged 5 commits into
mainfrom
tbphp/cross-protocol-tool-compatibility

Conversation

@tbphp

@tbphp tbphp commented Sep 14, 2026

Copy link
Copy Markdown
Owner

关联 Issue / Related Issue

Closes #651

变更内容 / Change Content

  • Bug 修复 / Bug fix
  • 新功能 / New feature
  • 其他改动 / Other changes

OpenAI Compatible 的 Responses 和 Anthropic 请求会经 SDK 转为 Chat Completions。Codex 的实际请求同时包含普通 function、namespace 与 web_search;SDK 会过滤无法表达的工具。此前本地保真检查把这类 SDK 降级直接转为 422,造成旧版可继续执行的请求在升级后失败。

  • OpenAI Compatible 改为沿用 SDK 的尽力转换:工具或 tool_choice 被 Chat fallback 过滤时继续转发,不提前返回 protocol_conversion_unsupported。
  • 保留普通函数白名单适配及其有效性校验;其他目标渠道的工具保真拒绝、DeepSeek 思考保护、中途系统指令保护不变。
  • Bifrost 与 CPA 的函数白名单、计数请求一致性、工具历史和角色保护保持既有定向修复。

兼容性:OpenAI Compatible 的 namespace、custom、服务端搜索等工具可能被 SDK 过滤,指定工具或 required 约束也可能被弱化或省略;本 PR 不承诺这些工具在 Chat 上游可用。无数据迁移,不新增依赖、路由或发送链路。Issue #651 缺少真实上游和请求,尚未完成同形验证。

验证:make check;另有 Codex 混合工具、Responses 指定搜索、Anthropic 指定搜索的普通和流式实际出站回归。

自查清单 / Checklist

  • 我已运行 make check,或在说明中写明无法运行的原因和未验证范围。 / I ran make check, or documented why it could not run and what remains unverified.
  • 本 PR 范围聚焦,未包含无关改动。 / This PR is focused and contains no unrelated changes.
  • 我已更新必要的公开文档或发布说明。 / I updated any required public documentation or release notes.
  • 我已确认提交、日志和测试数据不包含敏感信息。 / I confirmed that commits, logs, and test data do not contain sensitive information.
  • 如适用,我已说明兼容性或数据迁移影响。 / Where applicable, I documented compatibility or data-migration impact.

Copilot AI lite review requested due to automatic review settings September 14, 2026 09:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-14T13:38:02.497594Z 82f2634 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

本次变更为 Bifrost 和 CPA 转换路径增加工具约束保真度处理。代码会校验函数白名单、工具选择模式、目标协议兼容性和工具调用历史。无法保留语义时,转换会返回关键语义损失错误并停止发送。请求适配在副本上执行。新增测试覆盖多种协议、目标提供商、流式调用、两轮工具调用、非法约束和原生路由。

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to 82f26

Some converted tool requests can reach providers with disallowed tools or unrepresentable tool history, changing requested tool behavior. Fix these fidelity gates before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.35% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 74 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed 标题准确概括了主要变更,即恢复 Bifrost 兼容渠道的工具降级转发。标题简洁且与变更内容一致。
Description check ✅ Passed 描述包含关联 Issue、变更内容、兼容性影响、验证范围和自查清单。未勾选公开文档或发布说明,且描述未明确说明是否无需更新;该项不影响整体完整性。

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 79e6e20c9d

ℹ️ 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".

Comment thread internal/execution/bifrost/tool_compatibility.go
Comment thread internal/execution/bifrost/tool_compatibility.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Advanced

Run ID: 3095df7e-5a98-4663-82a1-8283dbc11d92

📥 Commits

Reviewing files that changed from the base of the PR and between 0a19e80 and 79e6e20.

📒 Files selected for processing (8)
  • internal/execution/bifrost/conversion_fidelity.go
  • internal/execution/bifrost/conversion_fidelity_test.go
  • internal/execution/bifrost/tool_compatibility.go
  • internal/execution/bifrost/tool_compatibility_runtime_test.go
  • internal/execution/bifrost/tool_compatibility_test.go
  • internal/execution/cpa/adapter.go
  • internal/execution/cpa/conversion_fidelity.go
  • internal/execution/cpa/tool_compatibility_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment thread internal/execution/bifrost/conversion_fidelity.go
Comment thread internal/execution/cpa/conversion_fidelity.go
@tbphp tbphp self-assigned this Sep 14, 2026
@tbphp tbphp added this to the v2.0.0 milestone Sep 14, 2026
@tbphp tbphp added the bug Something isn't working label Sep 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e074ad08a4

ℹ️ 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".

Comment thread internal/execution/bifrost/tool_compatibility.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b5c79fbe54

ℹ️ 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".

Comment thread internal/execution/cpa/conversion_fidelity.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (2)
internal/execution/cpa/conversion_fidelity.go (1)

83-103: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

When no allowed_tools is present, this early return skips subscriptionResponsesToolHistorySupported. Converted Claude and Antigravity Responses requests can therefore dispatch unsupported tool-history items through both unary and streaming paths, where their semantics cannot be preserved. Validate Responses history independently of allowlist presence before returning.

internal/execution/bifrost/tool_compatibility.go (1)

17-65: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

needsToolHistoryCheck remains false for unsupported Responses tool history when no function allowlist is present, so converted requests can skip the target-history validation and dispatch with semantic loss. Require the history check for applicable converted Responses requests regardless of allowlist presence.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Advanced

Run ID: 1d938ac7-ce4a-4470-a1ad-a6beb7850695

📥 Commits

Reviewing files that changed from the base of the PR and between e074ad0 and b5c79fb.

📒 Files selected for processing (2)
  • internal/execution/bifrost/tool_compatibility.go
  • internal/execution/bifrost/tool_compatibility_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@tbphp tbphp changed the title fix(execution): 保留跨协议工具调用约束 fix(bifrost): 恢复兼容渠道的工具降级转发 Sep 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 82f26348f7

ℹ️ 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".

Comment thread internal/execution/bifrost/conversion_fidelity.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (3)
internal/execution/cpa/conversion_fidelity.go (2)

175-176: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

仅在 snake_case 配置完整时覆盖 Gemini 配置。

当请求同时包含有效的 toolConfig.functionCallingConfig 和不含 function_calling_configtool_config 时,Line 175 会覆盖 config。Line 182 随后将该请求视为未设置白名单并直接返回。tools 中未允许的函数因此不会被过滤。

仅当 tool_config.function_calling_config 存在时才给予 snake_case 配置优先级。添加该组合输入的回归测试。

建议修复
 if providerKind == channel.ProviderClaude && gjson.GetBytes(body, "tool_config").Exists() {
-	config = gjson.GetBytes(body, "tool_config.function_calling_config")
+	legacyConfig := gjson.GetBytes(body, "tool_config.function_calling_config")
+	if legacyConfig.Exists() {
+		config = legacyConfig
+	}
 }

90-91: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

The !present return skips subscriptionResponsesToolHistorySupported, so converted Responses requests without an allowed_tools choice can dispatch unsupported history such as file_search_call to Claude or Antigravity. Validate history independently of the function allowlist before returning, so unrepresentable history is rejected rather than silently altered.

internal/execution/bifrost/conversion_fidelity.go (1)

19-25: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

独立启用工具历史检查

对于没有函数 allowlist 的 OpenAIResponses 请求,prepareConvertedToolConstraints 不会设置 needsToolHistoryCheckfinishConvertedPreparation 因此可能跳过 convertedTargetPreservesToolHistory。该函数会将 custom_tool_call 判定为 chat fallback、Anthropic 和 Bedrock 不支持的历史。请求可能绕过 CriticalSemanticLoss 拒绝并进入执行,导致工具历史无法保留。请将工具历史检查与 allowlist 适配分开启用。


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Advanced

Run ID: 17b0730b-1c52-4385-8cf3-3bf86b29a476

📥 Commits

Reviewing files that changed from the base of the PR and between b5c79fb and 82f2634.

📒 Files selected for processing (8)
  • internal/execution/bifrost/conversion_fidelity.go
  • internal/execution/bifrost/conversion_fidelity_test.go
  • internal/execution/bifrost/count_tokens_test.go
  • internal/execution/bifrost/executor.go
  • internal/execution/bifrost/tool_compatibility_runtime_test.go
  • internal/execution/bifrost/tool_compatibility_test.go
  • internal/execution/cpa/conversion_fidelity.go
  • internal/execution/cpa/tool_compatibility_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@tbphp
tbphp merged commit 91df89e into main Sep 14, 2026
11 checks passed
@tbphp
tbphp deleted the tbphp/cross-protocol-tool-compatibility branch September 14, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

版本升级后,OpenAI好像无法转换OpenAI Compatible

2 participants