Skip to content

fix: refresh idle WebChat after proactive messages - #10142

Open
beemines wants to merge 2 commits into
AstrBotDevs:masterfrom
beemines:fix/webchat-proactive-updates
Open

beemines wants to merge 2 commits into
AstrBotDevs:masterfrom
beemines:fix/webchat-proactive-updates

Conversation

@beemines

@beemines beemines commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #10097.

An idle WebChat window does not see scheduled or other proactive messages until history is reloaded. After a normal chat run ends, there is no generation queue for send_by_session to deliver to, so it only persists the message.

This adds an authenticated, owner-checked session SSE endpoint for history invalidations. Rejected subscriptions return a generic error rather than exception details. Proactive persistence notifies viewers only after the database write succeeds. These subscriptions are separate from generation queues, so multiple viewers do not cause duplicate persistence or keep a chat run alive. Each subscriber buffers at most one invalidation; connections send keepalives and release their queues on disconnect.

Both dashboard chat views use the shared message composable to subscribe while idle. Connection/reconnection refreshes history to recover missed notifications, existing loaded pages are retained, and updates arriving during a refresh trigger another read. Starting a run or switching sessions closes the subscription and prevents an in-flight refresh from overwriting live messages. The OpenAPI spec and generated client are updated.

This does not create LLM checkpoints for proactive messages or change scheduled-agent execution.

Validation (Windows, Python 3.12.13):

  • Ten new backend tests cover the actual idle proactive-send path, two viewers with one database write, failed persistence, ownership, bounded invalidations, cancellation cleanup, and generic rejection responses.
  • Related chat/queue regression: 21 passed before the additional idle-send and error-response tests; all ten new cases were then rerun successfully.
  • Full Python suite: 3,474 passed, 77 skipped, initially two failures. The API scope-document mismatch was fixed by regenerating the public documentation. The missing-DashScope-key test inherited a locally configured key; rerunning the affected provider, dashboard API, and documentation suites without that environment variable passed all 157 tests. No test was disabled.
  • Dashboard tests: 59 passed, including four new notification/loading/race scenarios. Final TypeScript checking passed.
  • Dashboard production build, startup smoke test, Ruff, and git diff --check passed.

AI assistance: Codex assisted with investigation, implementation, and tests. The original adapter's proactive-send path was compared with the modified path locally: both persisted once; only the modified path emitted a history notification. No external model calls were used for these regression tests.

Comment thread astrbot/dashboard/api/chat.py Fixed

@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 reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. If the ownership or scope check is wrong, a user could receive activity notifications for another WebChat session, and any such disclosure cannot be recalled by reverting. Client-side failures would otherwise be ordinary stale-history or redundant-refresh bugs that reverting fully removes.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] WebChat:定时任务主动推送成功,但打开的聊天窗口不实时显示,重新加载后才可见

3 participants