Skip to content

fix: 400 JSON node 上限单独分类,不再落入通用拒绝(#96) - #97

Merged
Mars-Sea merged 2 commits into
mainfrom
fix/json-node-limit-error
Oct 21, 2026
Merged

Mars-Sea merged 2 commits into
mainfrom
fix/json-node-limit-error

Conversation

@Mars-Sea

@Mars-Sea Mars-Sea commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

问题 / Problem

Fixes #96.

网关以 400 拒绝 JSON node count cannot exceed 32768 时,generateHttpError 里没有分支命中它,最终落入通用拒绝:界面只剩有界标识,上游那句点名真正上限的话被丢弃,用户无从下手。

The gateway's JSON node count cannot exceed 32768 rejection matched no branch in generateHttpError and fell through to the generic refusal, which drops the upstream sentence entirely — users got no actionable guidance.

改动 / Changes

  • src/provider-errors.ts:新增 JSON_NODE_LIMIT_REJECTION,在上下文溢出分支之后加专用分支。这是结构上限、不是 token 上下文超长:文案中英双语写明上限数值、明确「压缩上下文通常不足以降到该上限以内」,建议新建会话或减少消息与图片;失败码保持 PROVIDER_HTTP_ERROR(不重试、不触发压缩、不轮换账号)。上游原文仍按该函数既有的隐私设计不回显,只引用其给出的上限数字——因此未采纳报告人的方案 2(附上游原文)。
  • tests/adapter.test.ts:回归测试(Messages 通道 400,采用 issue 400 JSON node count cannot exceed 32768 被归到通用拒绝,上游原文被丢弃 #96 的双层转义真实报文,断言失败码、文案含 32768 与双语「通常不足」、且只发 1 次请求)。
  • lib/index.js:已重新构建。

A dedicated branch after the context-overflow branch in generateHttpError: the cap is on the request's JSON structure, not its token length, so the bilingual copy names the stated limit, says compacting usually will not be enough, and advises a new session or fewer messages/images. Failure code stays PROVIDER_HTTP_ERROR.

验证 / Verification

  • npm run typecheck 干净 / clean
  • npm test 1059/1059 通过 / passing
  • npm run build 成功 / OK

Mars-Sea and others added 2 commits October 21, 2026 12:47
generateHttpError 新增 JSON_NODE_LIMIT_REJECTION 分支(位于上下文溢出分支之后):网关的 JSON 节点数上限是结构限制、不是 token 上下文超长,文案中英双语写明上限数值与「压缩上下文无效」,失败码保持 PROVIDER_HTTP_ERROR(不重试、不轮换账号),上游原文仍按既有隐私设计不回显、只引用其给出的上限。

tests/adapter.test.ts 新增回归测试;lib/index.js 已重新构建。

验证:typecheck 干净,npm test 1059/1059,npm run build 成功。
- 文案:压缩上下文「无效」过于绝对。压缩会减少消息条数与 content part 数,
  节点数可能因此降到上限以内,改为「压缩上下文通常不足以降到该上限以内」/
  "compacting the session usually will not be enough",与 issue 报告人的「通常无效」
  一致,避免误导用户放弃可能有效的 /compact。
- 测试:改用 issue #96 的真实响应体形态(error.message 为内层转义 JSON 字符串,
  点名上限的句子只存在于 ParsedProviderError.rawMessage),替代此前只覆盖单层
  message 的构造,防止 unwrap 路径退化后回归测试仍然全绿。
- JSON_NODE_LIMIT_REJECTION 改为模块内常量(全仓无外部引用)。
- 分支内 test() 与 exec() 合并为一次 exec,nodeLimit 自然收窄为 string。

验证:npm run typecheck 干净;npm test 1059/1059;npm run build 后 lib/ 仅有
index.js 按预期更新;用 issue #96 原始报文回放命中新分支,失败码仍为
PROVIDER_HTTP_ERROR(不重试、不触发压缩、不轮换账号)。
@Mars-Sea
Mars-Sea merged commit cc26490 into main Oct 21, 2026
5 checks passed
@Mars-Sea
Mars-Sea deleted the fix/json-node-limit-error branch October 21, 2026 06:34
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.

400 JSON node count cannot exceed 32768 被归到通用拒绝,上游原文被丢弃

1 participant