Skip to content

fix(aiocqhttp): correct listener lifecycle handling#2336

Merged
RockChinQ merged 2 commits into
langbot-app:masterfrom
StevenQinDev:bpp/fix-aiocqhttp-listener-lifecycle
Jul 13, 2026
Merged

fix(aiocqhttp): correct listener lifecycle handling#2336
RockChinQ merged 2 commits into
langbot-app:masterfrom
StevenQinDev:bpp/fix-aiocqhttp-listener-lifecycle

Conversation

@StevenQinDev

@StevenQinDev StevenQinDev commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

概述 / Overview

修复 aiocqhttp 适配器中三个关联的监听器生命周期问题:

  • 每个 adapter 只注册一个 WebSocket connection observer,避免 RuntimeBot 初始化时产生三个重复 subscriber。
  • 修正连接事件去重逻辑,正确比较缓存事件和传入事件。
  • 保存 aiocqhttp 内部 message wrapper,使 unregister_listener() 能移除实际订阅的 callback,而不是抛出 NotImplementedError
  • 增加回归测试,覆盖 subscriber 数量、精确连接去重和 listener 注销。

Fixes three related listener-lifecycle issues in the aiocqhttp adapter:

  • Register one WebSocket connection observer per adapter instance.
  • Compare cached connection events against the incoming event.
  • Retain internal message wrappers so unregister_listener() removes the actual aiocqhttp callback.
  • Add regression tests for subscriber count, exact connection deduplication, and listener removal.

更改前后对比截图 / Screenshots

修改前 / Before:

Before: three connect subscribers and unregister_listener raising NotImplementedError

修改后 / After:

After: one connect subscriber, successful unregistration, and 23 passing tests

检查清单 / Checklist

PR 作者完成 / For PR author

  • 阅读仓库贡献指引了吗? / Have you read the contribution guide?
  • 我已签署或将在机器人提示后签署 CLA。 / I have signed, or will sign when prompted by the bot, the CLA.
  • 与项目所有者沟通过了吗? / Have you communicated with the project maintainer?
  • 我确定已自行测试所作的更改,确保功能符合预期。 / I have tested the changes and ensured they work as expected.

项目维护者完成 / For project maintainer

  • 相关 issues 链接了吗? / Have you linked the related issues?
  • 配置项写好了吗?迁移写好了吗?生效了吗? / Have you written the configuration items? Have you written the migration? Has it taken effect?
  • 依赖加到 pyproject.toml 和 core/bootutils/deps.py 了吗 / Have you added the dependencies to pyproject.toml and core/bootutils/deps.py?
  • 文档编写了吗? / Have you written the documentation?

验证 / Verification

  • uv run pytest tests/unit_tests/platform/test_aiocqhttp_message_converter.py -q (23 passed)
  • uv run pre-commit run --files src/langbot/pkg/platform/sources/aiocqhttp.py tests/unit_tests/platform/test_aiocqhttp_message_converter.py
  • git diff --check

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. eh: Improve enhance: 现有功能的改进 / improve current features IM: aiocqhttp OneBot 协议适配器相关 / OneBot adapter related m: Lifecycle 启动/关闭流程 / Bootstrap & application life cycle m: Platform 机器人管理相关 / Bots management labels Jul 13, 2026
@RockChinQ

Copy link
Copy Markdown
Member

Thanks for your contribution. Please use the PR template to file the PR, and attach the screenshot that proves your code works well.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.35294% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/langbot/pkg/platform/sources/aiocqhttp.py 82.35% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@RockChinQ
RockChinQ merged commit 2c3e52c into langbot-app:master Jul 13, 2026
10 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 13, 2026
@StevenQinDev
StevenQinDev deleted the bpp/fix-aiocqhttp-listener-lifecycle branch July 13, 2026 05:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

eh: Improve enhance: 现有功能的改进 / improve current features IM: aiocqhttp OneBot 协议适配器相关 / OneBot adapter related m: Lifecycle 启动/关闭流程 / Bootstrap & application life cycle m: Platform 机器人管理相关 / Bots management size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants