Skip to content

fix: preserve segmented WebChat replies and reasoning - #10458

Open
wcqqq1214 wants to merge 4 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/webchat-segmented-replies
Open

wcqqq1214 wants to merge 4 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/webchat-segmented-replies

Conversation

@wcqqq1214

@wcqqq1214 wcqqq1214 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes two WebChat bugs with different trigger conditions:

  • Earlier segments disappear: With segmented replies enabled and streaming disabled, a reply split into multiple messages overwrote earlier segments in the live view. Only the last segment remained visible; refreshing restored the saved segments.
  • Reasoning appears as ordinary reply text: With streaming disabled and reasoning display enabled, reasoning returned by the model was inserted into the reply body. This happens with or without segmented replies; enabling segmentation also exposes that text to body splitting. Reasoning should retain its own type and appear in the thinking section.

Normal WebChat streaming replies use a separate delivery path and do not trigger these bugs. Enabling the segmented-reply setting does not split a normal streaming reply into separate messages.

Modifications / 改动点

  • Preserve separate reply messages in the main chat, threads, saved history, and reconnect snapshots.

  • Keep text and attachments from one send together; replace all old segments on regeneration and keep queued replies in order.

  • Send reasoning as a thinking part attached to the first reply instead of splitting it into body text.

  • Add regression coverage and document the SSE message boundaries and snapshot fields.

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

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

Verification steps:

  1. Segment preservation: Enable segmented replies, disable streaming, and request three short sentences that match the configured splitting rule and stay below the segmentation length limit. Before refreshing, confirm all segments remain visible as separate messages; after refreshing, confirm their content and order are unchanged.
  2. Reasoning display: Keep streaming disabled, enable reasoning display, and use a model that returns reasoning. Test with segmented replies both enabled and disabled. Confirm reasoning appears in the thinking section of the first reply, not as ordinary body text or separate body segments. Disable reasoning display and confirm it is hidden.
  3. Related behavior: Regenerate a segmented reply and confirm all old segments are replaced. Queue another request while a segmented reply is being delivered and confirm its response follows all preceding segments.

Automated checks passed:

  • cd dashboard && node --test tests/chatSegmentedReply.test.mjs: 18 tests.
  • uv run --no-sync pytest -q tests/test_chat_route.py tests/unit/test_webchat_follow_up_status.py tests/unit/test_webchat_message_parts.py tests/test_webchat_queue_lifecycle.py: 35 tests.
  • Ruff formatting/lint and dashboard type checking.

Before — without refreshing: Only the last segment remains visible.

Before - No Fresh

Before — after refreshing: All three saved segments reappear.

Before - After Fresh

After — without refreshing: All three segments remain visible as separate messages.

Screenshot 2026-10-09 at 05 10 37

After — after refreshing: Message content, boundaries, and order remain unchanged.

Screenshot 2026-10-09 at 05 10 57

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

Preserve WebChat reply segments and reasoning types across delivery, persistence, reconnection, and regeneration.

Bug Fixes:

  • Preserve segmented non-streaming WebChat replies across live updates, reconnects, active-run snapshots, saved history, threads, and regeneration.
  • Keep model reasoning separate from reply text so it appears in the thinking section when enabled.
  • Keep text and attachments from a single non-streaming response together while maintaining ordering for subsequent queued replies.

Enhancements:

  • Extend WebChat run snapshots and the streaming API documentation with ordered message records, persistence metadata, and non-streaming message boundaries.

Documentation:

  • Document WebChat SSE snapshot fields and message-boundary behavior.

Tests:

  • Add regression coverage for segmented replies, reasoning preservation, attachments, regeneration, queued replies, reconnect snapshots, and legacy WebSocket envelopes.

@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 segmentation or snapshot bookkeeping is wrong, chat replies and reasoning can be persisted as incorrectly split or combined records, and reverting will not remove those already-saved histories. The damage is bounded and can be repaired or recomputed, but it is not undone automatically by a revert.


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

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