Skip to content

Fix: collapsible thinking display and separate deep research retrieval tag - #14613

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
wanghualoong:fix/think-tag-collapsible-and-deep-research
May 8, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
wanghualoong:fix/think-tag-collapsible-and-deep-research

Conversation

@wanghualoong

Copy link
Copy Markdown
Contributor

Summary

  • Collapsible thinking: Replace <section> with <details> for <think> content, so model thinking output is collapsed by default (click to expand). Works for all models that output <think> tags (Qwen3, DeepSeek, Gemini, Claude, etc.).
  • Fix double thinking tags: When reasoning/deep research mode is enabled in knowledge base chat, both the retrieval progress and model thinking were wrapped in <think> tags, producing two "Thinking..." blocks. Now retrieval progress uses a dedicated <retrieving> tag rendered as a separate "Retrieving..." collapsible with a distinct green accent.

Before

  • Thinking content displayed as flat gray-bordered <section>, occupying significant screen space
  • Deep research + model thinking both use <think> → two identical "Thinking..." blocks

After

  • Thinking content collapsed by default in a <details> element, click "Thinking..." to expand
  • Deep research shows "Retrieving..." (green border), model thinking shows "Thinking..." (gray border)

Changes

Backend (api/db/services/dialog_service.py)

  • Deep research callback: replace start_to_think/end_to_think marker flags with direct <retrieving>/</retrieving> answer text

Frontend

  • web/src/utils/chat.ts: replaceThinkToSection() now uses <details> instead of <section>; add new replaceRetrievingToSection()
  • 4 tsx files: import and pipe replaceRetrievingToSection, whitelist details, summary, retrieving in DOMPurify ADD_TAGS
  • 4 less files: section.think → details.think with <summary> styles; add details.retrieving with green accent; dark mode and RTL variants

Test plan

  • Open a chat WITHOUT knowledge base, ask a question to a model with thinking (e.g. Qwen3) → thinking content should be collapsed by default, click "Thinking..." to expand
  • Open a chat WITH knowledge base and reasoning enabled, ask a question → "Retrieving..." (green) shows retrieval progress, "Thinking..." (gray) shows model thinking, each independently collapsible
  • Verify dark mode renders correctly for both collapsible blocks
  • Verify RTL layout renders correctly

🤖 Generated with Claude Code

…l tag

1. Replace `<section>` with `<details>` for `<think>` content so model
   thinking output is collapsed by default and expandable on click.

2. Use a dedicated `<retrieving>` tag for deep research retrieval status
   instead of reusing `<think>` markers (`start_to_think`/`end_to_think`).
   This prevents double "Thinking..." blocks when reasoning mode is
   enabled with knowledge base chat — the retrieval progress now renders
   as a separate "Retrieving..." collapsible, while model thinking
   renders as "Thinking...".

Backend:
- dialog_service.py: deep research callback yields `<retrieving>` /
  `</retrieving>` answer text instead of think marker flags.

Frontend:
- chat.ts: add `replaceRetrievingToSection()` alongside existing
  `replaceThinkToSection()`, both using `<details>` elements.
- 4 tsx files: import and pipe `replaceRetrievingToSection`, whitelist
  `details`, `summary`, `retrieving` in DOMPurify `ADD_TAGS`.
- 4 less files: `section.think` → `details.think` with `<summary>`
  styles; add `details.retrieving` with distinct green accent. Dark
  mode and RTL variants included.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 7, 2026
@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Backend and frontend coordinate to render think and retrieving blocks as native HTML <details> elements instead of static sections. The backend emits retrieving tokens; utilities transform both think and retrieving tags into collapsible details with summaries; components sanitize, pipe, and style the new structure across the UI.

Changes

Collapsible Details Rendering for Think and Retrieving Blocks

Layer / File(s) Summary
Core HTML Transformation Utilities
web/src/utils/chat.ts
replaceThinkToSection wraps think content in <details class="think"> with "Thinking..." summary; replaceRetrievingToSection transforms retrieving blocks into <details class="retrieving"> with "Retrieving..." summary.
Backend Deep-Research Markers
api/db/services/dialog_service.py
Backend emits retrieving and closing retrieving tokens as answer placeholders instead of think-related marker flags when deep-research control messages are encountered.
Frontend Sanitization & Pipelines
web/src/components/markdown-content/index.tsx, web/src/components/next-markdown-content/index.tsx, web/src/pages/next-search/markdown-content/index.tsx, web/src/components/floating-chat-widget-markdown.tsx
Components whitelist details, summary, and retrieving tags in DOMPurify and apply replaceThinkToSection and replaceRetrievingToSection transformations in their content pipelines.
Component Styling
web/src/components/markdown-content/index.module.less, web/src/components/message-item/index.module.less, web/src/components/next-markdown-content/index.module.less, web/src/components/next-message-item/index.module.less
LESS modules style details.think and details.retrieving with cursor, colors, and hover states on nested summary elements; RTL variants use border-inline-end instead of border-inline-start.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • infiniflow/ragflow#14271: Both PRs modify dialog_service.py chat streaming logic around think/retrieving markers.
  • infiniflow/ragflow#14301: Related to streaming SSE message handling for thought/retrieving markers; this PR changes server-side emitted answer tokens for deep-research.

