Skip to content

Fix: enhance reference handling in SessionChat component - #16571

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:fix/bug-agent-0702
Jul 2, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:fix/bug-agent-0702

Conversation

@dcc123456

Copy link
Copy Markdown
Collaborator

Summary

Fix: update reference type in IAgentLogResponse and enhance reference handling in SessionChat component

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 2, 2026
@dcc123456
dcc123456 requested a review from wangq8 July 2, 2026 09:34
@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The reference field in IAgentLogResponse was changed from a single IReference to an array of IReference. SessionChat was updated to resolve each message's reference using a fallback chain: message-based lookup, then index-based lookup from session.reference, then an empty object.

Changes

Multi-reference support in agent chat

Layer / File(s) Summary
Reference type update
web/src/interfaces/database/agent.ts
IAgentLogResponse.reference changed from IReference to IReference[].
Reference resolution fallback
web/src/pages/agent/explore/components/session-chat.tsx
Imports IReferenceObject and reworks the MessageItem reference prop to try findReferenceByMessageId, then an index-based lookup into session?.reference, then an empty object fallback.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A single reference grew into a row,
Hop, skip, fallback—watch the data flow!
Index by index, the rabbit does peek,
Finding each message the answer it seeks. 🐰📚

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the main change to SessionChat reference handling.
Description check ✅ Passed The description matches the required Summary section and covers both reference-type and SessionChat changes.
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.

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.

🧹 Nitpick comments (1)
web/src/pages/agent/explore/components/session-chat.tsx (1)

154-156: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Magic index formula Math.floor((i - 1) / 2) for pairing message index to reference index is fragile and undocumented.

This assumes strictly alternating user/assistant messages with a 1:1 reference-per-assistant-turn mapping. Any deviation (e.g., multi-turn tool calls, inserted system messages, or messages not appended in pairs) will silently attach the wrong reference to a message. Consider adding a brief comment explaining the indexing invariant, or deriving the reference index from message role/order more explicitly.

🤖 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/agent/explore/components/session-chat.tsx` around lines 154 -
156, The reference lookup in session-chat.tsx uses a fragile implicit pairing
rule via Math.floor((i - 1) / 2), so update the logic around the
message/reference mapping to make the invariant explicit. Either add a short
comment near the reference selection in the session chat render path explaining
the strict alternating message assumption, or refactor the index derivation to
use message role/order more directly in the component that renders the chat
items.
🤖 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.

Nitpick comments:
In `@web/src/pages/agent/explore/components/session-chat.tsx`:
- Around line 154-156: The reference lookup in session-chat.tsx uses a fragile
implicit pairing rule via Math.floor((i - 1) / 2), so update the logic around
the message/reference mapping to make the invariant explicit. Either add a short
comment near the reference selection in the session chat render path explaining
the strict alternating message assumption, or refactor the index derivation to
use message role/order more directly in the component that renders the chat
items.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6c2a8d78-258d-4585-b08c-36e560298122

📥 Commits

Reviewing files that changed from the base of the PR and between c8cf0c9 and 1a18104.

📒 Files selected for processing (2)
  • web/src/interfaces/database/agent.ts
  • web/src/pages/agent/explore/components/session-chat.tsx

@wangq8
wangq8 merged commit c44d56f into infiniflow:main Jul 2, 2026
6 checks passed
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 3, 2026
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants