Skip to content

fix: make stream lifecycle cancellation-safe - #79

Merged
typefield merged 2 commits into
open-dingtalk:mainfrom
typefield:agent/fix-stream-lifecycle
Jul 30, 2026
Merged

fix: make stream lifecycle cancellation-safe#79
typefield merged 2 commits into
open-dingtalk:mainfrom
typefield:agent/fix-stream-lifecycle

Conversation

@typefield

@typefield typefield commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

修复 Stream 生命周期、重连、消息去重、任务上限和发布兼容性问题:

  • CancelledError 正确传播,增加异步 stop(),停止可中断重连等待
  • 连接正常关闭和异常关闭统一使用 1–60 秒指数退避 + jitter;收到服务器帧后重置
  • 跟踪、取消并限制后台 handler 任务;忽略取消的任务仍计入全局上限
  • keepalive 与 handler 绑定来源 websocket,ACK 不会写入替代连接
  • EVENT/CALLBACK 按 messageId 合并并发重复处理,成功 ACK 使用有界 TTL cache
  • SYSTEM 控制帧不跨连接去重,避免旧 disconnect 影响新连接
  • 集成 Allow configuring websocket connect options #74websocket_connect_options,并防御调用方后续修改 options
  • blocking connection-open 请求移出 event loop,HTTP 请求增加 timeout
  • 非法 JSON 仅跳过当前帧;日志保留 traceback 且不再发生格式化二次崩溃
  • 删除示例中的危险 eval
  • Python 要求明确为 >=3.8,版本升级至 0.24.4
  • CI 覆盖 Linux Python 3.8–3.14、Windows 3.10/3.14,并更新发布工作流

Related issues and PRs

Closes #46.
Refs #52.
Refs #54.
Closes #60.
Closes #63.
Closes #65.
Closes #68.
Closes #75.
Closes #76.
Refs #77.

Supersedes the lifecycle/task-tracking scope of #67 and #72, and includes #74.

Validation

  • Python 3.8–3.14 unit tests
  • Python 3.14 full suite连续 50 轮
  • asyncio debug + ResourceWarning strict mode
  • wheel metadata: version、Requires-Python、Python 3.14 classifier
  • compileallactionlintgit diff --check

@wxianfeng

Copy link
Copy Markdown

CR 结论:LGTM,未发现阻断项。

已核对 head 9efbbf3。重点审查了可取消重连、stop() 退出路径、HTTP/WebSocket 超时、后台任务与 orphan 全局上限、来源 WebSocket ACK、消息去重/成功结果缓存,以及 SYSTEM frame 不跨连接去重。异常与取消语义一致,兼容接口保留合理。

本地验证(macOS / Python 3.13.3):

  • python -m unittest discover -s tests -v:12/12 通过
  • python -m compileall -q dingtalk_stream tests examples 通过

GitHub CI:9/9 通过。

@typefield
typefield marked this pull request as ready for review July 30, 2026 12:23
@typefield
typefield merged commit 67c3f72 into open-dingtalk:main Jul 30, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants