Skip to content

Conversation

@stevessr
Copy link
Contributor

@stevessr stevessr commented Jan 9, 2026

增强代码健全性,session_id可能包含冒号(如matrix的房间)

Modifications / 改动点

astrbot/core/platform/message_session.py

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

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

image

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

错误修复:

  • 修复会话字符串的解析方式,使包含冒号的会话 ID 能被正确处理,而不会被错误地拆分成额外的片段。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Fix parsing of session strings so that session IDs containing colons are handled correctly instead of being split into extra segments.

Copilot AI review requested due to automatic review settings January 9, 2026 02:40
@auto-assign auto-assign bot requested review from LIghtJUNction and Soulter January 9, 2026 02:40
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jan 9, 2026
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 - 我在这里给出了一些高层次的反馈:

  • 建议在 from_str 中添加一些基本的校验或错误处理(例如检查分割结果的长度),这样当会话字符串格式不正确时,可以抛出比 split 默认产生的 ValueError 更清晰的错误。
  • 可以在注释或文档字符串中简单说明一下:session_id 是允许包含 : 的,并且使用 split(":", 2) 是有意为之,用来确保剩余部分被保留为 session ID。
面向 AI Agent 的提示词
Please address the comments from this code review:

## Overall Comments
- Consider adding minimal validation or error handling in `from_str` (e.g., checking the split result length) so malformed session strings fail with a clearer error than the default `ValueError` from `split`.
- It may be helpful to briefly document in a comment or docstring that `session_id` is allowed to contain `:` and that `split(":", 2)` is intentional to preserve the remainder as the session ID.

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

Hey - I've left some high level feedback:

  • Consider adding minimal validation or error handling in from_str (e.g., checking the split result length) so malformed session strings fail with a clearer error than the default ValueError from split.
  • It may be helpful to briefly document in a comment or docstring that session_id is allowed to contain : and that split(":", 2) is intentional to preserve the remainder as the session ID.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding minimal validation or error handling in `from_str` (e.g., checking the split result length) so malformed session strings fail with a clearer error than the default `ValueError` from `split`.
- It may be helpful to briefly document in a comment or docstring that `session_id` is allowed to contain `:` and that `split(":", 2)` is intentional to preserve the remainder as the session ID.

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 Jan 9, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where MessageSession.from_str() would incorrectly parse session strings when the session_id component contains colons, such as Matrix room IDs (e.g., !roomid:server.com).

Key change:

  • Modified split(":") to split(":", 2) to limit splitting to the first two colons, allowing the session_id to contain colons

@Dt8333
Copy link
Member

Dt8333 commented Jan 10, 2026

#3624 #3634

合并后也许可以回退#3634

另:想到一个问题
会不会有人在PlatformID里塞:

@Soulter
Copy link
Member

Soulter commented Jan 11, 2026

#3624 #3634

合并后也许可以回退#3634

另:想到一个问题 会不会有人在PlatformID里塞:

我觉得我们应该避免这种情况发生,创建 platform 的时候不允许 :,以及 platform/manager.py 做一个兜底策略,发现冒号之后先改为其他字符比如下划线然后重新保存配置。当然了这个不是这个 PR 要做的,可以在新的 PR 里面优化。

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 11, 2026
@Soulter Soulter merged commit 6c2f738 into AstrBotDevs:master Jan 11, 2026
6 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.

3 participants