Skip to content

fix(gateway): record native Anthropic endpoints on error paths - #8741

Open
r266-tech wants to merge 1 commit into
Wei-Shaw:mainfrom
r266-tech:codex/native-anthropic-error-endpoint
Open

r266-tech wants to merge 1 commit into
Wei-Shaw:mainfrom
r266-tech:codex/native-anthropic-error-endpoint

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Fixes #8712

多协议 API key 账号实际走原生 Anthropic /v1/messages 时,三条转发入口没有更新运行时的上游端点。遇到网络、HTTP 或响应读取错误后,错误日志使用的 GetUpstreamEndpoint 可能读到先前的 /v1/chat/completions 或按入站路径推导的端点;例如没有 native Responses 的 adaptive Messages 账号会出现此问题。

三条原生入口现在各调用一次现有 SetActualOpenAIUpstreamEndpoint,在解析和发送请求前将所选上游端点记为 /v1/messages,供没有成功转发结果的诊断路径读取。

回归通过公开的 OpenAIGatewayService 转发入口,先核验实际发出的 HTTP 路径,再检查错误日志与无结果用量记录采用的 handler 端点 reader。覆盖 Kimi 的 Messages、Chat Completions、Responses 三入口,报告中的 Zhipu adaptive Messages/no-native-Responses,流式/非流式,以及网络错误、HTTP 拒绝、响应读取错误和成功对照。同一组 32 个场景在未修改的 main@530c5e3a4 全部因运行时端点断言失败,修复后全部通过。

验证(Go 1.27.3 / macOS arm64):

  • 同一组 32 个真实转发路径回归:main 32 失败,修复后 32 通过。
  • 完整 go test -p=1 -tags=unit ./... -count=1:26,912 个测试/子测试通过,41 条件跳过。
  • 完整 go test -p=2 -tags=integration ./... -count=1:16,143 个测试/子测试通过,16 条件跳过。
  • CI 固定 golangci-lint v2.14.0 全后端检查及带 unit 标记的增量 handler lint:均为 0 issues;gofmt 与 git diff --check 通过。

首轮 -p=2 完整 unit 曾在未修改的 TestInflightEstimate_AccountMappingNoDBAndBoundedMemory(全局堆内存阈值)和 TestRefreshIfNeeded_LateSuccessAfterDeadlineDoesNotPersist(10 ms deadline)各失败一次。原样 main 后端的两项隔离对照各跑 20 次均通过,完整 service 包对照为 18,759 通过/10 跳过;同一修复源码的上述完整 -p=1 unit 也通过。没有修改这两处实现或断言,本轮未确认首次失败根因,原始结果已保留。

使用合成 HTTP/SSE 响应,未调用真实供应商或写入生产错误日志。上游 Go 1.27.3 安全基线升级仍由 #8670 单独处理。实现与验证由 AI agent 完成。

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.

[Bug] openai gateway: native Anthropic pass-through records the wrong upstream endpoint on error

1 participant