Repository navigation
fix(providers): 带图请求被拒时去图重发一次,413 按输入超限交接 - #408
Merged
Merged
Conversation
- 根因:isContextOverflow 只认正文里 context length 一类字样。网关回的 413(openresty 的 HTML 页、 带自定义错误码的 JSON)都不匹配,Core 把它当普通失败结束本批,下一批从同一份记录渲染出同样的 请求体,再次被拒,会话停在这里直到手动交接。 - 413 是请求体超过服务的大小上限,与正文怎么写无关;算作超限后由 Core 交接。 - errors.test 的 413 用例在改动前失败。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- 根因:带图请求被 400/413/422 拒收时,transport 和 Core 都不重试,本批结束;下一批从同一份记录 渲染出同样的图片,次次被拒。单张不合规的图(边长超限、解码不了)和累积超过请求体上限的历史 图片都会这样卡住。 - transport 加 ImageFallback,两个内建模块的 client 都套上:去掉这次请求的图片重发一次;被接受就 按句柄记下(只在内存里),之后不带,并在正文后补一行说明图没发出去;重发也被拒就带上两次尝试 交还,什么都不记。正常请求的字节不变,前缀缓存不受影响。 - 413 先去图再交给 Core 判超限:附件字节先撞请求体上限,token 计数几乎不动。去图后仍 413 由 Core 交接。 - 没选:另设请求体字节上限,网关的上限配置不出来;只去掉上次成功之后的新图,请求里图片数量变化 会改变旧图的边长上限,那时旧图才是原因,只去新图会卡在同一个请求上。 - image-fallback.test 经两个内建模块和本机假服务验证;改动前前三个用例失败。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- 根因:message() 建的用户消息正文是只有一段的数组,补说明时追加的是新的一段;Chat 把各段文字 直接拼接,说明就粘在 [blob …] 行末尾。 - 追加的段以换行开头。新用例经 llamacpp 走 Chat,改动前失败。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- 扩展 provider 的 client 没有套 ImageFallback:带图请求被 413 拒收时直接进交接,坏图的 400 每批原样再被拒。ProviderRegistry.bind 现在给每个实例套一层,图像开关取端点的 multimodal,contextOverflow 取模块的。 - bind 每次请求都跑,回落要记住被拒的句柄,所以按实例存一份(WeakMap),随实例重建。 - ProviderInstance.handlesRefusedImages:client 自己已经套了的实例声明它,bind 不再套。 两个内建模块声明;只给一部分记录附图的 client 要自己套并用 attached 交回那些记录。 - ImageFallbackOptions.contextOverflow 的参数改成 GenerationError,和 ProviderModule 的一致。 - 测试:经 bind 的带图请求被拒后去图重发一次,下一次 bind 不再带图(共一次请求); 声明了 handlesRefusedImages 的实例只发一次,拒收原样交回。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- 422 没有被拒的现场:400 有超过单边上限的 JPEG,413 有网关的请求体上限。集合里只留 这两个,注释和两份文档同改。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- 去图重发写在 docs/providers.md「传输」和 src/providers/README.md;交接页只留「413 也算 服务拒绝超长输入」。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
先前两条已不成立。422 被纳进去图重发 那条:REFUSED 现只含 400 与 413。交接页写了 provider 的去图重发 那条:docs/sessions.md 只留「413 请求体过大也算」。
— Cortico PR Gate via Cursor Cloud Agent
Sent by Cursor Automation: Cortico PR Gate
This was referenced Nov 12, 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.


Refs Pal-AI-Lab/Coopanion#552, Refs #372
问题
带图的请求被上游拒收后,会话停在同一个请求上:
isContextOverflow只认正文里 context length 一类字样,网关的 413 不匹配,Core 不交接。改动
前四个提交,顺序即依赖(后两个是按评审意见改的:去图重发不认 422、交接页不复述 provider 的回落):
isContextOverflow把任何 413 算作输入超限,由 Core 走现有的交接路径。src/providers/transport/image-fallback.ts的ImageFallback:带图请求回 413,或回 400 且模块的contextOverflow不认,去掉这次请求的图片重发一次。重发被接受,按句柄记下这些图(只在内存里),之后经这个 client 的请求都不带,每条失去图片的记录在正文后补一行imageLeftOut;重发也被拒,错误带上两次尝试,什么都不记。openai-responses-compat和llamacpp的 client 套上。ProviderRegistry.bind给没有声明ProviderInstance.handlesRefusedImages的实例套一层ImageFallback,扩展 provider 不用各自改就有这层回落。bind每次请求都跑,回落要记住被拒的句柄,所以按实例存一份,随实例重建。两个内建模块声明handlesRefusedImages,不套两层;只给一部分记录附图的 client 自己套,用attached交回附了图的记录。合起来的顺序:带图的 413 先去图重发;去图后仍 413,或请求里本来没有图,按输入超限交接。正常请求的字节不变。
文档:
docs/providers.md「传输」、src/providers/README.md;docs/sessions.md只补「413 也算服务拒绝超长输入」。取舍
ProviderInstance加的是可选字段,provider 契约版本不动。验证
pnpm test、pnpm run typecheck、pnpm run typecheck:web通过。tests/providers/transport/image-fallback.test.ts经两个内建模块和本机假服务;tests/providers/registry.test.ts新增两条:经bind的带图请求被拒后去图重发一次、下一次bind不再带图(共一次请求);声明了handlesRefusedImages的实例只发一次,拒收原样交回。合入后
Coopanion 升子模块时,
packages/cortico-provider-coo改用这里的ImageFallback(attached传它的sinceLastDelivery)并声明handlesRefusedImages,删掉自己那份。🤖 Generated with Claude Code