Skip to content

fix: fix: restore missing WebChat sessions - #9607

Open
Alchuang22-dev wants to merge 1 commit into
AstrBotDevs:masterfrom
Alchuang22-dev:fix/platform_message_history
Open

fix: fix: restore missing WebChat sessions#9607
Alchuang22-dev wants to merge 1 commit into
AstrBotDevs:masterfrom
Alchuang22-dev:fix/platform_message_history

Conversation

@Alchuang22-dev

@Alchuang22-dev Alchuang22-dev commented Aug 9, 2026

Copy link
Copy Markdown

Fix #9605 issue

Modifications / 改动点

修复了后端消息入口直接写入 platform_message_history,没有查询或补建 platform_sessions导致的 sidebar 相关问题。对应代码在chat_service.py (line 1090)

Fix WebChat conversations that have message history but are missing from the sidebar because no corresponding platform_sessions record exists.

  • Ensure a WebChat platform session exists when processing a message.

  • Make the existing WebChat session migration run idempotently on every startup.

  • Preserve normal message delivery if session backfilling fails.

  • Add a focused regression test based on the existing ChatService test fixture.

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

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

test_chat_route.py 中添加了相关的新测试。

Commands:

  • ruff format .
  • ruff check .
  • pytest tests/test_chat_route.py -q — 10 passed
  1. 生成一个对话
image
  1. 人为复现issue里的历史
image
  1. 重新查询,修复后的预期结果是 1
image
  1. UI也正常
image

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 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.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

PTAL!

Summary by Sourcery

Ensure WebChat conversations are correctly surfaced by creating missing platform sessions at message processing time and making the WebChat session migration rerunnable.

Bug Fixes:

  • Restore WebChat conversations that had message history but were missing from the sidebar due to absent platform session records.
  • Prevent failures in WebChat session backfilling from disrupting normal message delivery.

Enhancements:

  • Make the WebChat platform session migration idempotent so it can safely run on every startup.

Tests:

  • Add an async regression test verifying that processing a WebChat message creates a missing platform_session entry.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend feature:chatui The bug / feature is about astrbot's chatui, webchat labels Aug 9, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In test_chat_stream_creates_missing_webchat_platform_session, the teardown uses chat_service.webchat_queue_mgr.remove_queues(session_id) instead of service.webchat_queue_mgr.remove_queues(session_id), which will raise a NameError and should be corrected.
  • The new WebChat session backfill in build_chat_stream relies on the literal string platform_history_id == "webchat"; consider centralizing this identifier (or aligning with the platform id constants already used elsewhere) to avoid subtle mismatches and make future changes easier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `test_chat_stream_creates_missing_webchat_platform_session`, the teardown uses `chat_service.webchat_queue_mgr.remove_queues(session_id)` instead of `service.webchat_queue_mgr.remove_queues(session_id)`, which will raise a NameError and should be corrected.
- The new WebChat session backfill in `build_chat_stream` relies on the literal string `platform_history_id == "webchat"`; consider centralizing this identifier (or aligning with the platform id constants already used elsewhere) to avoid subtle mismatches and make future changes easier.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend feature:chatui The bug / feature is about astrbot's chatui, webchat size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebChat 会话不显示在侧边栏:消息入口不建 platform_sessions 记录,且一次性迁移导致历史欠账无法补齐

1 participant