Skip to content

feat(infra): SSE 心跳 + 超时保护 #263

Description

@jerry609

关联 Epic

Closes part of #245

问题描述

studio_chat.py:517 有 15s keepalive 外,其他 SSE 端点无心跳机制。长时间运行的 paper analysis 或 code generation 过程中,nginx/cloudflare 可能因空闲超时断连。

此外 wrap_generatorstreaming.py:151-171)中:

  • 未捕获 asyncio.CancelledError(Python 3.8+ 是 BaseException)
  • 缺少 finally 块确保 generator 关闭
  • 未设 X-Accel-Buffering: no header

修复方案

  • wrap_generator 中添加周期性 :comment\n\n 心跳(SSE 标准注释行,每 15s)
  • 添加 asyncio.timeout() 包装,默认 30 分钟可配置
  • 捕获 asyncio.CancelledError 并在 finallyaclose() generator
  • SSE 响应添加 X-Accel-Buffering: no header

验收标准

  • SSE 连接每 15s 发送心跳
  • 超时后正确终止并清理
  • 客户端断连时资源正确释放

Metadata

Metadata

Assignees

Labels

P1Priority 1 - ImportantbackendBackend/API related workinfraInfrastructure and platform operationsphase-3Roadmap phase 3

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions