Skip to content

fix: prevent duplicated post-think text - #15651

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
buua436:b065
Jun 5, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
buua436:b065

Conversation

@buua436

@buua436 buua436 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

This fixes duplicated post-think text in streamed chat responses. When the model emits text immediately after </think>, the stream state now advances its cursor correctly so the same visible prefix is not emitted twice.

Type of change

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

@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ff209a97-322a-43e2-9c7c-ca07dc70f54a

📥 Commits

Reviewing files that changed from the base of the PR and between e627f5d and cfaca2c.

📒 Files selected for processing (1)
  • api/db/services/dialog_service.py

📝 Walkthrough

Walkthrough

The pull request updates the streaming text processor to correctly track position when </think> tag boundaries are encountered. After capturing trailing content following a closing think tag, the internal stream cursor is advanced to reflect the end of the processed text, ensuring subsequent deltas start from the correct position.

Changes

Think tag processing

Layer / File(s) Summary
Think tag processing cursor update
api/db/services/dialog_service.py
When </think> is detected, trailing content after the tag is captured into state.post_think_text and state.last_idx is updated to len(full_text) to advance the stream position bookkeeping for follow-up processing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • infiniflow/ragflow#15582: Both PRs adjust _next_think_delta think streaming logic to correctly handle tail content immediately after </think> via cursor advancement.

Suggested labels

🐞 bug, size:XS

Poem

🐰 A cursor hops along the stream,
Following think tags like a dream,
When </think> appears in sight,
Position leaps to new height!
Now deltas dance in the right place,
With streaming fixed at proper pace. 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: prevent duplicated post-think text' clearly and specifically describes the main bug fix in the changeset, matching the core problem the PR solves.
Description check ✅ Passed The description includes both required template sections: a clear problem statement explaining the bug and the type of change marked as a bug fix.
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.

@buua436 buua436 added the ci Continue Integration label Jun 4, 2026
@buua436
buua436 marked this pull request as ready for review June 4, 2026 11:26
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jun 4, 2026
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (7789862) to head (d3bc22c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15651      +/-   ##
==========================================
- Coverage   94.56%   93.16%   -1.40%     
==========================================
  Files          10       10              
  Lines         717      717              
  Branches      118      118              
==========================================
- Hits          678      668      -10     
- Misses         25       29       +4     
- Partials       14       20       +6     

☔ View full report in Codecov by Harness.
📢 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.

@wangq8
wangq8 merged commit 71649db into infiniflow:main Jun 5, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 8, 2026
1 task done
SailedApple1991 added a commit to SailedApple1991/greenlaw-ragflow that referenced this pull request Jun 14, 2026
chat-internals port (route-independent; fork keeps /chats contract + parallel
gather + cache + infiniflow#12689). Replaced fork's think-stream helper block
(_ThinkStreamState / _next_think_delta / _stream_with_think_delta) with
upstream v0.26's final version, which folds in:
- infiniflow#15745 refine think stream parsing (big refactor; min_tokens 1->16)
- infiniflow#15891 remove think text buffering (real-time reasoning)
- infiniflow#15651 prevent duplicated post-think text
- infiniflow#15582 think stream tail handling
- infiniflow#14271 normalize think tags in final answer (adds _extract_visible_answer;
  removes _next_think_delta)
Plus applied infiniflow#14271's 2 consumer wraps: async_chat + async_ask now call
decorate_answer(_extract_visible_answer(...)).

SKIPPED infiniflow#13917 (remove final["answer"]=""): conflicts with fork's deliberate
answer-clearing — async_chat explicitly caches the full answer then blanks it
for the streaming client ('preserve full answer for caching before clearing').
Touching it risks fork's cache/stream contract.

Verified: call convention unchanged (3 consumers); _next_think_delta fully
removed (0 refs); _extract_visible_answer logic correct (5 cases); fork customs
intact (parallel gather x8, cache x5); py_compile. Live SSE smoke -> batch F.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. 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