Skip to content

feat(relaykit): opt in to plaintext thinking replay per channel - #7945

Draft
wxst wants to merge 1 commit into
QuantumNous:mainfrom
wxst:codex/claude-thinking-replay-opt-in
Draft

wxst wants to merge 1 commit into
QuantumNous:mainfrom
wxst:codex/claude-thinking-replay-opt-in

Conversation

@wxst

@wxst wxst commented Oct 21, 2026 •

Copy link
Copy Markdown

Agent

  • Tool: OpenAI Codex,AI 辅助实现与验证
  • Tool version: GitHub CLI 2.102.1;Codex 宿主版本未暴露
  • Model (full id): 代码子任务 gpt-6-luna;协调会话完整 ID 未暴露
  • Host (CLI / IDE / GitHub coding agent / other): Codex desktop
  • Date (UTC): 2026-10-21

Links

User request

  • Verbatim:

把这些修复提 PR 给 NewAPI 官方,再把补丁检查和回归测试接入现有升级流程,尽量减少以后手动维护。

  • Later constraints or corrections from the user (quote, or none):

我们现在用的是OpenCode GO的DeepSeek

Out of scope — refuse

  • Matched: no。本 PR 只增加独立、默认关闭的通用转换选项;不提供订阅、Coding Plan、第三方服务或本机升级工具适配。
  • If yes, what was told to the user (stop here; do not open a PR): 不适用。

Open gate — do not open unless all are satisfied

  • Out of scope (including pass-through-only forwarding): no
  • Usage / configuration / integration (answered instead of opening): no
  • Required issue facts present without invention: yes,见 feat: 按渠道显式启用 Messages→Chat 明文 thinking 回放 #7944
  • Verification is actual commands or steps and observed results, not only go build or tests passed: yes
  • Body is short and factual; no unfiltered AI-generated text: yes,已按实际 diff 和证据整理
  • Open: yes
  • If no, what was told to the user (stop here): 不适用。

Kind

  • Bug fix
  • New feature
  • Performance / refactor
  • Docs
  • Other:

Issue facts

  • Actual behavior: 当前 Messages→Chat 默认省略输入中的明文 thinking,不能按渠道选择回放。
  • Impact: 已确认接受 reasoning_content 的目标无法使用这一转换能力。
  • Frequency: 合成库输入确定复现;不推断所有供应商行为。
  • Evidence that the problem is in new-api rather than the client or upstream: 输入 DTO 有合成文本,转换输出无字段;受控 HTTP 端点验证完整 Chat 历史接受,缺字段拒绝。
  • Applicable types and their fields (relay / billing / frontend / deployment; write "not applicable" otherwise): relay,POST /v1/messages→/v1/chat/completions,58高级自定义、非透传;其余不适用。

Change

新增既有 channel settings JSON 的 claude_thinking_to_reasoning_content,由 RelayInfo 的 per-request ConvOptions 快照传入 relaykit。默认 false 保持现有策略;显式 true 时,仅将 assistant 明文 thinking 按顺序写入 reasoning_content,保留空值与 reasoning-only 历史。不根据模型名推断能力,不将签名或 redacted payload 转成明文。

管理员应只为已验证支持此扩展的目标开启,并合并进已有 settings,不覆盖其他键。无数据库列或 UI 扩展。

Research

Duplicate / prior art

Docs and code

Alternatives considered

Files

Path Why
relaykit/dto/channel_settings.go 现有 settings JSON 的显式选项
relaykit/relayconvert/convmeta/options.go 请求快照中默认关闭的能力
relay/common/relay_info.go Host 配置接线
relaykit/relayconvert/internal/claude_messages/to_oai_chat_req.go 仅开启时恢复明文
relaykit/relayconvert/internal/claude_messages/reasoning_replay_test.go default/enabled、顺序、空值及工具历史回归
relay/common/relay_info_test.go JSON设置到真实转换链的接线回归

Behavior

  • Before: 默认省略 thinking,不能按渠道选择。
  • After: 默认不变;启用后原样回放 assistant 明文 thinking,工具关联和其他内容保持。
  • Explicit non-goals / leftover work: 不解密签名,不补造缺失推理,不自动识别供应商,不改其他协议方向/计费/UI/DB;#7933独立处理流式问题。

Verification

Only what was actually run.

  • Commands and results: Go1.26.10、GOWORK=off;relaykit go test ./... 与 go build ./... 全部通过;root go test ./relay/common -count=1 与 go build ./relay/common 通过;另以 GOOS=linux、GOARCH=arm64、CGO_ENABLED=0 编译后端供隔离 HTTP 测试。新增测试实现前分别因 missing ReasoningContent / reasoning-only丢失 / JSON true 未接线而失败,实现后通过。
  • Manual steps and observed result: 独立 internal Docker 网络、两个 fresh SQLite:经真实管理 API 创建 Advanced Custom 58 渠道并 GET 确认设置。关闭时第一轮200、第二轮缺 reasoning 的 fixture400(保留默认策略);开启时三轮客户端/上游均200,fake 逐轮核对完整 thinking 回放与 tool_result 配对,最终文本匹配。无真实供应商请求,所有自建容器/网络已清理。Linux/arm64后端由本提交+Go1.26.10编译;仅API测试HTML占位,不声称前端或生产镜像验收。
  • UI: screenshot or recording (or why none): 无 UI 变化。
  • Tests added or updated, or why none: 覆盖默认关闭、开启、多thinking块、显式空、nil、reasoning-only、user/redacted/signature不明文、tool_use/result配对;host测试从JSON false/true经过ConvOptions调用公开converter。
  • Databases / providers / platforms exercised: 独立库macOS/arm64;本地隔离API测试(如上);DB代码未变。
  • Not verified: 未直连DeepSeek官方API,未在生产启用此新开关,未跑root全套或数据库三引擎矩阵;不将此前本机OpenCode Go私有补丁的上线验收称为此PR验收。

Risks

Scope check

  • Single focused change: yes
  • Secrets included: no
  • Out of scope (Coding Plan / reverse-engineered channel / third-party wrapper / Codex / pass-through-only forwarding): no

Summary by CodeRabbit

  • New Features

    • Added an opt-in setting to preserve Claude assistant thinking content when converting messages to OpenAI format.
    • Preserved thinking is now included as OpenAI reasoning content, including messages containing only reasoning.
    • Visible assistant text remains unchanged while reasoning content is kept separate.
  • Bug Fixes

    • Channel-level configuration now correctly controls whether assistant reasoning is preserved during conversion.
  • Tests

    • Added coverage for enabled, disabled, empty, and multi-block reasoning scenarios.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 67cd6b59-2397-4ed5-bd56-d03fd564e504
📥 Commits

Reviewing files that changed from the base of the PR and between 7d8b912 and 058575f.

📒 Files selected for processing: 6
  • relay/common/relay_info.go
  • relay/common/relay_info_test.go
  • relaykit/dto/channel_settings.go
  • relaykit/relayconvert/convmeta/options.go
  • relaykit/relayconvert/internal/claude_messages/reasoning_replay_test.go
  • relaykit/relayconvert/internal/claude_messages/to_oai_chat_req.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Adds a channel-level opt-in for converting Claude assistant thinking text into OpenAI Chat reasoning_content. The setting flows through conversion options. When enabled, the converter preserves assistant thinking text, including in reasoning-only messages.

Changes

Claude thinking replay

Layer / File(s) Summary
Channel option and conversion wiring
relaykit/dto/channel_settings.go, relaykit/relayconvert/convmeta/options.go, relay/common/relay_info.go, relay/common/relay_info_test.go
Adds the claude_thinking_to_reasoning_content channel setting and passes its value to the converter option. Tests verify enabled and disabled behavior.
Assistant reasoning conversion
relaykit/relayconvert/internal/claude_messages/to_oai_chat_req.go, relaykit/relayconvert/internal/claude_messages/reasoning_replay_test.go
When enabled, concatenates assistant thinking text into ReasoningContent and retains reasoning-only messages. Tests cover tool history, empty reasoning, excluded content, and default suppression.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant ChannelSettings
  participant RelayInfo
  participant ConvOptions
  participant ClaudeToOpenAIConverter
  ChannelSettings->>RelayInfo: provides ClaudeThinkingToReasoningContent
  RelayInfo->>ConvOptions: sets PreserveAssistantReasoning
  ConvOptions->>ClaudeToOpenAIConverter: enables assistant thinking conversion
  ClaudeToOpenAIConverter->>ClaudeToOpenAIConverter: writes thinking text to ReasoningContent
Loading

Possibly related issues

Suggested reviewers: calcium-ion

Merge Risk: ⚪ Minimal · up to 05857

No identified issue remains that needs resolution before merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed 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 11 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: enabling opt-in plaintext thinking replay per channel.
Linked Issues check Passed 直接关联的 #7944 已关闭并标记为完成。按评估规则,该议题仅提供历史背景,不产生本 PR 的活动编码要求。当前变更仍实现了该历史范围中的默认关闭、按渠道接线、明文 thinking 回放和回归测试。
Out of Scope Changes check Passed 整个 PR 的变更集中在 #7944 描述的转换能力:新增 channel settings 字段,接入 RelayInfo.ConvOptions,按显式选项回放 assistant 明文 thinking,并增加转换器及接线测试。Diff 未显示 UI、数据库、计费、模型能力推断、签名或 redacted payload 转换,亦未包含流式修复或无关重构。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks the channel switch,
Then thinking texts join reasoning’s stitch.
Tool turns stay beside their thread,
Empty thoughts keep what they said.
With the switch off, the old paths run,
The rabbit hops; the tests are done.

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

This branch has not been deployed

No deployments
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.

feat: 按渠道显式启用 Messages→Chat 明文 thinking 回放

1 participant