Skip to content

Chainlit#2899 - Hot-swap Chat Profile within an active conversation - #3015

Open
FosanzDev wants to merge 21 commits into
Chainlit:mainfrom
FosanzDev:Chainlit#2899
Open

Chainlit#2899 - Hot-swap Chat Profile within an active conversation#3015
FosanzDev wants to merge 21 commits into
Chainlit:mainfrom
FosanzDev:Chainlit#2899

Conversation

@FosanzDev

@FosanzDev FosanzDev commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

This feature allows users to hot-swap between chat profiles within a conversation.

As shown in the video, when going back to a chat, it sets the latest used profile

2026-08-20.19-59-04.mp4

Summary by cubic

Hot-swaps the chat profile during an active conversation so switching no longer reconnects or resets the thread. Previously, switching profiles forced a reconnect; now the session updates in place and persists the last used profile (and thread tag when features.auto_tag_thread is on) after the first interaction.

Backend

  • Adds opt-in features.hot_swap_chat_profile and cl.set_chat_profile(name | None), which validates against @cl.set_chat_profiles, updates the session config, persists to thread metadata, and emits chat_profile_updated.
  • The set_chat_profile event is ignored when the feature is off; metadata redaction keeps chat_profile and chat_settings, and restoration honors an explicitly unset profile.

Frontend

  • hotSwapChatProfile switches in place without recreating the socket; Chat Profiles hot-swaps when the feature is on, otherwise falls back to the confirm-and-reset flow.
  • New, updated, streamed, and ask messages are stamped with metadata.chat_profile so avatars resolve per message.

Written for commit 7e2c863. Summary will update on new commits.

Review in cubic

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. backend Pertains to the Python backend. enhancement New feature or request frontend Pertains to the frontend. labels Aug 20, 2026

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 10 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread backend/chainlit/session.py Outdated
Comment thread backend/chainlit/__init__.py Outdated
Comment thread backend/chainlit/callbacks.py Outdated
Comment thread libs/react-client/src/useConfig.ts
Comment thread frontend/src/components/header/ChatProfiles.tsx Outdated
Comment thread backend/chainlit/socket.py Outdated
Comment thread frontend/src/components/chat/Messages/Message/Avatar.tsx
Comment thread backend/chainlit/socket.py Outdated
Comment thread libs/react-client/src/useChatSession.ts
Comment thread libs/react-client/src/useChatSession.ts Outdated
FosanzDev and others added 3 commits August 20, 2026 20:32
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@FosanzDev
FosanzDev marked this pull request as draft August 20, 2026 18:43

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread backend/chainlit/__init__.py Outdated
Comment thread backend/chainlit/__init__.py Outdated
FosanzDev and others added 4 commits August 20, 2026 20:45
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
callbacks.py was modified to not trigger an error in the callback tests
@FosanzDev
FosanzDev marked this pull request as ready for review August 20, 2026 19:31

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 12 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread libs/react-client/src/useChatSession.ts
Comment thread libs/react-client/src/useConfig.ts Outdated
Comment thread libs/react-client/src/useChatSession.ts
Comment thread libs/react-client/src/useChatSession.ts Outdated
Comment thread backend/chainlit/__init__.py Outdated
Comment thread backend/chainlit/session.py Outdated
Comment thread backend/chainlit/session.py
Comment thread backend/chainlit/socket.py Outdated
Comment thread backend/chainlit/socket.py
Comment thread backend/chainlit/socket.py
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@FosanzDev
FosanzDev marked this pull request as draft August 20, 2026 19:56
@FosanzDev
FosanzDev marked this pull request as ready for review August 20, 2026 20:19

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 12 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread libs/react-client/src/useChatSession.ts
Comment thread libs/react-client/src/useConfig.ts Outdated
Comment thread backend/chainlit/socket.py Outdated
Comment thread backend/chainlit/session.py Outdated
Comment thread backend/chainlit/session.py
Comment thread backend/chainlit/session.py Outdated
FosanzDev and others added 2 commits August 21, 2026 00:03
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@dokterbob

Copy link
Copy Markdown
Collaborator

Closes #2355. @FosanzDev This requires at least E2E and backend unit tests and ideally also frontend unit tests.

- New backend tests to test context and data layer
- Mod. test_session to check actions on set_chat_profile calls
- Mod. test_socket to also check actions on set_chat_profile that go through websocket
- Tests covering legacy flow compat, non-triggering new chat dialog on change when hot-swap is enabled
- Tests convering if avatar icons are preserved when changing profiles
Validates in-place switching between profiles during an active chat.

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 7 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread cypress/e2e/hot_swap_chat_profiles/spec.cy.ts
Comment thread backend/tests/test_session.py Outdated
Comment thread frontend/tests/ChatProfiles.spec.tsx Outdated
Comment thread frontend/tests/ChatProfiles.spec.tsx
FosanzDev and others added 2 commits August 30, 2026 22:31
- main.py: Used to do testing with a config file with flag set to true. Now it is explicitly set. This also fixes the env on the CI runs.
- test_session.py: some methods modified the global state without reverting them unlike other tests do, leaving stale entries accross test runs. Corrected
- ChatProfiles.spec.tsx: Added an untested branch for when chatProfiles array is empty. Also missing a not called assertion for set chat profiel
@FosanzDev

Copy link
Copy Markdown
Contributor Author

@dokterbob done added backend, frontend and E2E tests for this.

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

Labels

backend Pertains to the Python backend. enhancement New feature or request frontend Pertains to the frontend. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants