Skip to content

长任务流式零字节挂起:上游接受请求后不吐首 token,客户端重试数次后放弃,任务中断需手动「继续」 #42

Closed

Description

@moonjoke001

环境

  • 版本:v1.3.3(v1.3.4/v1.3.5 changelog 未见相关改动,应同样存在)
  • 部署:Docker,出站经本地代理,匿名通道为主
  • 模型:muse-spark-1.3-contributor-free(free tier,reasoning 型)
  • 使用方:Claude Code 跑长 agent 任务,上下文约 150K,走 /v1/chat/completions 流式

现象

agent 任务执行到一半流中断,模型侧没有任何输出到达客户端,agent 停止等人工输入,必须手动说「继续」才能恢复;一次长任务里反复发生。

日志证据(2026-09-22 一次任务窗口,共 424 请求 / 420 条同模型匿名通道)

形态一(13 次):client_canceled,零 token

06:59:17 outcome=client_canceled status=200 stream=true in=0 out=0 reasoning_tokens=0 dur=29936ms attempts=1
07:01:55 outcome=client_canceled status=200 stream=true in=0 out=0 reasoning_tokens=0 dur=6753ms  attempts=1
07:02:27 outcome=client_canceled status=200 stream=true in=0 out=0 reasoning_tokens=0 dur=6646ms  attempts=1
07:02:29 outcome=client_canceled status=200 stream=true in=0 out=0 reasoning_tokens=0 dur=7918ms  attempts=1
07:02:32 outcome=client_canceled status=200 stream=true in=0 out=0 reasoning_tokens=0 dur=3977ms  attempts=1
07:03:09 outcome=client_canceled status=200 stream=true in=0 out=0 reasoning_tokens=0 dur=5252ms  attempts=1

上游已接受请求、SSE 已建立,但一个 token 都没有下发;客户端(agent 框架自带超时)等不到首事件,4–30s 后主动断开重试。07:02:27→07:02:29→07:02:32 两秒间隔连环重试全部同样挂死,最终 agent 放弃本轮,等人工「继续」。

形态二(1 次):stream_error,同样零 token

06:17:10 outcome=stream_error status=200 stream=true in=0 out=0 reasoning_tokens=0 dur=46931ms attempts=1

46.9s 零输出后流报错。

分析

  • 同窗口内成功请求正常(dur 6–17s,in≈150K cached≈150K),说明不是持续性的网络/代理问题,而是上游 free tier 间歇性「收下请求后长时间不发首事件」(疑似软限流:不返回 429,直接挂住)。
  • 网关侧对「流已建立但零首事件」没有独立超时:attempt_timeout_seconds=0 时单次尝试兜底是 retry.timeout_seconds(300s),远超客户端耐心,客户端永远先放弃;attempts=1 也说明挂死期间网关没有机会换出口透明重试。
  • 结果就是把上游的间歇挂死原样透传给 agent 客户端,表现为任务中断、需要人工「继续」。

建议

  1. 流首事件看门狗:流式 attempt 建立后若 N 秒(如 10–15s,可配置 first_event_timeout_seconds)未收到首个 SSE 事件,判定该 attempt 挂死,中止并在网关内透明重试(新 session/换出口),对客户端无感。零 token 挂死与「已发部分内容后中断」不同,前者可以安全重放整个请求。
  2. 中途流错误时按目标协议补发结构化错误事件(Chat 目标 data: {"error": ...};Anthropic 目标 event: error),给客户端重试依据——与 跨协议转换健壮性:delta.reasoning 不识别、上游错误被映射为正常结束/断流、流式 redacted_thinking 丢失 #11 第 3 点同方向。

感谢维护!

Activity

  1. jasonxu114514 commented on Sep 25, 2026

    @jasonxu114514
    Owner

    尝试使用其他模型呢,另外agent通常会等待响应的 3-5分钟都会出现,我偏向是网络问题

  2. moonjoke001 commented on Sep 25, 2026

    @moonjoke001
    Author

    尝试使用其他模型呢,另外agent通常会等待响应的 3-5分钟都会出现,我偏向是网络问题

    感谢回复!

  3. added a commit that references this issue on Oct 7, 2026
  4. jasonxu114514 commented on Oct 7, 2026

    @jasonxu114514
    Owner

    v1.3.6 新增 performance.first_event_timeout_seconds,可通过配置文件或 WebUI 设置。

    默认 0 保持旧行为;遇到这类上游收下请求却不发事件的情况,可尝试设置为 15 秒。成功的 SSE 响应会先等待完整 data 事件,注释心跳和未完成的事件不计入;在交付客户端之前超时或断开时,沿用现有 Key/代理重试及请求总超时预算。开始向客户端交付后不重放,避免重复内容。单匿名出口且没有其他可用 Key 时,仍可能耗尽尝试而返回超时。

    已有的协议化流错误事件继续保留;新增回归验证了首事件超时、客户端取消、重试前不输出、原始 SSE 字节保留及首事件后不误触发超时。此设置限制的是首事件而非首个文本 token;轮转别名使用独立 first_output_seconds,System One 原样转发不适用此看门狗。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions