Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(socket): handle missing user env - #2927

#2927
Merged
dokterbob merged 1 commit into
Chainlit:mainChainlit/chainlit:mainfrom
pragnyanramtha:codex/fix-load-user-env-nonepragnyanramtha/chainlit:codex/fix-load-user-env-noneCopy head branch name to clipboard
May 26, 2026
Merged

fix(socket): handle missing user env#2927
dokterbob merged 1 commit into
Chainlit:mainChainlit/chainlit:mainfrom
pragnyanramtha:codex/fix-load-user-env-nonepragnyanramtha/chainlit:codex/fix-load-user-env-noneCopy head branch name to clipboard

Conversation

@pragnyanramtha

@pragnyanramtha pragnyanramtha commented May 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • initialize websocket user env parsing with an empty dict when the client sends no userEnv payload
  • keep required user env validation on the intended ConnectionRefusedError path
  • update socket tests that previously pinned the NameError/UnboundLocalError behavior

Validation

  • uv run --no-sync ruff check chainlit/socket.py tests/test_socket.py
  • uv run --no-sync ruff format --check chainlit/socket.py tests/test_socket.py
  • uv run --no-sync pytest tests/test_socket.py

Note: local pytest required temporary empty chainlit/frontend/dist and chainlit/copilot/dist directories because importing chainlit.server expects built UI directories.


Summary by cubic

Fix WebSocket user env parsing to default to an empty dict when the client sends no payload, while keeping required-key validation. This avoids NameError/UnboundLocalError and raises ConnectionRefusedError only when required vars are missing.

  • Bug Fixes
    • Initialize user_env_dict = {} in chainlit.socket.load_user_env when userEnv is absent.
    • Update tests to expect {} when no keys are required and ConnectionRefusedError when required keys are missing.

Written for commit df30c9b. Summary will update on new commits. Review in cubic

Co-Authored-By: Codex <noreply@openai.com>
@pragnyanramtha
pragnyanramtha marked this pull request as ready for review May 17, 2026 03:09
@pragnyanramtha
pragnyanramtha requested a review from hayescode as a code owner May 17, 2026 03:09
Copilot AI review requested due to automatic review settings May 17, 2026 03:09
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. backend Pertains to the Python backend. bug Something isn't working unit-tests Has unit tests. labels May 17, 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.

No issues found across 2 files

Re-trigger cubic

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

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

Comment thread backend/chainlit/socket.py

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

I love how the original tests had actual bugs marked as such. :p

Thanks, good PR! Sorry it took a while.

@dokterbob
dokterbob added this pull request to the merge queue May 26, 2026
Merged via the queue into Chainlit:main with commit b094a8f May 26, 2026
25 of 27 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:XS This PR changes 0-9 lines, ignoring generated files. unit-tests Has unit tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.