Skip to content

修复:插件 2xx 业务错误不再变成空回答 - #434

Open
SsuJojo wants to merge 1 commit into
aimod-cc:betafrom
SsuJojo:fix/plugin-2xx-error-response
Open

SsuJojo wants to merge 1 commit into
aimod-cc:betafrom
SsuJojo:fix/plugin-2xx-error-response

Conversation

@SsuJojo

@SsuJojo SsuJojo commented Nov 2, 2026

Copy link
Copy Markdown

现象

testwhy0out 请求日志里状态码是 200,但响应正文只有:

{"type":"error","message":"上游未返回有效 Anthropic 消息"}
{"type":"response.failed","response":{"status":"failed","output":[]}}

客户端拿到的 output 为空,账号也没有进入限流冷却。

根因

ZCode 活动套餐通道对超额返回 HTTP 200 + application/json:

{"code":1005,"msg":"exceed quota limit"}

网关的 ProviderAdapter::is_error_response 默认只按 HTTP 状态码判定,
RpcAdapter 在控制面 RPC 失败时直接返回错误;成功路径则把 200 当成
SSE 交给 Anthropic 翻译层。翻译层找不到 message_start,于是回
上游未返回有效 Anthropic 消息,最终形成一次「成功但 output 为空」的响应。

修复

  • RpcAdapter::is_error_response_async 在插件 RPC 失败时回落到
    HTTP 状态码判定,不再让一次控制面超时中断整份请求,也避免误罚账号;
  • ProviderAdapter 的异步钩子补上契约说明,内置家行为不变;
  • 新增回归测试:
    • 200 + application/json 必须判为错误;
    • 200 + text/event-stream 仍判为成功;
    • 429 仍判为错误。

验证

  • cargo check -p agent2api-server 通过;
  • cargo test -p agent2api-server plugin_host::tests:13 passed。

上游 beta 的 provider_loop/tests.rs 与 api/pipeline.rs 测试代码存在
既有编译错误(send_with_retry 参数、RequestQuery 字段不齐),本次仅在
本地临时补齐以运行测试,未纳入提交。

🤖 本条回复由 AI Agent 生成

ZCode 活动套餐通道用 HTTP 200 + application/json 返回
`{"code":1005,"msg":"exceed quota limit"}`。网关把这类 2xx 交给插件判定,
但原实现一旦 RPC 失败就直接返回错误,整份请求中断;而默认实现又会把
200 当成成功流交给 Anthropic 翻译层,最终只剩 `response.failed`、
`output` 为空。

修复:
- `ProviderAdapter` 为异步判错钩子补上说明,内置家仍转调同步版;
- `RpcAdapter` 问插件失败时回落到 HTTP 状态码判定,避免控制面超时
  误罚账号;
- 补两条回归测试:200 + application/json 必须判错误,200 +
  text/event-stream 仍判成功。

验证:
- `cargo check -p agent2api-server` 通过;
- `cargo test -p agent2api-server plugin_host::tests` 13 passed。
  注:上游 beta 的 `provider_loop/tests.rs` 与 `api/pipeline.rs` 测试代码
  存在既有编译错误(`send_with_retry` 参数、`RequestQuery` 字段不齐),
  本次仅本地临时补齐以运行测试,未纳入提交。
@SsuJojo

SsuJojo commented Nov 2, 2026

Copy link
Copy Markdown
Author

PR 已就绪:base=beta,mergeable,改动 3 个文件(+101/-7),无冲突。

当前账号 SsuJojo 对 aimod-cc/Agent2API 只有 read 权限,gh pr merge 与 auto-merge 均返回 does not have the correct permissions to execute MergePullRequest,因此需要维护者点合并。

验证:cargo check -p agent2api-server 通过;cargo test -p agent2api-server plugin_host::tests 13 passed(含 200+JSON 判错用例)。

🤖 本条回复由 AI Agent 生成

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