Suggested labels

🐞 bug, size:S

Poem

A rabbit hops through think blocks now,
With details unfolding, a collapsible bow! 🐰
Retrieving retrieves in a twirl,
Details and summaries swirl and unfurl! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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 accurately and specifically describes the two main changes: making thinking display collapsible and separating the deep research retrieval tag from thinking tags.
Description check ✅ Passed The description covers all required template sections with clear problem statement, type of change selected, comprehensive summary, detailed changes, and test plan included.
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.

@dosubot dosubot Bot added 🌈 python Pull requests that update Python code 🐞 bug Something isn't working, pull request that fix bug. 🧰 typescript Pull requests that update Typescript code labels May 7, 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/pages/next-search/markdown-content/index.tsx (1)

244-247: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

details blocks are unstyled here due to stale section.think selectors.

Line 246 still styles section.think, but the new renderer outputs details.think / details.retrieving. This causes a visual regression in this page for the new collapsible blocks.

Suggested patch
-      className="[&>section.think]:pl-[10px] [&>section.think]:text-[`#8b8b8b`] [&>section.think]:border-l-2 [&>section.think]:border-l-[`#d5d3d3`] [&>section.think]:mb-[10px] [&>section.think]:text-xs [&>blockquote]:pl-[10px] [&>blockquote]:border-l-4 [&>blockquote]:border-l-[`#ccc`] text-sm"
+      className="[&>details.think]:pl-[10px] [&>details.think]:text-[`#8b8b8b`] [&>details.think]:border-l-2 [&>details.think]:border-l-[`#d5d3d3`] [&>details.think]:mb-[10px] [&>details.think]:text-xs [&>details.retrieving]:pl-[10px] [&>details.retrieving]:text-[`#23a55a`] [&>details.retrieving]:border-l-2 [&>details.retrieving]:border-l-[`#23a55a`] [&>details.retrieving]:mb-[10px] [&>details.retrieving]:text-xs [&>blockquote]:pl-[10px] [&>blockquote]:border-l-4 [&>blockquote]:border-l-[`#ccc`] text-sm"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/pages/next-search/markdown-content/index.tsx` around lines 244 - 247,
The CSS selector string on the div still targets `section.think` (className in
the JSX) but the renderer now uses `details.think` and `details.retrieving`;
update the selector list in the className on the div to replace `section.think`
with `details.think` (and add `details.retrieving` if needed) so the collapsible
blocks receive the same padding, color, border and margin styles as before; keep
the other selectors (e.g., `blockquote`) unchanged and ensure you update the
exact className prop in this component (the JSX element that currently contains
the long Tailwind-style selector).
🧹 Nitpick comments (2)
api/db/services/dialog_service.py (1)

667-669: ⚡ Quick win

Add transition logs for the new <retrieving> streaming markers.

Line 667 and Line 669 introduce a new stream state transition but don’t log start/end events, which makes retrieval-flow debugging harder.

Proposed patch
                 if msg.find("<START_DEEP_RESEARCH>") == 0:
+                    logging.debug("deep_research retrieving started")
                     yield {"answer": "<retrieving>", "reference": {}, "audio_binary": None, "final": False}
                 elif msg.find("<END_DEEP_RESEARCH>") == 0:
+                    logging.debug("deep_research retrieving finished")
                     yield {"answer": "</retrieving>", "reference": {}, "audio_binary": None, "final": False}
                     break

As per coding guidelines, **/*.py: Add logging for new flows.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/db/services/dialog_service.py` around lines 667 - 669, Add logging calls
around the new streaming markers so entering/exiting the "<retrieving>" flow is
recorded: when yielding {"answer": "<retrieving>", ...} emit a start log (e.g.
logger.info or process_logger.info) noting you entered the retrieving state and
include the msg or dialog id/context; when yielding {"answer": "</retrieving>",
...} emit a corresponding end log indicating retrieval finished and include the
same context; place these logs immediately before the two yield statements that
use "<retrieving>" and "<END_DEEP_RESEARCH>" so retrieval-flow transitions are
visible in the logs.
web/src/utils/chat.ts (1)

