Skip to content

Fix: New sessions will automatically carry over messages from the previous session by default. - #18078

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:fix/chat-conversation-error
Aug 11, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:fix/chat-conversation-error

Conversation

@dcc123456

Copy link
Copy Markdown
Collaborator

Summary

Fix: New sessions will automatically carry over messages from the previous session by default.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 11, 2026
@dcc123456
dcc123456 requested a review from wangq8 August 11, 2026 03:44
@dcc123456 dcc123456 added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration labels Aug 11, 2026
@dcc123456
dcc123456 marked this pull request as draft August 11, 2026 03:44
@dcc123456
dcc123456 marked this pull request as ready for review August 11, 2026 03:44
@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The chat page now clears currentConversation when a new session opens without an existing conversation. This prevents messages from the previous session from remaining visible.

Changes

Chat session state

Layer / File(s) Summary
Reset current conversation state
web/src/pages/next-chats/chat/index.tsx
New sessions now set currentConversation to an empty conversation when no existing conversation is selected.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Suggested labels: 🧰 typescript

Suggested reviewers: jinhai-cn

Poem

A rabbit opens a chat anew,
The old words vanish from view.
A fresh conversation waits,
With empty paws at the gates.
No stale messages hop through!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes the faulty carry-over behavior as the fix, which conflicts with the code that prevents previous messages from remaining visible. Change the title to state that new sessions no longer carry over messages from the previous session.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description check ✅ Passed The description includes the required Summary section and accurately states the issue addressed by the pull request.

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.

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

Actionable comments posted: 2

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

Inline comments:
In `@web/src/pages/next-chats/chat/index.tsx`:
- Around line 56-58: Update the session-loading flow around fetchSessionManually
and setCurrentConversation so results from an outdated request cannot restore
the previous conversation after a new session opens. Cancel the prior request
when possible, or track the latest session selection and apply the fetched
conversation only when it still matches that selection; preserve clearing
messages for new sessions.
- Around line 56-58: Replace the `{}` assertion in the new-session reset and the
initial state with a shared empty-conversation factory that returns a fully
valid IClientConversation, including messages: [] and every required field.
Reuse this factory for both the initial state and setCurrentConversation in the
new-session branch so SingleChatBox and MultipleChatBox always receive a valid
conversation.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bb159d8d-6702-4554-a997-c223946f63ff

📥 Commits

Reviewing files that changed from the base of the PR and between cad2833 and ea4f0c2.

📒 Files selected for processing (1)
  • web/src/pages/next-chats/chat/index.tsx

Comment on lines +56 to +58
} else {
// New session: clear previous session's messages so they don't leak in.
setCurrentConversation({} as IClientConversation);

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.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Prevent stale requests from restoring the previous conversation.

If fetchSessionManually is still pending when a new session opens, it can resolve later and execute setCurrentConversation(conversation) at Line 54. The previous session's messages can then reappear. Cancel the previous request or apply the result only when it matches the latest session selection.

🤖 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-chats/chat/index.tsx` around lines 56 - 58, Update the
session-loading flow around fetchSessionManually and setCurrentConversation so
results from an outdated request cannot restore the previous conversation after
a new session opens. Cancel the prior request when possible, or track the latest
session selection and apply the fetched conversation only when it still matches
that selection; preserve clearing messages for new sessions.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Reset to a valid IClientConversation.

IClientConversation requires messages: IMessage[], but this branch assigns {} through a type assertion. SingleChatBox and MultipleChatBox receive this value. Use an empty-conversation factory with messages: [] and all required fields. Apply it to both the initial state at Line 27 and this reset.

🤖 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-chats/chat/index.tsx` around lines 56 - 58, Replace the
`{}` assertion in the new-session reset and the initial state with a shared
empty-conversation factory that returns a fully valid IClientConversation,
including messages: [] and every required field. Reuse this factory for both the
initial state and setCurrentConversation in the new-session branch so
SingleChatBox and MultipleChatBox always receive a valid conversation.

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! The change correctly prevents message leakage from a previous session into a new one.

What this does: When URL params indicate a new session (!conversationId || isNew), setCurrentConversation({} as IClientConversation) clears the stale conversation state before the new session data loads.

Review:

  • ✅ The else branch correctly handles the case where we are not loading an existing conversation
  • ✅ setCurrentConversation is a React state setter with stable reference, so it does not need to be in the dependency array
  • ✅ No side effects on the existing happy path (conversationId && !isNew)

One suggestion (non-blocking): Consider wrapping the fetchConversation callback in a useCallback like the handleSessionClick is, to maintain consistency. But this is not required for correctness.

Approve ✅

@wangq8
wangq8 merged commit f930b1c into infiniflow:main Aug 11, 2026
9 checks passed
mill413 pushed a commit to mill413/ragflow that referenced this pull request Sep 3, 2026
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