Skip to content

Fix: /chat/completions not aware of conversation_id - #15162

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
wangq8:bugfix/fix-chat-not-aware-of-conversation_id
May 25, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
wangq8:bugfix/fix-chat-not-aware-of-conversation_id

Conversation

@wangq8

@wangq8 wangq8 commented May 22, 2026 •

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Fix /chat/completions not aware of conversation_id

Type of change

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

@coderabbitai

coderabbitai Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The session_completion endpoint in the REST API now accepts conversation_id as an alternative parameter when session_id is not provided, falling back to an empty string if neither is present. This maintains backward compatibility while allowing the endpoint to be called with either parameter name.

Changes

Session ID Parameter Fallback

Layer / File(s) Summary
Session ID derivation with conversation_id fallback
api/apps/restful_apis/chat_api.py
session_completion now derives the internal session_id by falling back to conversation_id from the request when session_id is not provided, enabling both parameter names to work.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit hops through parameter lands,
Where names may shift like desert sands,
"session" or "conversation"—no matter the call,
The fallback embraces them all.
Flexibility blooms where alternatives dance. 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly addresses the main change: enabling /chat/completions to accept conversation_id as an alternative to session_id.
Description check ✅ Passed The description follows the required template with both sections completed: problem statement and type of change (Bug Fix) are clearly specified.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

@wangq8 wangq8 added the ci Continue Integration label May 22, 2026
@wangq8
wangq8 marked this pull request as ready for review May 22, 2026 12:25
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label May 22, 2026
@dosubot

dosubot Bot commented May 22, 2026 •

Copy link
Copy Markdown

Documentation Updates

1 document(s) were updated by changes in this PR:

What is the complete API flow for building a frontend UI with RAGFlow, covering dialogs, conversations, message history, streaming responses, and deletion?
View Changes
@@ -189,6 +189,8 @@
 }
 ```
 
+> **Note:** Either `session_id` or `conversation_id` can be used interchangeably to identify the session/conversation.
+
 **Payload — Second message (includes ALL previous history):**
 ```json
 {

How did I do? Any feedback?  Join Discord

@wangq8 wangq8 changed the title Fix /chat/completions not aware of conversation_id Fix: /chat/completions not aware of conversation_id May 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.

🧹 Nitpick comments (1)
api/apps/restful_apis/chat_api.py (1)

1074-1074: ⚡ Quick win

Add a log for the conversation_id fallback path.

This introduces a new request-handling flow but doesn’t emit any trace when fallback is used, which makes debugging client behavior harder.

Proposed change
-    session_id = req.pop("session_id", "") or req.pop("conversation_id", "") or ""
+    raw_session_id = req.pop("session_id", "") or ""
+    raw_conversation_id = req.pop("conversation_id", "") or ""
+    session_id = raw_session_id or raw_conversation_id
+    if raw_conversation_id and not raw_session_id:
+        logging.info("session_completion received conversation_id fallback")

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/apps/restful_apis/chat_api.py` at line 1074, The single-line assignment
that sets session_id from req.pop("session_id", "") or falls back to
req.pop("conversation_id", "") should be expanded so we detect when the fallback
is used and emit a log; specifically, first attempt to pop "session_id" into a
local variable (session_id), then if empty pop "conversation_id"
(conversation_id) and when conversation_id is used, call the module's logger
(e.g., logger.info/debug) to record that the conversation_id fallback path was
taken and include the conversation_id value and any relevant request identifier;
update the code around the session_id handling in chat_api.py accordingly so the
new flow is logged.
🤖 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 `@api/apps/restful_apis/chat_api.py`:
- Line 1074: The single-line assignment that sets session_id from
req.pop("session_id", "") or falls back to req.pop("conversation_id", "") should
be expanded so we detect when the fallback is used and emit a log; specifically,
first attempt to pop "session_id" into a local variable (session_id), then if
empty pop "conversation_id" (conversation_id) and when conversation_id is used,
call the module's logger (e.g., logger.info/debug) to record that the
conversation_id fallback path was taken and include the conversation_id value
and any relevant request identifier; update the code around the session_id
handling in chat_api.py accordingly so the new flow is logged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ae4474df-d6aa-4f80-9f15-36a2b26e207a

📥 Commits

Reviewing files that changed from the base of the PR and between 302f97d and a2a6e16.

📒 Files selected for processing (1)
  • api/apps/restful_apis/chat_api.py

@codecov

codecov Bot commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.12%. Comparing base (7e68441) to head (a2a6e16).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15162   +/-   ##
=======================================
  Coverage   93.12%   93.12%           
=======================================
  Files          10       10           
  Lines         713      713           
  Branches      116      116           
=======================================
  Hits          664      664           
  Misses         29       29           
  Partials       20       20           

☔ 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 0ce6655 into infiniflow:main May 25, 2026
1 check passed
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.

1 participant