81-95: ⚡ Quick win

Consider renaming helpers to reflect actual output (details, not section).

replaceThinkToSection / replaceRetrievingToSection now emit <details>..., so the current names are misleading. Renaming to replaceThinkToDetails and replaceRetrievingToDetails would reduce future confusion.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/utils/chat.ts` around lines 81 - 95, The helper names
replaceThinkToSection and replaceRetrievingToSection are misleading because they
produce <details> elements; rename both functions to replaceThinkToDetails and
replaceRetrievingToDetails, update all internal references/usages and any
exported names accordingly (keep the same implementation in
replaceThinkToDetails and replaceRetrievingToDetails), and run a quick search
across the repo to update imports/usages to the new function names to avoid
breaking consumers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@web/src/pages/next-search/markdown-content/index.tsx`:
- Around line 244-247: The CSS selector string on the div still targets
`section.think` (className in the JSX) but the renderer now uses `details.think`
and `details.retrieving`; update the selector list in the className on the div
to replace `section.think` with `details.think` (and add `details.retrieving` if
needed) so the collapsible blocks receive the same padding, color, border and
margin styles as before; keep the other selectors (e.g., `blockquote`) unchanged
and ensure you update the exact className prop in this component (the JSX
element that currently contains the long Tailwind-style selector).

---

Nitpick comments:
In `@api/db/services/dialog_service.py`:
- Around line 667-669: Add logging calls around the new streaming markers so
entering/exiting the "<retrieving>" flow is recorded: when yielding {"answer":
"<retrieving>", ...} emit a start log (e.g. logger.info or process_logger.info)
noting you entered the retrieving state and include the msg or dialog
id/context; when yielding {"answer": "</retrieving>", ...} emit a corresponding
end log indicating retrieval finished and include the same context; place these
logs immediately before the two yield statements that use "<retrieving>" and
"<END_DEEP_RESEARCH>" so retrieval-flow transitions are visible in the logs.

In `@web/src/utils/chat.ts`:
- Around line 81-95: The helper names replaceThinkToSection and
replaceRetrievingToSection are misleading because they produce <details>
elements; rename both functions to replaceThinkToDetails and
replaceRetrievingToDetails, update all internal references/usages and any
exported names accordingly (keep the same implementation in
replaceThinkToDetails and replaceRetrievingToDetails), and run a quick search
across the repo to update imports/usages to the new function names to avoid
breaking consumers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b2956a2e-127c-4d98-8c2e-3fb86def1f89

📥 Commits

Reviewing files that changed from the base of the PR and between 12f80f1 and 83402ff.

📒 Files selected for processing (10)
  • api/db/services/dialog_service.py
  • web/src/components/floating-chat-widget-markdown.tsx
  • web/src/components/markdown-content/index.module.less
  • web/src/components/markdown-content/index.tsx
  • web/src/components/message-item/index.module.less
  • web/src/components/next-markdown-content/index.module.less
  • web/src/components/next-markdown-content/index.tsx
  • web/src/components/next-message-item/index.module.less
  • web/src/pages/next-search/markdown-content/index.tsx
  • web/src/utils/chat.ts

@wangq8
wangq8 requested a review from cike8899 May 8, 2026 05:42
@wangq8 wangq8 added the ci Continue Integration label May 8, 2026
@wangq8
wangq8 marked this pull request as draft May 8, 2026 05:43
@wangq8
wangq8 marked this pull request as ready for review May 8, 2026 05:44
@codecov

codecov Bot commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (12f80f1) to head (83402ff).
⚠️ Report is 28 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14613   +/-   ##
=======================================
  Coverage   94.16%   94.16%           
=======================================
  Files          10       10           
  Lines         703      703           
  Branches      112      112           
=======================================
  Hits          662      662           
  Misses         25       25           
  Partials       16       16           

☔ 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.

