-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
I am using Chainlit 2.9.2 with Python 3.12, deploying a single Chainlit application that serves:
1. A main Chainlit chat UI, and
2. Chainlit Copilot, embedded on multiple external websites.
Both the main app and Copilot use the same Chainlit backend domain (e.g. https://chat.example.org).
When Copilot authenticates using accessToken, the main Chainlit app disconnects (WebSocket closes). This happens even when:
• the same browser is used
• the same logged-in user identity is used
• only one Chainlit deployment exists
Environment
• Chainlit: 2.9.2
• Python: 3.12
• Deployment: Kubernetes
• Exposure: Service type LoadBalancer
• TLS termination: on Chainlit pod
• Domain: single domain (no subdomains available)
• Copilot: embedded on multiple external websites
Copilot embed example
<script src="https://chat.example.org/copilot/index.js"></script> <script> window.mountChainlitWidget({ chainlitServer: "https://chat.example.org", }); </script>Observed behavior
• When Copilot initializes and authenticates, Chainlit sets or refreshes its auth cookie.
• This causes the existing WebSocket session of the main app to become invalid.
• The main app UI disconnects immediately after Copilot authentication.
Expected behavior
• Authenticating Copilot for the same user should not invalidate or disconnect an existing main app session.
• Ideally, the main Chainlit UI and Copilot should be able to coexist on the same domain without interfering with each other’s sessions.
Suspected root cause
• Chainlit v2 uses cookie-based authentication.
• Copilot authentication refreshes or replaces the auth cookie on the same origin.
• Existing WebSocket connections appear to be tied to the previous cookie/session and are closed when it changes.
Constraints
• Cannot use multiple domains or subdomains.
• Prefer not to run a separate backend per website.
• Currently using a single Chainlit deployment to serve both UI and Copilot.
Questions
1. Is it expected that re-authentication (even for the same user) invalidates existing WebSocket sessions?
2. Is there a recommended way to run Chainlit UI and Copilot on the same domain without session conflicts?
3. Is CHAINLIT_COOKIE_PATH intended only for isolating separate app mounts, or can it help within a single app instance?
4. Would it be feasible to make Copilot auth idempotent for the same user (i.e., avoid rotating cookies if identity hasn’t changed)?
Any guidance or recommended architecture would be appreciated.