Repository navigation
fix: 正确处理 Anthropic 请求体过大的 413 错误 - #829
Merged
Merged
Conversation
ranxi2001
marked this pull request as ready for review
November 13, 2026 05:23
This was referenced Nov 13, 2026
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.
解决的问题与行为变化
/v1/messages上游 HTTP 413 被服务层写成 502;自定义错误码或冷却策略可能重发相同请求、切换账号或污染健康状态。request_too_largeJSON;已提交 SSE 时保留 HTTP 状态,只写一个兼容终止错误。提示中的 32 MiB 是请求字节限制,不是 token 窗口,不自动删除/压缩历史或工具。skip_monitoring;先前事件及其规则快照保持不变。只使用内部请求级标记与request_too_large类型判定,不按任意上游正文跳过观察。98cce6160e34621f11c4815259fdc979e2e7a6b2的原始与 L1/L2 行为 RED、56 场景 GREEN、focused race/service/生产包 build 已通过;独立复核无源码阻塞项。生产尚未部署,无 Release。仓库级最终 CI 状态见下方验收记录。关联记录与来源
production。ff23a988f4c5825ec06a7efb4e0f16f2b1e65ced;最初 tests-only head:69d2433e51417a3a3a53e3eae77c1d1d4cfbda9c。4bb46c4c83de1f0cd08b7f3f4ba25ec01e3a3371。监督者确认该 head 的 matrix/race/service/build 已通过,见 run 43366344948 / artifact 14011405601。该结果不包含尚未发布的 L1/L2 修复;同 head 的 lint 因 ST1005 失败。2.21.1、commit11f250894eab310cbd4508946c44c9e2a3a2eb48的同一请求有上游 413 → 网关 502;客户标识、请求 ID、真实正文、IP、凭据保持私密。不是修复后生产验证。管理员新功能提示
frontend/src/constants/newFeatureNotices.ts登记项:不适用,协议/错误处理修复,无新增管理员功能。NewFeatureBadge展示位置:不适用,无新增入口。复现与验收
backend/go.mod,原 RED 实际为 1.27.4。合成小请求、虚构凭据、本地 HTTP fixture,无真实上游或数据库操作。OpsService.SetAutoConfigObserver连接,使用生产AdvanceConcurrency状态转换并预置已有成功进度。skip_monitoring=true;每类覆盖 JSON 与已提交 SSE。backend/internal/handler/anthropic_413_test.go的 50 场景保留;新增backend/internal/handler/anthropic_413_review_test.go的三个测试各含 json/sse 两个场景,共 56 个。协议、调度或传输改动补充
/v1/messages,测试模型claude-sonnet-4-5;原矩阵含 API-key/passthrough/OAuth/setup-token,本轮新增场景使用 Anthropic API-key。{"model":"claude-sonnet-4-5","max_tokens":16,"thinking":{"type":"enabled","budget_tokens":1},"stream":false,"messages":[{"role":"user","content":"synthetic-413-review"}]};fixture 返回 400thinking.budget_tokens must be >= 1024,第二次确实发送生产整流后的预算,随后 413 终止,无第三次请求。request_too_large/ 固定安全提示;已提交时保留 HTTP 状态,event: error承载同一 JSON。不反射上游任意 body/header。Writer.Written(),不依赖测试外层的 streamStarted 布尔值。实际验证
TestAnthropic413MessagesHTTP/apikey/streamanthropic request body too large,对客常量字节保持不变;最终 head 的普通 CI lint 已 successgofmt、git diff --check、新文件空白检查review-redTestAnthropic413ReviewAutoConfigNoCooldown/{json,sse}TestAnthropic413ReviewBudgetRepairMonitoring/{json,sse}TestAnthropic413ReviewPreservesEarlierFailures/{json,sse}TestIssue805ChatWSPostHeaders429KeepsCommittedAndReleasesPending读到仍带pending:前缀的路由快照,与后续已完成转换的 JSON 比较失败;保留 raw job 131697533691 日志。未改/跳过测试,attempt 2 已 success。最终门禁逐个核对所有 workflow 最新 attempt,历史失败单独保留为 superseded,不声称所有历史尝试均成功check-runs?filter=all,ID 去重与total_count核对:73 条全历史 check,其中当前 72 个 job 覆盖 30 个 workflow run,全部 completed / success、skipped 或 neutral,传统 commit status 0 条,无 pending/failure。唯一旧 attempt 失败为上行 Issue805 job,已按同一 run attempt 2 的成功记录核实 superseded;push 与 pull_request 两套普通 CI 均成功合并基线:验收原 base 为
ff23a988f4c5825ec06a7efb4e0f16f2b1e65ced。等待 CI 期间外部 PR #826、#828 将 live production 推进至f890f77c31e896c35c5ba2d0eced2032e9996d1c,分别为 frontend 视频价卡及风险代次/管理端 ACL 独立更新,均不涉及本修复上游错误/ops/并发观察调用链;路径交集为空,已检查邻接的 APIKeyService 更新 diff。只读git merge-tree --write-tree实测无冲突,结果 tree497503c77e99e2e98fb3a8d9052762538781876e。不把旧 PR REST base.sha 的缓存值当作 live base;不将原 CI 误称为合并后 CI。所有验收绑定最终 head
98cce6160e34621f11c4815259fdc979e2e7a6b2。执行目录为backend/;实际完整命令见本 PR.github/workflows/anthropic-413.yml的 exact-head job 与 raw artifact,其中核心命令:原始与评审 RED 均保存 raw JSON、stderr、退出码、head/base/tree/测试摘要和 Go 版本;文件在
RUNNER_TEMP,退出时恢复干净 checkout。无 UI 改动,截图不适用。兼容性与运行影响
文档与用户可见变化
请求过大时提供可操作的 413 提示;先前内部修复尝试不能隐藏最终拒绝,也不能让最终拒绝单独触发账号并发 cooldown。32 MiB 为字节限制;不会自动裁剪对话/工具。源码合并、Release 与生产部署是独立状态。
Agent 使用声明
gpt-6.1-sol;推理强度未知(配置未提供)。gpt-6-astra、推理强度xhigh,监督者已通过 turn_context 独立核实;请求 fast,实际交付 tier 未确认。作者未启动子 Agent。01a1d32f-623e-7101-83aa-abcfde297d63;模型gpt-6-astra、推理强度xhigh,评审 turn_context 已核实。检查 pinned diff、未改调用方与控制流,先提出 L1/L2 并阻止通过;最终在 head 98cce61 逐项复核闭合,结论 clear-source,无 security/logic blocker。评审未执行动态检查或修改源码;远程执行证据由 Hermes 监督者另行验收。提交前自查