Skip to content

fix: report WebChat preprocessing errors - #10482

Open
wcqqq1214 wants to merge 3 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/webchat-preprocessing-errors
Open

wcqqq1214 wants to merge 3 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/webchat-preprocessing-errors

Conversation

@wcqqq1214

@wcqqq1214 wcqqq1214 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Uploading an MP3 in WebChat without FFmpeg leaves the assistant reply stuck on the loading/thinking indicator indefinitely. Refreshing the page or reopening the conversation restores the same stuck state. Preprocessing only logs the exception and never ends the response stream, so the request remains active instead of showing an error and finishing.

Modifications / 改动点

  • Return an error followed by an end event when WebChat preprocessing fails.

  • Preserve errors in SSE/WebSocket history without invalid regeneration checkpoints.

  • Localize missing-FFmpeg and generic failure messages in Chinese, English, Japanese and Russian, including after reload.

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

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

Verification steps:

  1. With FFmpeg unavailable, upload an MP3 in WebChat. Confirm an actionable error replaces the waiting indicator.
  2. Refresh or reopen the conversation. Confirm it shows the saved error without a stuck loading/thinking indicator or invalid regenerate action; switch languages to verify localization.
  3. Send a normal text message and confirm it still works.

Validated locally: the above flow; 20 existing tests in test_webchat_queue_lifecycle.py, test_chat_route.py and test_live_chat_service.py; Ruff; frontend typecheck/build; documentation build.

Before

Before

After (中文)

Screenshot 2026-10-09 at 20 07 31

After (English)

Screenshot 2026-10-10 at 00 44 49

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 checked the affected WebUI instructions and screenshots in docs/zh and docs/en against the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog.
    / 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新 docs/zh 和 docs/en 的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。

  • 🤓 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.txt 和 pyproject.toml 文件相应位置。

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

Summary by Sourcery

Complete WebChat responses cleanly when message preprocessing fails and preserve the resulting localized error state across reloads.

New Features:

  • Display actionable, localized WebChat preprocessing errors in Chinese, English, Japanese, and Russian, including after conversation reload.

Bug Fixes:

  • Ensure WebChat preprocessing failures terminate the response instead of leaving the assistant indefinitely stuck in a loading state.
  • Preserve preprocessing errors in chat history without creating invalid LLM regeneration checkpoints.

@wcqqq1214
wcqqq1214 marked this pull request as ready for review October 9, 2026 17:05

@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 found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/dashboard/services/chat_service.py" line_range="1161" />
<code_context>
+                if msg_type in ("plain", "error"):
+                    if msg_type == "error":
+                        run.status = "failed"
+                        run.llm_checkpoint_id = None
                     for accumulator in (pending_accumulator, display_accumulator):
                         accumulator.add_plain(
</code_context>
<issue_to_address>
**Editing failed prompts is rejected**

When preprocessing fails before an LLM-history turn is created and the user later retries or edits the saved message, clearing `run.llm_checkpoint_id` does not clear the checkpoint on the already-saved user history record. `update_message` then looks for a turn that does not exist, so the edit request fails.

Clear the checkpoint on the persisted user history record as well as on the run when preprocessing fails.

Also at `astrbot/dashboard/services/live_chat_service.py:708-709`.
</issue_to_address>

### Comment 2
<location path="dashboard/src/components/chat/ThreadPanel.vue" line_range="287-290" />
<code_context>
   if (type === "error") {
     markMessageStarted(botRecord);
-    appendPlain(botRecord, `\n\n${String(data)}`);
+    botRecord.content.message.push({
+      type: "plain",
+      text: String(data),
+      error_code: payload.error_code,
+    });
     return;
</code_context>
<issue_to_address>
**Failed replies retain regenerate action**

When a ThreadPanel bot record receives a run snapshot with a checkpoint before `message_saved` carries a null checkpoint, the `message_saved` handler uses `data?.llm_checkpoint_id || botRecord.llm_checkpoint_id`, so it retains the old checkpoint. The UI offers regeneration for the failed message, and the request is rejected because the saved bot message has no checkpoint.

When the event supplies a null checkpoint, overwrite the bot record’s checkpoint with null instead of falling back to its previous value.

Also at `astrbot/dashboard/services/chat_service.py:1161`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and if the new error path is wrong, failed chat runs could be marked failed and an error message/end event could be written into the conversation state instead of only being logged. Reverting stops the behavior for future runs, while any incorrect stored transcript or run state would require bounded cleanup or a rerun.

Blocking findings: astrbot/dashboard/services/chat_service.py:1161, dashboard/src/components/chat/ThreadPanel.vue:290


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

Comment thread astrbot/dashboard/services/chat_service.py
Comment thread dashboard/src/components/chat/ThreadPanel.vue
@wcqqq1214

Copy link
Copy Markdown
Contributor Author

@sourcery-ai review

@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 new error path is wrong, failed WebChat turns could be recorded with incorrect status or leave pending output and edit state inconsistent; these records and state are bounded and can be repaired or retried. Reverting prevents future occurrences but does not remove error messages or status changes already persisted.


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

@wcqqq1214
wcqqq1214 force-pushed the fix/webchat-preprocessing-errors branch from 7a8801a to c7a1e8e Compare October 9, 2026 19:20

This branch has not been deployed

No deployments
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.

1 participant