Skip to content

fix(gateway): enforce effort policies on Anthropic compatibility routes - #8739

Merged
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
r266-tech:codex/anthropic-compat-effort-policy
Nov 16, 2026
Merged

Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
r266-tech:codex/anthropic-compat-effort-policy

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Fixes #8713

Anthropic 分组通过 /v1/chat/completions 或 /v1/responses 转发时,会跳过分组的推理强度映射与上限。例如分组上限为 medium,请求 high 仍会以 output_config.effort: "high" 发给 Anthropic;配置为拒绝超限请求时也会继续转发。

两个入口现在复用现有策略 helper,在调度和计费预留前应用映射、上限和拒绝规则,并沿用各自现有错误格式。原始请求强度与最终生效强度分别保留在用量记录中。

回归通过真实 GatewayHandler、协议转换、内存上游及用量仓储执行,覆盖两个入口、流式/非流式、Anthropic/Composite 分组、映射与模型匹配、映射后封顶、拒绝、无限制与缺省值。最终同一组 80 个场景在未修改的 main@530c5e3a4 为 48 失败/32 对照通过;修复后 80 全部通过。

验证:

  • 聚焦前后对照:Go 1.27.4 / macOS arm64。
  • 完整 Go 1.27.3 后端 unit:26,960 个测试/子测试通过,41 条件跳过。
  • 完整 Go 1.27.3 后端 integration:16,143 个测试/子测试通过,16 条件跳过。
  • CI 固定 golangci-lint v2.14.0 全后端检查:0 issues;gofmt 与 git diff --check 通过。

附加带 unit 标记的 handler lint 在基线对照与修复代码中均报告 auth_wechat_oauth_test.go / user_platform_quotas_handler_test.go 的 8 项既有问题;增量 lint 为 0 issues。原始失败结果已保留。

当前上游的 Go 1.27.3 安全基线升级由 #8670 单独处理,本分支未混入该工具链补丁。使用合成 HTTP/SSE 响应和临时测试数据库,未调用真实 Anthropic 或验收生产部署。实现与验证由 AI agent 完成。

@Wei-Shaw
Wei-Shaw merged commit c782537 into Wei-Shaw:main Nov 16, 2026
8 of 9 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Anthropic groups ignore the reasoning effort cap on /v1/chat/completions and /v1/responses

2 participants