Skip to content

fix(memory): replace wall-clock timeout with per-chunk SSE liveness - #329

Merged
LeXwDeX merged 1 commit into
devfrom
fix/memory-sse-liveness
Aug 17, 2026
Merged

fix(memory): replace wall-clock timeout with per-chunk SSE liveness#329
LeXwDeX merged 1 commit into
devfrom
fix/memory-sse-liveness

Conversation

@LeXwDeX

Copy link
Copy Markdown
Owner

问题(Refs #324,解决其 streaming-liveness 半区)

#328RESPONSE_TIMEOUT 5min 墙钟兜底,但它与"思考即输出、输出即活着"的 SSE 原则相悖:墙钟无法区分"正在思考"与"连接已死",一条 16k-token 的慢思考随时可能被误杀。

修法

src/memory/model.ts

  • generateObjectstreamObject,让 chunk 可见(仓库先例:agent.ts 同款 fullStream 消费)。
  • 新增 drainWithLiveness:消费 fullStream每个到达的 part(含 reasoning delta)都重置 idle 看门狗——只要 SSE 还在推送,调用就活着,无论总时长多长。
  • 两个纯"无响应"检测器:CONNECT_TIMEOUT 60s(首个 part 未到达=死连接)与 IDLE_TIMEOUT 60s(chunk 间断流=卡死),触发即 abort 并失败为 TimeoutError
  • 生成终止仍由 max_output_tokens / 自然 stop 负责,不设整体墙钟。
  • make({timeout}) 注入仍保留(测试用硬期限);生产路径不再有默认墙钟。

边界覆盖(新增 4 个回归测试,it.live 真实计时)

  1. 持续吐流不被杀:30 个 part、每 8ms 一个、总时长 ~240ms ≫ 40ms idle 窗——每次到达重置计时,调用存活(证明无整体墙钟)。
  2. 静默 → idle 超时:吐 1 个 part 后挂起,idle 窗内无 chunk → Stalled,且 abort 钩子恰被调用一次。
  3. 死连接 → connect 超时:从不吐第一个 part → Stalled,且快速失败(<200ms)。
  4. 错误 part 透传:流中 error part 按原因失败,不误判为 stall。

验证

  • bun typecheck(packages/opencode)干净
  • test/memory/90 pass / 0 fail(其中 4 个为本次新增 liveness 回归)
  • compaction 相关套件 61 pass / 1 skip / 0 fail

说明

Retire the whole-call wall clock in favor of activity-based liveness on the memory model seam: switch generateObject -> streamObject and re-arm an idle watchdog on every arriving part (reasoning deltas included), so an actively streaming call is never killed however long the reasoning runs. Add a connect timeout (no first part) and an idle timeout (gap between parts), both pure non-response detectors; generation still terminates via max_output_tokens / a natural stop. Addresses the streaming-liveness half of #324; the periodic prepare lock hardening remains tracked there.
Sign up for freeto 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

@LeXwDeX