Skip to content

Fix: Remove duplicate text output from the thought model on the chat page. - #14301

Merged
yingfeng merged 1 commit into
infiniflow:mainfrom
cike8899:fix-search-embed
Apr 22, 2026
Merged

yingfeng merged 1 commit into
infiniflow:mainfrom
cike8899:fix-search-embed

Conversation

@cike8899

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Fix: Remove duplicate text output from the thought model on the chat page.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 22, 2026
@cike8899 cike8899 added ci Continue Integration and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Apr 22, 2026
@coderabbitai

coderabbitai Bot commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

A targeted fix to the useSendMessageWithSse hook that changes how final SSE events are processed. When the final flag is set on incoming data, the answer string is now cleared instead of appended, ensuring proper state handling at the completion of the streaming response.

Changes

Cohort / File(s) Summary
Streaming Message Logic
web/src/hooks/logic-hooks.ts
Modified currentAnswer update logic within useSendMessageWithSse to force the answer to an empty string when d.final is truthy, preventing content from being appended during final SSE chunks.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

🐞 bug, size:S

Poem

🐰 A final fix, so small yet keen,
Clears the answer when d.final gleams,
SSE streaming flows just right,
No extra bytes in the final night! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing duplicate text output from the thought model, which aligns with the code modification that prevents answer content from being appended during final SSE chunks.
Description check ✅ Passed The description follows the required template structure with both 'What problem does this PR solve?' and 'Type of change' sections completed, though the problem statement could be more detailed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cike8899
cike8899 marked this pull request as draft April 22, 2026 11:23
@cike8899
cike8899 marked this pull request as ready for review April 22, 2026 11:23
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 22, 2026

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
web/src/hooks/logic-hooks.ts (1)

278-285: ⚠️ Potential issue | 🔴 Critical

The fix on line 278 reintroduces a regression that the backend recently fixed, causing loss of answer content in final SSE chunks.

The backend code in async_ask() (line ~1444) and async_chat() (line ~774) was recently fixed to include answer in the final SSE event with the decorated response (containing citation markers). Regression tests in test/unit_test/api/db/services/test_dialog_service_final_answer.py (lines 203–208 and 352–357) explicitly guard against re-introducing final["answer"] = "", which is exactly what line 278 does:

const currentAnswer = d.final ? '' : d.answer || '';

When d.final is true, this unconditionally discards the answer from the final chunk. For responses that arrive with little or no prior streamed content (short answers, buffered responses, or providers emitting only a terminal chunk), prevAnswer will be empty and the assistant message renders blank.

Consider applying the narrower condition suggested in the original comment: only suppress the final answer when it would duplicate already-accumulated content, rather than discarding it unconditionally.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/src/hooks/logic-hooks.ts` around lines 278 - 285, The current code
unconditionally drops the final SSE chunk's answer (const currentAnswer =
d.final ? '' : d.answer || ''), which reintroduces a regression; change the
logic so currentAnswer defaults to d.answer || '' and only set it to '' when the
final decorated answer would duplicate already-accumulated content (i.e., when
d.final is true, prevAnswer is non-empty, d.answer is non-empty, and
d.answer.startsWith(prevAnswer)); update the block near currentAnswer/prevAnswer
in web/src/hooks/logic-hooks.ts to implement that narrower suppression using the
existing symbols d.final, d.answer, and prevAnswer.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@web/src/hooks/logic-hooks.ts`:
- Around line 278-285: The current code unconditionally drops the final SSE
chunk's answer (const currentAnswer = d.final ? '' : d.answer || ''), which
reintroduces a regression; change the logic so currentAnswer defaults to
d.answer || '' and only set it to '' when the final decorated answer would
duplicate already-accumulated content (i.e., when d.final is true, prevAnswer is
non-empty, d.answer is non-empty, and d.answer.startsWith(prevAnswer)); update
the block near currentAnswer/prevAnswer in web/src/hooks/logic-hooks.ts to
implement that narrower suppression using the existing symbols d.final,
d.answer, and prevAnswer.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 32255fba-5df5-4e83-954d-103a3e7ab311

📥 Commits

Reviewing files that changed from the base of the PR and between b52c518 and 2e929da.

📒 Files selected for processing (1)
  • web/src/hooks/logic-hooks.ts

@codecov

codecov Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.97%. Comparing base (b52c518) to head (2e929da).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14301   +/-   ##
=======================================
  Coverage   95.97%   95.97%           
=======================================
  Files          10       10           
  Lines         695      695           
  Branches      111      111           
=======================================
  Hits          667      667           
  Misses         11       11           
  Partials       17       17           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yingfeng
yingfeng merged commit ffa8738 into infiniflow:main Apr 22, 2026
1 check passed
@Lynn-Inf Lynn-Inf mentioned this pull request Apr 23, 2026
4 tasks done
@buua436 buua436 mentioned this pull request Apr 29, 2026
4 tasks done
@coderabbitai coderabbitai Bot mentioned this pull request May 24, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants