Bug: Responses terminal failures are recorded as successful EOF and preserve channel affinity
Read This First (Do Not Remove This Section)
- Docs: https://docs.newapi.ai/
- Usage questions first: https://deepwiki.com/QuantumNous/new-api
- This report isolates behavior introduced by new-api by comparing the same redacted standard OpenAI Responses SSE failure directly from the upstream with new-api's downstream response and internal server logs.
- This is not a pass-through, Coding Plan, reverse-engineered channel, third-party wrapper, or Codex-specific protocol report. The reproduction uses the standard
POST /v1/responsesstreaming protocol through an OpenAI channel.
Deployment source
Repository release / official image (self-hosted)
Your current newapi version
v1.0.0-rc.22 (bc14c18f6024e79cba1c08d02cd007796e12d668)
Submission Checks
- [x] Non-duplicate issue: I searched open and closed Issues and PRs for
response.failed,model_at_capacity, and the exact capacity message. #3142 is related but only covers returning a non-200 error before the first downstream write; this report covers failure classification and affinity/health handling after the SSE response has already started. Its companion PR #3143 was closed without merge. - [x] Read this first: I reviewed the documentation, README, issue template, #3142, and #3143. This is not a usage, configuration, or integration question.
- [x] Supported version: The behavior was reproduced on the unmodified official
v1.0.0-rc.22image identified above. - [x] Not a third-party service: The affected new-api instance uses the official image. The upstream is represented by a standard OpenAI-compatible mock/event sequence in the reproduction below.
- [x] Issue attribution: The upstream and client correctly expose the terminal
response.failedevent. The new-api-specific failure is that its internal stream outcome, channel health, and affinity state treat that event as a successful EOF. - [x] Channel and protocol boundary: The reproduction uses a standard OpenAI channel and standard OpenAI Responses SSE events, with pass-through disabled. It does not depend on a Codex-specific request or client.
- [x] Maintainer time: The report includes a minimized event sequence, sanitized server evidence, impact, expected behavior, and the related existing issue.
Issue Description
Actual behavior
For a streaming POST /v1/responses request, an OpenAI-compatible upstream establishes HTTP 200, emits normal lifecycle events, and then emits this terminal event:
event: response.failed
data: {"type":"response.failed","response":{"status":"failed","error":{"type":"server_error","code":"model_at_capacity","message":"Selected model is at capacity. Please try a different model."}}}
Direct upstream result:
- HTTP 200 establishes the SSE stream.
- The client receives
response.failedand the structuredmodel_at_capacityerror. - The upstream then closes the stream.
Result through new-api:
- The same terminal event is forwarded to the client, so the client correctly sees the capacity error.
- Internally, new-api records
stream ended: reason=eof. - The consume log records
stream_status={"status":"ok","end_reason":"eof"}with zero input/output tokens. - The request is recorded as HTTP 200 with a generic zero-usage billing warning.
- No structured channel failure reaches the normal channel error handling path.
- The current channel affinity remains active. A subsequent request with the same affinity key selects the same channel again and can immediately receive the same capacity failure.
Sanitized logs from two consecutive requests on the official image:
stream ended: reason=eof
total tokens is 0, cannot consume quota, model gpt-5.6-sol
record consume log: prompt_tokens=0, completion_tokens=0,
stream_status={"end_reason":"eof","status":"ok"}
POST /v1/responses -> 200
# Next request with the same affinity key:
stream ended: reason=eof
total tokens is 0, cannot consume quota, model gpt-5.6-sol
record consume log: prompt_tokens=0, completion_tokens=0,
stream_status={"end_reason":"eof","status":"ok"}
POST /v1/responses -> 200
The two failures completed in approximately 10 seconds and 25 seconds. The same channel also completed another request successfully between them with non-zero usage. This rules out a fixed local timeout or permanent channel outage and is consistent with a transient upstream capacity event.
Impact
- Retry-capable clients can remain pinned to the same transiently unhealthy route.
- Channel health and cooldown logic receive no failure signal.
- Operational logs label a protocol failure as a successful EOF.
- The generic zero-usage billing warning is misleading; it is a consequence of the unclassified terminal event, not evidence of a timeout.
Frequency
Observed repeatedly under intermittent upstream capacity pressure, including two consecutive failures for the same affinity key in less than one minute.
Evidence that the issue is in new-api
The upstream event and downstream client-visible event agree: both contain response.failed with model_at_capacity. The divergence is entirely inside new-api: its direct Responses handler does not convert that terminal event into a structured stream failure, so the generic scanner treats the following EOF as success and the controller never invokes channel failure/affinity cleanup.
This is related to #3142, but it remains relevant even when downstream SSE bytes have already been committed and the HTTP status can no longer be changed.
Steps to Reproduce
-
Run the unmodified official
v1.0.0-rc.22image. -
Configure two eligible standard OpenAI channels for the same model, with pass-through disabled and channel affinity enabled for a stable request field such as
prompt_cache_key. -
Make the preferred channel return HTTP 200 with the following SSE sequence:
event: response.created data: {"type":"response.created","response":{"id":"resp_test","status":"in_progress"}} event: response.failed data: {"type":"response.failed","response":{"id":"resp_test","status":"failed","error":{"type":"server_error","code":"model_at_capacity","message":"Selected model is at capacity. Please try a different model."}}} -
Send a streaming
POST /v1/responsesrequest through new-api using a stable affinity value. -
Confirm that the client receives the failure event, while new-api records HTTP 200, successful EOF, and zero usage.
-
Send the same request again with the same affinity value.
-
Observe that the same failed channel remains preferred rather than being cleared/excluded as a transient route failure.
The minimal protocol trigger is any terminal response.failed, response.error, response object with status=failed, or non-empty response error object followed by EOF.
Expected Result
- Direct Responses streaming should recognize terminal failure event shapes and retain a structured stream outcome after bytes have been committed.
- The original SSE terminal event must still be forwarded exactly once; new-api must not append a JSON error after committing SSE or transparently replay a partially started stream.
- Stream logs should report an error outcome rather than
status=ok, end_reason=eof. - Transient capacity/overload/temporary 429/5xx failures should reach channel health handling, clear the current affinity, and temporarily exclude only the failed route so the next request can select another eligible channel.
- Request-specific failures such as invalid parameters or context length should be recorded without penalizing channel health.
- If a failure event includes real usage, settlement should preserve that usage; zero usage should remain zero.
Related Screenshots
Not applicable. All evidence is protocol and server-log based; sensitive request, user, IP, channel, and credential details have been removed.
[Bot Review]
感谢提交。这个 issue 已包含版本信息、提交确认、问题描述和复现步骤,格式上比较完整。
你提到的 #3142 看起来是相关背景;从当前提供的 open issues 列表看,没有发现可以直接判定为重复的 open issue。
https://github.com/QuantumNous/new-api/pull/6549
会在这个PR进行处理
什么时候修复这个bug呀,着急
这个问题影响了new api代理codex类型账号的整体成功率,因为决定了当上游报这个错误时new api未能识别到错误就不会自动在其它账号做重试导致了最终请求模型成功率直线下降
什么时候才能修改呀,这都一个多月了
这个问题影响了new api代理codex类型账号的整体成功率,因为决定了当上游报这个错误时new api未能识别到错误就不会自动在其它账号做重试导致了最终请求模型成功率直线下降
这个重试不了,只能标记错误信息,流错误的重试需要客户端重试
+1,期待抓紧合并,
补充当前版本的排查结果:日志已经能显示流失败,但渠道自动禁用这条路径仍可能被跳过。理解上面维护者的说明:流开始后的重试应由客户端完成;这里希望确认的是服务端渠道健康处理。
- 实际部署版本:
v1.0.0-rc.44,普通 OpenAI 渠道,未开启请求体/请求头透传,原生POST /v1/responses、stream=true。 - 全局“失败时禁用”和渠道“异常自动禁用”均开启,自动禁用状态码包含
429。 - 上游额度耗尽期间,同一渠道连续出现零用量的 Responses 请求:日志为
stream_status.status=error、end_reason=eof,决策为stream_not_successful,每条只有一次渠道尝试,渠道没有因这些流失败自动停用。Chat Completions 测试触发 HTTP 429 时可以自动禁用。 - 限制:没有保留上述生产请求的原始 SSE/HTTP 报文,因此不把客户端报告的“429”直接等同于这些请求的原始 HTTP 状态,也没有在新版本上做运行时复现。以下是独立的源码核对结果。
v1.0.0-rc.51 中相关路径仍然是:
OaiResponsesStreamHandler第 102–104 行:记录流状态后return accumulator.Finish(), nil。ObserveResponsesOutcome第 130–140 行:流内error/response.failed只MarkFailed(code, errorType, 0)。Relay第 247–258 行:错误为 nil 时记录策略后直接 return,不进入ProcessChannelError。MarkRequestPolicySuccess第 129–144 行:只记录stream_not_successful,不执行渠道禁用。
因此,明确的流内余额不足/鉴权失败,即使可识别,也无法经过标准 ShouldDisableChannel 规则处理。#7956 修复的是完成事件后的收尾误判,没有补上这条路径。
能否让明确的上游流内错误进入渠道健康/自动禁用判断,并保留错误码及可用的状态信息?自动禁用应与当前流的重试分开处理;裸 EOF、客户端取消、输出预算截断或普通临时限流也不应一律按余额不足停用。建议回归覆盖 HTTP 429、HTTP 200 + response.failed/error、无终态 EOF 和正常 completed。