Skip to content

Conversation

@daniel-oronsi
Copy link
Contributor

@daniel-oronsi daniel-oronsi commented Nov 25, 2025

Hi,

I encountered this behavior when using cl.context.session.environ to get the HTTP headers.
It seemed like the headers were outdated when I used them - and after going through the connect function it seemed like environ is not passed to the restore_existing_session function, which means that the updated socket won't necessarily have the updated environment variables.

If there's an intentional reason for this behavior that I'm missing, I'd appreciate some context :)
And one more question - I didn't dive deeply into the authentication flow, but do you think I should also update the user when restoring the session? for now I left it unchanged.

Thanks for the help!


Summary by cubic

Restored websocket sessions now receive the current request environ so headers and context stay up to date after reconnects. This prevents stale header usage in session logic.

  • Bug Fixes
    • Added an environ parameter to restore_existing_session and set session.environ during restore.
    • Passed environ when restoring a session and updated tests to assert environ propagation and not-found behavior.

Written for commit 0b840fe. Summary will update automatically on new commits.

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. backend Pertains to the Python backend. bug Something isn't working labels Nov 25, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@hayescode
Copy link
Contributor

@daniel-oronsi thanks for the contribution! I don't see why we would include the environ so looks good to me but please address the CI issues then we can merge this

@daniel-oronsi
Copy link
Contributor Author

Hey, thanks for the quick response :)

I see that main is also failing with the same header_auth test, so I think the recent change to main might've introduced some flakiness...
I modified the test a bit, let me know if it looks good to you

@hayescode hayescode added this pull request to the merge queue Dec 4, 2025
Merged via the queue into Chainlit:main with commit 71a8e8f Dec 4, 2025
10 checks passed
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. bug Something isn't working 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