Skip to content

fix: preserve explicit dialogue user names#3068

Open
wolfkill wants to merge 2 commits into
eosphoros-ai:mainfrom
wolfkill:fix/conversation-user-name-preserved
Open

fix: preserve explicit dialogue user names#3068
wolfkill wants to merge 2 commits into
eosphoros-ai:mainfrom
wolfkill:fix/conversation-user-name-preserved

Conversation

@wolfkill

Copy link
Copy Markdown
Contributor

Description

Fixes #2930.

When /v1/chat/completions and related chat preparation endpoints receive a dialogue payload with an explicit user_name, the value was overwritten by the authenticated token user before the conversation was stored. The conversation response adapter also returned an empty user_name, so history queries could not reliably show or filter the original dialogue user.

This change centralizes dialogue user resolution so request user_name is preserved when provided and the authenticated token user is used only as a fallback. It also returns the stored user_name from conversation history responses.

Testing

  • PYTHONPATH=packages/dbgpt-core/src:packages/dbgpt-app/src:packages/dbgpt-serve/src:packages/dbgpt-ext/src .venv/bin/python -m pytest packages/dbgpt-serve/src/dbgpt_serve/conversation/tests/test_models.py::test_to_response_preserves_user_name -q
  • PYTHONPATH=packages/dbgpt-core/src:packages/dbgpt-app/src:packages/dbgpt-serve/src:packages/dbgpt-ext/src .venv/bin/python -m pytest packages/dbgpt-app/src/dbgpt_app/tests/test_chat_completions_user_name.py -q
  • PYTHONPATH=packages/dbgpt-core/src:packages/dbgpt-app/src:packages/dbgpt-serve/src:packages/dbgpt-ext/src .venv/bin/python -m pytest packages/dbgpt-serve/src/dbgpt_serve/conversation/tests packages/dbgpt-app/src/dbgpt_app/tests/test_chat_completions_user_name.py -q
  • .venv/bin/ruff check packages/dbgpt-app/src/dbgpt_app/openapi/api_view_model.py packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/api_v1.py packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/agentic_data_api.py packages/dbgpt-app/src/dbgpt_app/tests/test_chat_completions_user_name.py packages/dbgpt-serve/src/dbgpt_serve/conversation/models/models.py packages/dbgpt-serve/src/dbgpt_serve/conversation/tests/test_models.py
  • .venv/bin/ruff format --check packages/dbgpt-app/src/dbgpt_app/openapi/api_view_model.py packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/api_v1.py packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/agentic_data_api.py packages/dbgpt-app/src/dbgpt_app/tests/test_chat_completions_user_name.py packages/dbgpt-serve/src/dbgpt_serve/conversation/models/models.py packages/dbgpt-serve/src/dbgpt_serve/conversation/tests/test_models.py
  • PYTHONPATH=packages/dbgpt-core/src:packages/dbgpt-app/src:packages/dbgpt-serve/src:packages/dbgpt-ext/src .venv/bin/python -m compileall -q packages/dbgpt-app/src/dbgpt_app/openapi/api_view_model.py packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/api_v1.py packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/agentic_data_api.py packages/dbgpt-app/src/dbgpt_app/tests/test_chat_completions_user_name.py packages/dbgpt-serve/src/dbgpt_serve/conversation/models/models.py packages/dbgpt-serve/src/dbgpt_serve/conversation/tests/test_models.py
  • git diff --cached --check

@chenliang15405

Copy link
Copy Markdown
Collaborator

Thanks for your contribution. LGTM

chenliang15405
chenliang15405 previously approved these changes May 21, 2026

@chenliang15405 chenliang15405 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 your contribution. LGTM

Copilot AI 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.

Pull request overview

This PR fixes conversation user_name handling so that when a client provides an explicit user_name in dialogue payloads, it is preserved (instead of being overwritten by the authenticated token user), and conversation history responses return the stored user_name to enable reliable filtering/querying.

Changes:

  • Introduces a centralized resolve_dialogue_user_name() helper to prefer request user_name and fall back to the authenticated token user.
  • Updates chat preparation/completions-related endpoints to use the centralized resolver.
  • Fixes conversation history response adaptation to return the stored user_name, and adds targeted tests.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/dbgpt-serve/src/dbgpt_serve/conversation/tests/test_models.py Adds a regression test ensuring DAO response preserves user_name.
packages/dbgpt-serve/src/dbgpt_serve/conversation/models/models.py Returns entity.user_name in conversation history response adapter.
packages/dbgpt-app/src/dbgpt_app/tests/test_chat_completions_user_name.py Adds tests for resolve_dialogue_user_name() behavior.
packages/dbgpt-app/src/dbgpt_app/openapi/api_view_model.py Adds resolve_dialogue_user_name() helper.
packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/api_v1.py Uses resolver in chat_prepare and chat_completions.
packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/agentic_data_api.py Uses resolver in chat_react_agent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +516 to +518
dialogue.user_name = resolve_dialogue_user_name(
dialogue.user_name, user_token.user_id if user_token else None
)
@chenliang15405

Copy link
Copy Markdown
Collaborator

LGTM. Good fix for the dialogue user name preservation issue. The centralized resolve_dialogue_user_name helper cleanly handles the explicit vs fallback logic. Nice that conversation history responses now correctly return the stored user_name. Test coverage is solid with both unit tests for the resolver and integration tests for the chat_prepare flow.

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

LGTM. Good fix for the dialogue user name preservation issue. The centralized resolve_dialogue_user_name helper cleanly handles the explicit vs fallback logic. Nice that conversation history responses now correctly return the stored user_name. Test coverage is solid with both unit tests for the resolver and integration tests for the chat_prepare flow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 发起会话带上user_name,但无法在对话历史中根据user_name进行查询

3 participants