Skip to content

fix(providers): 被拒的请求去掉所有附件重发,ImageFallback 改名 AttachmentFallback - #423

Merged
Phantivia merged 2 commits into
mainfrom
fix/attachment-fallback
Nov 19, 2026
Merged

Phantivia merged 2 commits into
mainfrom
fix/attachment-fallback

Conversation

@Phantivia

Copy link
Copy Markdown
Member

带附件的请求被上游以 413 拒收,或以 400 拒收且不是上下文超限时,回落层现在去掉这次请求带上的所有附件重发一次,不再只去图片。

为什么

回落层只把图片算作请求带上的附件。Coopanion 的 Gemini 端点从 v0.2.21 起还发音频、视频、PDF 和纯文本;请求因为一份 PDF 或一段录音被拒时,去完图片仍然超,最后 413 走交接或 400 直接失败。Coopanion 为此在 Gemini 那条路上另加了一套「发送前 18 MiB 额度」,那套额度又引出了 Pal-AI-Lab/Coopanion#741 的问题(旧 PDF 占满额度、新截图只剩文字行)。回落层管所有附件之后,Coopanion 那边可以删掉这套预筛,和其他协议一样被拒再去附件。

两个提交(请用 rebase 合并,保留两步)

  1. refactor(providers):ImageFallback → AttachmentFallback(image-fallback.ts → attachment-fallback.ts),imageLeftOut → attachmentLeftOut,withoutImages → withoutAttachments,handlesRefusedImages → handlesRefusedAttachments。行为不变。
  2. fix(providers):新增 accepts 选项(client 会发的附件类型,不给只算图片);ProviderRegistry.bind 套的那层取模块的 accepts,和 Core 判断模型收哪些类型用同一个函数。说明行改说「这份附件」。

兼容

  • 改名会影响用到这几个名字的 provider。市场上 9 个第三方 provider 包(npm 最新版)都没有用到;用到的只有 Cortico 的两个内建模块和 Coopanion 的 provider-coo,provider-coo 的跟进在 Coopanion 的配套 PR 里,随子模块升级一起改。
  • 内建模块只发图片,不给 accepts,行为和以前一样。

检查

  • pnpm test:292 个文件、5227 条通过,4 条跳过(rebase 到 9609ddc 之后又跑了 tests/providers 和 tests/core:623 条通过)。
  • pnpm run typecheck 通过。
  • 新测试 drops an attachment of another type the module accepts… 在改动前失败、改动后通过;does not retry for an attachment type the module does not accept… 挡住把没发出去的附件也算进去。

没验证的

Gemini 因为请求体超限拒收时回 413 还是 400,没有用真服务验过;两种都会触发重发,只要 400 不被模块的 contextOverflow 认作上下文超限。

🤖 Generated with Claude Code

Comment thread docs/providers.md Resolved
- image-fallback.ts 改名 attachment-fallback.ts;imageLeftOut、withoutImages、
  handlesRefusedImages 跟着改成 attachment 的叫法。
- 下一个提交让它管请求带上的所有附件,名字先改,免得行为和名字对不上。
- 市场上的第三方 provider 包都没有用到这几个名字。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Phantivia
Phantivia force-pushed the fix/attachment-fallback branch from 3a1b0d3 to 6c894df Compare November 19, 2026 04:39
- 根因:AttachmentFallback 只把图片算作请求带上的附件,请求因为一份 PDF 或一段录音被拒时
  去完图片仍然超,最后 413 走交接或 400 直接失败。
- 新增 accepts 选项:client 会发的附件类型,不给只算图片(框架内建的 client 只发图片)。
  ProviderRegistry.bind 套的那层取模块的 accepts,和 Core 判断模型收哪些类型用的是同一个函数。
- 说明行 attachmentLeftOut 改说「这份附件」;日志字段 images 改 attachments。
- 测试:模块收的非图片附件被拒后去掉重发、之后不再带;模块不收的类型 client 没发过,不重发。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Phantivia
Phantivia force-pushed the fix/attachment-fallback branch from 6c894df to a33db35 Compare November 19, 2026 04:52

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

先前 这条 Accuracy after editing 已不成立:当前 docs/providers.md 把 accepts 写在 ProviderRegistry.bind 会套上的那一层,声明了 handlesRefusedAttachments 时不再提它。

— Cortico PR Gate via Cursor Cloud Agent

Open in Web View Automation 

Sent by Cursor Automation: Cortico PR Gate

@Phantivia
Phantivia merged commit 8f5c52f into main Nov 19, 2026
4 checks passed
@Phantivia
Phantivia deleted the fix/attachment-fallback branch November 19, 2026 04:57
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.

1 participant