@wangq8
wangq8 merged commit 1bcb6de into infiniflow:main May 8, 2026
1 check passed
pekar9781 pushed a commit to pekar9781/ragflow that referenced this pull request May 8, 2026
…l tag (infiniflow#14613)

## Summary

- **Collapsible thinking**: Replace `<section>` with `<details>` for
`<think>` content, so model thinking output is collapsed by default
(click to expand). Works for all models that output `<think>` tags
(Qwen3, DeepSeek, Gemini, Claude, etc.).
- **Fix double thinking tags**: When reasoning/deep research mode is
enabled in knowledge base chat, both the retrieval progress and model
thinking were wrapped in `<think>` tags, producing two "Thinking..."
blocks. Now retrieval progress uses a dedicated `<retrieving>` tag
rendered as a separate "Retrieving..." collapsible with a distinct green
accent.

### Before
- Thinking content displayed as flat gray-bordered `<section>`,
occupying significant screen space
- Deep research + model thinking both use `<think>` → two identical
"Thinking..." blocks

### After
- Thinking content collapsed by default in a `<details>` element, click
"Thinking..." to expand
- Deep research shows "Retrieving..." (green border), model thinking
shows "Thinking..." (gray border)

## Changes

**Backend (`api/db/services/dialog_service.py`)**
- Deep research callback: replace `start_to_think`/`end_to_think` marker
flags with direct `<retrieving>`/`</retrieving>` answer text

**Frontend**
- `web/src/utils/chat.ts`: `replaceThinkToSection()` now uses
`<details>` instead of `<section>`; add new
`replaceRetrievingToSection()`
- 4 tsx files: import and pipe `replaceRetrievingToSection`, whitelist
`details`, `summary`, `retrieving` in DOMPurify `ADD_TAGS`
- 4 less files: `section.think` → `details.think` with `<summary>`
styles; add `details.retrieving` with green accent; dark mode and RTL
variants

## Test plan
- [ ] Open a chat WITHOUT knowledge base, ask a question to a model with
thinking (e.g. Qwen3) → thinking content should be collapsed by default,
click "Thinking..." to expand
- [ ] Open a chat WITH knowledge base and reasoning enabled, ask a
question → "Retrieving..." (green) shows retrieval progress,
"Thinking..." (gray) shows model thinking, each independently
collapsible
- [ ] Verify dark mode renders correctly for both collapsible blocks
- [ ] Verify RTL layout renders correctly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: wanghualoong <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
Ricardo-M-L pushed a commit to Ricardo-M-L/ragflow that referenced this pull request Aug 17, 2026
…l tag (infiniflow#14613)

## Summary

- **Collapsible thinking**: Replace `<section>` with `<details>` for
`<think>` content, so model thinking output is collapsed by default
(click to expand). Works for all models that output `<think>` tags
(Qwen3, DeepSeek, Gemini, Claude, etc.).
- **Fix double thinking tags**: When reasoning/deep research mode is
enabled in knowledge base chat, both the retrieval progress and model
thinking were wrapped in `<think>` tags, producing two "Thinking..."
blocks. Now retrieval progress uses a dedicated `<retrieving>` tag
rendered as a separate "Retrieving..." collapsible with a distinct green
accent.

### Before
- Thinking content displayed as flat gray-bordered `<section>`,
occupying significant screen space
- Deep research + model thinking both use `<think>` → two identical
"Thinking..." blocks

### After
- Thinking content collapsed by default in a `<details>` element, click
"Thinking..." to expand
- Deep research shows "Retrieving..." (green border), model thinking
shows "Thinking..." (gray border)

## Changes

**Backend (`api/db/services/dialog_service.py`)**
- Deep research callback: replace `start_to_think`/`end_to_think` marker
flags with direct `<retrieving>`/`</retrieving>` answer text

**Frontend**
- `web/src/utils/chat.ts`: `replaceThinkToSection()` now uses
`<details>` instead of `<section>`; add new
`replaceRetrievingToSection()`
- 4 tsx files: import and pipe `replaceRetrievingToSection`, whitelist
`details`, `summary`, `retrieving` in DOMPurify `ADD_TAGS`
- 4 less files: `section.think` → `details.think` with `<summary>`
styles; add `details.retrieving` with green accent; dark mode and RTL
variants

## Test plan
- [ ] Open a chat WITHOUT knowledge base, ask a question to a model with
thinking (e.g. Qwen3) → thinking content should be collapsed by default,
click "Thinking..." to expand
- [ ] Open a chat WITH knowledge base and reasoning enabled, ask a
question → "Retrieving..." (green) shows retrieval progress,
"Thinking..." (gray) shows model thinking, each independently
collapsible
- [ ] Verify dark mode renders correctly for both collapsible blocks
- [ ] Verify RTL layout renders correctly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: wanghualoong <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
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 🌈 python Pull requests that update Python code size:L This PR changes 100-499 lines, ignoring generated files. 🧰 typescript Pull requests that update Typescript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants