Skip to content

fix(stream): TTFT 前武装下游 SSE 保活 (#429) - #445

Closed
dofastted wants to merge 1 commit into
mainfrom
cursor/stream-keepalive-arm-ttft-dfea
Closed

dofastted wants to merge 1 commit into
mainfrom
cursor/stream-keepalive-arm-ttft-dfea

Conversation

@dofastted

Copy link
Copy Markdown
Owner

背景

Closes #429 / REQ-0429

流式请求在首字(TTFT)到达前,下游 SSE 保活只调用了 keepalive.start(),armed 仍为 false,beat() 被守卫拦截,客户端长时间收不到任何字节;经 Cloudflare 等反向代理时约 120s 会返回 524。

改动

  • handle-protocol.mjs 流式 callAttempt 路径:将 keepalive.start() 改为 keepalive.arm()(内部仍会 start() 定时器,并立即 armed=true),使 ping/comment 在首字前也能按 stream_keepalive_ms 发出。
  • 回归单测:start() alone 在首事件前不写入;arm() 在 TTFT 前会 ping;源码断言流式 attempt 使用 arm()。
  • CHANGELOG.md → ## Unreleased(未改 VERSION)。

范围

  • 不涉及鉴权、计费、并发、公开 API、数据库迁移。

测试

  • node --test test/unit/stream-keepalive.test.mjs
  • npm run format:check(Biome 部分通过)
Open in Web Open in Cursor 

Streaming attempts only called keepalive.start(), leaving armed=false
so beat() never wrote until the first upstream SSE line. Use arm() so
ping/comment keepalives flow during long TTFT and avoid proxy 524s.

Co-authored-by: ted <kuhlmangarry24@gmail.com>

Copy link
Copy Markdown
Owner Author

已被 #448(v1.3.171 tip-cut)超集吸收(含 start→arm,并额外 ping 写出即 onCommit)。请勿再合;本 PR 可关。

@dofastted

Copy link
Copy Markdown
Owner Author

已由 #448 / v1.3.171 取代,本 PR 不再合并。

@dofastted dofastted closed this Oct 15, 2026
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.

[Bug] 流式请求在首字(TTFT)到达前未激活保活心跳,导致反向代理 120s 超时中断 (HTTP 524) (1.3.169)

2 participants