fix(protocol): sub2api-parity audit — 9 conversion gaps across chat/responses/anthropic - #33
Merged
Merged
Conversation
…esponses/anthropic - chat->responses request: passthrough parallel_tool_calls/service_tier (top-level keys backfilled from raw body via preserveChatPassthroughKeys); map response_format to text.format (json_schema flatten / json_object type) - responses->chat stream/aggregate/nonstream: accept custom_tool_call + custom_tool_call_input delta/done on shared tool index (done reads input key); split incomplete reason (content_filter vs length); echo upstream service_tier on chat top level; treat response.done alias like completed - chat->anthropic request: strip temperature/top_p when thinking enabled - claude responses: content_filter stop_reason refusal -> end_turn (enum); stop branch falls back to tool_use when content holds tool_use blocks - usage/finish closed sets: cache_creation_input_tokens -> details 归位; normalizeFinishReason unknown -> stop - 11 regression tests in protocol_parity_sub2api_test.go; docs/API.md + CHANGELOG updated - live E2E (mimo-v2.6-flash direct + muse-spark responses-rule): 9/9 pass Co-Authored-By: Claude Code <noreply@anthropic.com>
同一客户端 token 下所有请求曾恒选同一池 key(仅哈希 token 部分), 1811 把 key 实际只有 k36 在服务。现 sticky 复用完整 egress sticky 键 (token + 客户端会话后缀),同一会话仍粘定同 key(缓存亲和),不同 会话按哈希散开;failover 重试混入常量后缀跳离故障 key。 Co-Authored-By: Claude Code <noreply@anthropic.com>
stickySessionBase 对无 token(admin 密码触发池)的请求剥离共享 public fallback 前缀,以 sess:<会话后缀> 散列:不同网关会话散开, 同一会话仍粘定;有 token 路径保持 tok:<token>|cli:<会话> 不变。 回归测试覆盖 admin scope 散开 + 同 scope 粘定。 Co-Authored-By: Claude Code <noreply@anthropic.com>
withSessionFromRequest 实际克隆全部请求头供 sticky 路由使用, 而不仅是 x-opencode-session;改名为 withClientHeadersFromRequest 避免读者误以为客户端会话头被丢弃。无行为变更。 Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
对照审计
以 Wei-Shaw/sub2api
backend/internal/pkg/apicompat为参照(chatcompletions_to_responses / responses_to_chatcompletions / chatcompletions_anthropic_bridge / anthropic_to_responses / responses_to_anthropic / responses_stream_event_wire / responses_namespace / types),辅以官方 Responses 流事件文档,对三条转换链路逐项对照,补齐 9 项差异。历史三个协议转换 issue(#17 工具索引分裂、#19 免费层指纹、#21 responses 指纹形状)已在 main 中修复并验证,本 PR 不碰那些路径,只补审计中新发现的 gaps。修复清单
parallel_tool_calls/service_tier透传上游(顶层键经preserveChatPassthroughKeys从原始 body 回填 ExtraBody,类型化结构装不下;extra_body显式键优先);response_format映射为text.format(此前直接丢弃)。custom_tool_call纳入工具槽位,custom_tool_call_input.delta/done同形累积(done 读input键);incomplete按reason细分(content_filter→content_filter);上游service_tier回写 chat 顶层;response.done别名与completed同等终结。temperature/top_p(此前无条件透传→上游 400;与convertClaudeRequest同口径)。content_filter的stop_reason由非法枚举refusal改为end_turn;stop分支加 tool_use block 存在性回退。cache_creation_input_tokens→details 归位;normalizeFinishReason未知原因回退stop。测试
protocol_parity_sub2api_test.go11 用例(custom 工具同 index、content_filter 双路径、response.done 哨兵、service_tier 双路径、thinking 剥参、cache_creation 归位、未知 finish 闭集合、ExtraBody 回填等)。go test ./...全绿,go vet/gofmt干净。[DONE]、responses 流completed、messages 流message_stop,9/9 通过;thinking+temperature 同传 200。🤖 Generated with Claude Code