Skip to content

fix(cpa): 保留 Codex 和 Grok 的中途系统指令 - #633

Merged
tbphp merged 2 commits into
mainfrom
tbphp/fix-cpa-system-instructions
Sep 12, 2026
Merged

fix(cpa): 保留 Codex 和 Grok 的中途系统指令#633
tbphp merged 2 commits into
mainfrom
tbphp/fix-cpa-system-instructions

Conversation

@tbphp

@tbphp tbphp commented Sep 12, 2026

Copy link
Copy Markdown
Owner

关联 Issue / Related Issue

暂无关联 Issue;修复 #631 引入的 Anthropic → Codex/Grok 兼容性回归。

变更内容 / Change Content

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

Claude Code 的 Anthropic 请求包含中途 system 消息时,Codex/Grok 路径会在发送前返回 422。现在在调用 CPA 前将消息中的 system 映射为 developer,保留指令内容和会话位置,允许这类请求正常转换。

  • 统一聊天与本地 token 计数的指令映射,覆盖流式和非流式请求;已有 developer、顶层 system、普通 user 提醒及原始请求不被改写。
  • 保留其他渠道的有损转换拒绝规则,以及工具约束和 DeepSeek 思考检查。
  • 补充实际出站内容的回归测试,验证多段指令、工具调用与结果的顺序及内容、思考配置、请求隔离,以及本地计数与执行提示的一致性。已有 gjson/sjson 依赖调整为直接依赖,版本不变。

验证:

  • make check 通过。
  • third_party/cpaembeddedgo test -count=1 ./... 通过。
  • 新增回归用例在修复前复现同一拒绝错误,修复后通过。
  • 用户实测确认:Claude Code 使用 Anthropic 协议请求 Codex 账号的 GPT 模型正常。Grok 已通过自动化出站验证,未做真实账号联调。

兼容性:不新增配置或数据库迁移。本次未更新公开文档或发布说明。

自查清单 / 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 fixtures contain no sensitive data.
  • 如适用,我已说明兼容性或数据迁移影响。 / Where applicable, I documented compatibility or data-migration impact.

在 Anthropic 转换入口将 system 映射为 developer,保留消息内容和位置,并继续拒绝其他渠道的有损转换。

验证:make check;third_party/cpaembedded 中 go test -count=1 ./...。新增出站回归测试已在修复前复现拒绝,在修复后通过。

用户实测确认:Claude Code 使用 Anthropic 协议请求 Codex 账号的 GPT 模型正常。
Copilot AI lite review requested due to automatic review settings September 12, 2026 12:36

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 12, 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-12T12:58:08.998889Z 9543bd5 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 12, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Advanced

Run ID: 0e24ceb2-8dee-431f-af58-c502dfcff26c

📥 Commits

Reviewing files that changed from the base of the PR and between 7e6989e and 9543bd5.

📒 Files selected for processing (2)
  • internal/execution/cpa/conversion_fidelity.go
  • internal/execution/cpa/conversion_fidelity_test.go

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


📝 Walkthrough

Walkthrough

本次修改将 gjsonsjson 声明为直接依赖。prepareConvertedInstructions 会为 Codex 和 Grok 的 Anthropic 请求将 system 消息改写为 developer 消息。ExecuteExecuteStream 使用更新后的请求规格。测试覆盖流式、非流式和 CountTokens 操作,并验证消息顺序、内容、reasoning.effort 及原始请求体保持不变。

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 9543b

The instruction-role conversion is scoped to the intended Codex/Grok Anthropic paths and is covered for streaming, non-streaming, and token-count behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 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 标题明确概括了主要修复内容,准确指出 Codex 和 Grok 的中途系统指令保留行为。
Description check ✅ Passed 描述覆盖关联问题、变更内容、测试验证、兼容性影响和自查清单。作者明确说明未更新公开文档或发布说明,其他必需信息完整。

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: 7e6989e09b

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

🧹 Nitpick comments (1)
internal/execution/cpa/conversion_fidelity_test.go (1)

196-198: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

验证工具结果内容。

当前测试只验证 input.9.call_id。如果转换器丢失或改写 "tool result",测试仍会通过。

请同时断言 input.9.output

建议修改
 					"input.7.call_id":        "call_lookup", "input.7.name": "lookup",
-					"input.8.content.0.text": "DURING_TOOL", "input.9.call_id": "call_lookup",
+					"input.8.content.0.text": "DURING_TOOL", "input.9.call_id": "call_lookup",
+					"input.9.output":         "tool result",

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Advanced

Run ID: d177453d-e8c7-436f-8b33-a490e6e22999

📥 Commits

Reviewing files that changed from the base of the PR and between 5b03d29 and 7e6989e.

📒 Files selected for processing (4)
  • go.mod
  • internal/execution/cpa/adapter.go
  • internal/execution/cpa/conversion_fidelity.go
  • internal/execution/cpa/conversion_fidelity_test.go

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

@tbphp tbphp self-assigned this Sep 12, 2026
@tbphp tbphp added the bug Something isn't working label Sep 12, 2026
@tbphp tbphp added this to the v2.0.0 milestone Sep 12, 2026
让 Codex/Grok 的 Anthropic 本地计数复用执行请求的指令角色映射,保持其他渠道计数行为不变。补充计数一致性回归测试和工具结果内容断言。

验证:计数回归测试先复现差异,修复后通过;make check 和 CPA embedded 全套测试通过。
@tbphp

tbphp commented Sep 12, 2026

Copy link
Copy Markdown
Owner Author

关于 Docstring Coverage 的 80% 提示:仓库没有该比例门禁,关键转换逻辑已有必要说明,本次不按比例批量补充注释。

@tbphp
tbphp merged commit 426bde9 into main Sep 12, 2026
11 checks passed
@tbphp
tbphp deleted the tbphp/fix-cpa-system-instructions branch September 12, 2026 13:01
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.

2 participants