Skip to content

Conversation

@shangxueink
Copy link
Contributor

@shangxueink shangxueink commented Dec 28, 2025

Fix Satori WebSocket connection drops due to large message size

Add max_size parameter to websocket connection to handle larger messages and prevent connection drops when receiving large payloads from Satori platform.

修复 Satori WebSocket 因消息过大而断开连接的问题,通过增加 max_size 参数来支持接收更大的消息负载。

Motivation / 动机

修复了 Satori 适配器在接收大消息时出现的连接断开和无限重连问题。

问题描述:
当 Satori 服务器发送超过 1MB(默认限制)的 WebSocket 消息时,连接会因为 message too big 错误而关闭,导致适配器陷入无限重连循环。

错误日志:

[16:37:10] [Core] [WARN] [satori.satori_adapter:161]: Satori WebSocket 连接关闭: sent 1009 (message too big) frame with 2541903 bytes exceeds limit of 1048576 bytes; no close frame received

Modifications / 改动点

修改文件:

  • astrbot/core/platform/sources/satori/satori_adapter.py

具体改动:
connect_websocket() 方法中的 WebSocket 连接调用处(第 145-149 行),为 connect() 函数添加了 max_size 参数:

websocket = await connect(
    self.endpoint, 
    additional_headers={},
    max_size=10 * 1024 * 1024  # 10MB
)

功能说明:

  • 将 WebSocket 消息大小限制从默认的 1MB 提升到 10MB

  • 允许 Satori 适配器接收更大的消息负载

  • 防止因消息过大导致的连接断开和重连循环

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

修复前:

[16:37:08] [Core] [INFO] [satori.satori_adapter:137]: Satori 适配器正在连接到 WebSocket: ws://localhost:5140/satori/v1/events

[16:37:10] [Core] [WARN] [satori.satori_adapter:161]: Satori WebSocket 连接关闭: sent 1009 (message too big) frame with 2541903 bytes exceeds limit of 1048576 bytes

[16:37:15] [Core] [INFO] [satori.satori_adapter:137]: Satori 适配器正在连接到 WebSocket: ws://localhost:5140/satori/v1/events

[16:37:17] [Core] [WARN] [satori.satori_adapter:161]: Satori WebSocket 连接关闭: sent 1009 (message too big) frame with 2541903 bytes exceeds limit of 1048576 bytes

修复后:
连接稳定,不再出现 message too big 错误和无限重连问题。

 [16:46:34] [Core] [INFO] [satori.satori_adapter:137]: Satori 适配器正在连接到 WebSocket: ws://localhost:5140/satori/v1/events

 [16:46:34] [Core] [INFO] [satori.satori_adapter:138]: Satori 适配器 HTTP API 地址: http://localhost:5140/satori/v1

[2025-12-28 16:46:36 +0800] [11780] [INFO] 127.0.0.1:59442 GET /api/tools/mcp/servers 1.1 200 41 999

 [16:46:36] [Core] [INFO] [satori.satori_adapter:254]: Satori 连接成功 - Bot 1: platform=onebot, user_id=1787850032, user_name=猫猫不是喵喵

 [16:46:36] [Core] [INFO] [satori.satori_adapter:254]: Satori 连接成功 - Bot 2: platform=yunhu, user_id=37090343, user_name=小学云bot

 [16:46:36] [Core] [INFO] [satori.satori_adapter:254]: Satori 连接成功 - Bot 3: platform=yunhu, user_id=86297657, user_name=yunhu test bot

 [16:46:36] [Core] [INFO] [satori.satori_adapter:254]: Satori 连接成功 - Bot 4: platform=bilibili, user_id=312276085, user_name=叫我小学就好了

 [16:46:36] [Core] [INFO] [satori.satori_adapter:254]: Satori 连接成功 - Bot 5: platform=nextchat, user_id=nextchat, user_name=nextchat

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

Bug Fixes:

  • 防止 Satori WebSocket 连接在接收大于默认 1MB 限制的消息时被关闭并不断重新连接。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Prevent Satori WebSocket connections from closing and endlessly reconnecting when receiving messages larger than the default 1MB limit.

Add max_size parameter to websocket connection to handle larger messages
and prevent connection drops when receiving large payloads from Satori platform.
@auto-assign auto-assign bot requested review from Soulter and anka-afk December 28, 2025 08:50
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Dec 28, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出一些总体反馈:

  • 建议将 max_size 的值提取为命名常量或配置项,而不是内联字面量,这样就可以在不修改代码的情况下进行调整,并在其他使用 WebSocket 的地方保持一致。
给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- Consider making the `max_size` value a named constant or configuration option rather than an inline literal so it can be adjusted without code changes and stays consistent across any other WebSocket usages.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进后续的代码评审。
Original comment in English

Hey - I've left some high level feedback:

  • Consider making the max_size value a named constant or configuration option rather than an inline literal so it can be adjusted without code changes and stays consistent across any other WebSocket usages.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider making the `max_size` value a named constant or configuration option rather than an inline literal so it can be adjusted without code changes and stays consistent across any other WebSocket usages.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. label Dec 28, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 29, 2025
@Soulter Soulter merged commit 4f15102 into AstrBotDevs:master Dec 29, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants