Skip to content

[chore] Warn when websockets 17 pairs with old uvicorn - #17115

Merged
sfc-gh-lwilby-1 merged 4 commits into
developfrom
chore/warn-uvicorn-websockets-17-mismatch
Oct 8, 2026
Merged

sfc-gh-lwilby-1 merged 4 commits into
developfrom
chore/warn-uvicorn-websockets-17-mismatch

Conversation

@sfc-gh-lwilby-1

@sfc-gh-lwilby-1 sfc-gh-lwilby-1 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes

Logs a startup warning when websockets 17+ is paired with uvicorn < 0.52.0 . Follow-up to allowing websockets 17.x (#17113). That mix is a legal install, but uvicorn can abort the /_stcore/stream handshake when a reverse proxy forwards non-ASCII identity headers (#16030). uvicorn fixed the round-trip in 0.52.0 (Kludex/uvicorn#3036).

The warning can also fire for operators who will never see a non-ASCII proxy header.

GitHub Issue Link (if applicable)

#16030

Testing Plan

  • Unit Tests (JS and/or Python)
  • E2E Tests
  • Any manual testing needed?

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

Made with Cursor

@sfc-gh-lwilby-1 sfc-gh-lwilby-1 added change:chore PR contains maintenance or housekeeping change impact:users PR changes affect end users labels Sep 24, 2026
@snyk-io

snyk-io Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

@sfc-gh-lwilby-1
sfc-gh-lwilby-1 marked this pull request as ready for review September 24, 2026 18:51
@sfc-gh-lwilby-1 sfc-gh-lwilby-1 added the ai-final-review If applied to PR or issue will run AI review workflow with the latest generation of AI models. label Sep 24, 2026
@greptile-apps

greptile-apps Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds a version-check warning for websockets and uvicorn compatibility.

The PR appears safe to merge; no outstanding findings remain.

Summary

The PR adds a startup warning for affected websockets and uvicorn version pairs and tests the warning boundaries. The latest changes simplify the version predicate and clarify the warning text.

Reviews (4) · Last reviewed commit: "Clarify mismatch warning range and remed..." · Reviewed by Greptile

@github-actions github-actions Bot removed the ai-final-review If applied to PR or issue will run AI review workflow with the latest generation of AI models. label Sep 24, 2026

@github-actions github-actions 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.

Summary

This PR adds a one-time startup warning when Streamlit’s bundled uvicorn server is configured with websockets 17+ and uvicorn older than 0.52.0. That pairing can abort the /_stcore/stream handshake if a reverse proxy forwards non-ASCII identity headers (#16030; fixed upstream in Kludex/uvicorn#3036, released in uvicorn 0.52.0). The published uvicorn floor stays >=0.30.0. The helper is invoked from _get_uvicorn_config_kwargs(), so both UvicornServer and UvicornRunner pick it up. Unit tests cover the warn / no-warn version gates and a missing-metadata path.

All four expected reviews completed (gpt-5.6-sol-high, claude-opus-5-thinking-high, gemini-3.7-flash-high, cursor-grok-4.6-xhigh) and all approved. Reviewers agreed the change is small, correctly researched, and the right alternative to raising the uvicorn floor. Disagreements were limited to optional scope (whether to also cover websockets==16.1), defensive exception handling, test structure, and warning copy — none of those are merge-blocking.

One cross-cutting note on merge order: #17113 (raising the cap to websockets<18) is still open. lib/pyproject.toml still declares websockets>=12.0.0,<17, and uv.lock pins uvicorn 0.53.0 / websockets 16.1.1, so this warning is unreachable for any resolver-respecting install until that cap moves. Merging this first is harmless; the two should land together (or #17113 first) so the diagnostic is live when the combination first becomes installable.

Product Alignment

This has limited user-facing product impact: a new console warning at server start. It does not add or change a public API, config option, CLI flag, or rendered UI, so no product spec is required — this is a small, non-controversial diagnostic under specs/AGENTS.md.

Reviewers differed on whether Product Alignment applied at all. One treated it as not applicable (internal logger only). The rest treated the new console line as externally observable. The latter is the right reading of the review policy (“error message, or other externally observable behavior”), but the impact is still a one-line operator diagnostic, not a product-surface change.

No relevant spec is on develop, and the PR body does not claim separate product approval. The body does state the intended tradeoff: warn instead of raising the uvicorn floor. The implementation matches that decision and aligns with:

  • Fail fast, fail helpfully: the message names the failing handshake and tells the operator to upgrade uvicorn to >= 0.52.0.
  • Graceful evolution: bumping uvicorn>=0.52.0 would break legal installs on 0.30–0.51; a warning keeps those installs working.
  • Logging guidance (lib/streamlit/AGENTS.md): console-only, at most once per process, for a failure mode that otherwise surfaces as a silent handshake drop and a hung “Please wait…”. Analogous surfaces already exist in starlette_server.py (for example the IPv6 bind fallback).

The PR already notes that the warning can fire for operators who never see non-ASCII proxy headers. That false-positive cost is acceptable.

Code Quality

The implementation is proportionate: a private helper, two importlib.metadata lookups, existing is_version_less_than, and no new dependencies, abstractions, or state. Naming (_maybe_warn_uvicorn_websockets_mismatch, _package_version) matches module conventions and the private-name rule in lib/AGENTS.md. Missing-package lookup fails closed (no warning). Thresholds match the upstream uvicorn fix.

Reviewers differed on the call site. One preferred calling the helper from UvicornServer.start() and UvicornRunner.run() to keep _get_uvicorn_config_kwargs() free of side effects. The current placement is the better one: kwargs are built once, outside both port-retry loops (lines 388 and 585), so both entry points share the check without duplicating it and without re-warning on port retries. Complexity is appropriate.

Performance

No meaningful impact. The helper runs once per server process at startup, not on the backend hot paths in lib/streamlit/AGENTS.md (element creation, ForwardMsg hashing, delta queueing, reruns, caching, dataframe conversion). Two metadata lookups and two packaging.version parses are negligible. importlib.metadata is now imported at module import time, but starlette_server.py itself is only imported when a server is started, and packaging was already an import-time dependency of is_version_less_than. No frontend changes.

Test Coverage

Unit tests in starlette_server_test.py cover the important gates:

  • warns on websockets 17.0.0 + uvicorn 0.51.0 (including message content and interpolated versions)
  • silent on uvicorn 0.52.0
  • silent on websockets 16.x
  • silent when package metadata is missing

That is enough for merge. E2E is not warranted: the combination cannot be installed in CI today (lock pins websockets 16.1.1 / uvicorn 0.53.0), and Playwright has no mechanism for asserting server startup logs under a manipulated dependency set.

Optional gaps (parametrizing the near-identical version tests, and asserting the _get_uvicorn_config_kwargs() wiring) are noted inline. Reviewers agreed those are follow-ups, not missing required coverage.

Backwards Compatibility

No breaking changes. Dependency ranges, protocol selection, and handshake behavior are unchanged. Existing apps keep running; some operators may see a new startup warning after websockets 17 becomes a legal install (#17113) or if an environment already overrides Streamlit’s <17 cap. That is the intended signal. Deployments that treat stderr warnings as fatal could notice it, but that combination is currently uninstallable for resolver-respecting installs.

Security & Risk

No security-sensitive surface is modified. The change does not alter the WebSocket handshake, session management, endpoints, auth, cookies, XSRF, CORS, headers, file serving, or sanitization. It only reads local package metadata and logs fixed version strings — no user input, no network calls, no new dependencies.

Regression risk is low and confined to startup logging. A non-PEP 440 version string could theoretically raise InvalidVersion from is_version_less_than; that is unlikely for these packages and is already an unguarded pattern in _get_websocket_protocol(). A cheap guard is suggested inline, not as a merge blocker.

External test recommendation

  • Recommend external_test: No
  • Triggered categories: None
  • Evidence:
    • lib/streamlit/web/server/starlette/starlette_server.py: adds a log-only helper and one call from the kwargs builder. Returned uvicorn kwargs, ws protocol selection, socket binding, and handshake behavior are unchanged. Category 3 (websocket handshake and session transport) is in the neighborhood of this file but is not hit.
    • lib/tests/streamlit/web/server/starlette/starlette_server_test.py: unit tests only, fully mocked metadata and logger.
  • Suggested external_test focus areas: none for this PR. If external coverage is added for this problem area, it belongs on the dependency bump (#17113), where an externally hosted run behind a proxy forwarding a non-ASCII identity header (for example X-Authentik-Name: Céline) would actually exercise the /_stcore/stream handshake against websockets 17.
  • Confidence: High
  • Assumptions and gaps: Assumes no downstream tooling treats a new startup warning as a failure. The warning cannot fire in CI today because the lock pins websockets 16.1.1 and uvicorn 0.53.0.

Accessibility

Not applicable — no frontend files are changed and nothing rendered in the UI is affected. The warning goes to the server console only.

Readability

lib/streamlit/web/server/starlette/starlette_server.py

  • Function docstring (lines 217–221): clear and correctly scoped — condition, consequence, and #16030. No change needed.
  • Naming: _maybe_warn_uvicorn_websockets_mismatch follows the established _maybe_* convention. _package_version reads clearly at call sites.
  • One reviewer suggested splitting the compound version-gate if (lines 228–231) into two early returns. That is a style preference; the current form is readable enough.

lib/tests/streamlit/web/server/starlette/starlette_server_test.py

  • Test and method names (test_warns_when_websockets_17_and_uvicorn_below_052, etc.) stand alone. Class-docstring nit is noted inline.

PR title and description

  • Title — [chore] Warn when websockets 17 pairs with old uvicorn — stands alone, matches [type] Description, and is within the length budget. Optional tightening: [chore] Warn when websockets 17 pairs with uvicorn < 0.52 (replaces “old” with the actual boundary).
  • Description — leads with the change and the rejected alternative (raising the uvicorn floor), explains the why with upstream links, and stays concise. Two optional additions:
    • Close the false-positive sentence so it is clearly an accepted tradeoff: “The warning can also fire for operators who never see a non-ASCII proxy header. That cost is acceptable: it is one line per server start, and the failure it predicts otherwise surfaces only as a silent handshake drop.”
    • Note that the warning is inert until #17113 raises the cap to websockets<18.

Recommendations

  1. Coordinate merge order with #17113 so the warning is live when the websockets 17 combination first becomes installable, and mention that coupling in the PR description.
  2. Optionally tighten the PR title (“old uvicorn” → “uvicorn < 0.52”) and close the description’s false-positive sentence with the accepted-tradeoff rationale above.

Verdict

APPROVED: A small, well-tested startup diagnostic with no behavioral, security, or performance risk; remaining notes are optional follow-ups (version-range coverage, defensive parsing, test structure, copy).


This is an automated AI review by cursor-grok-4.6-xhigh (consolidated). Please verify the feedback and use your judgment.

This review also includes 6 inline comment(s) on specific code lines.



class TestWarnUvicornWebsocketsMismatch:
"""Tests for _maybe_warn_uvicorn_websockets_mismatch."""

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.

nitpick: The class docstring restates the internal helper name rather than the behavior under test. Proposed rewrite: """Verify startup warnings for incompatible uvicorn and websockets versions."""

@github-actions github-actions 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.

Auto-approved by AI final review (workflow run).

@sfc-gh-lwilby-1 sfc-gh-lwilby-1 added the ai-final-review If applied to PR or issue will run AI review workflow with the latest generation of AI models. label Oct 6, 2026
@github-actions github-actions Bot removed the ai-final-review If applied to PR or issue will run AI review workflow with the latest generation of AI models. label Oct 6, 2026

@github-actions github-actions 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.

Summary

PR #17115 logs a startup warning when the installed websockets release decodes HTTP headers as ISO-8859-1 and uvicorn is older than 0.52.0. That pair can abort the /_stcore/stream handshake if a reverse proxy forwards non-ASCII identity headers (#16030). The affected websockets set is exactly 16.1 (16.1.1 reverted the decode) and every 17+ release. The published floor stays uvicorn>=0.30.0.

All four expected reviewers completed and approved: gpt-5.6-sol-high, claude-opus-5-5-high, gemini-3.8-flash-high, and grok-4.7-xhigh. None failed to complete review. They agree the change is a small, correct, well-tested diagnostic with no security, performance, or compatibility blocker.

The one product-scope disagreement is wording, not substance. gemini-3.8-flash-high marked Product Alignment not applicable. The other three treated the new console line as narrow operator-visible behavior. The warning is externally observable, so product alignment applies, and no spec is required. Title and docstring rewrites differed in wording; every reviewer agreed the title and opening sentence omit websockets 16.1.

Product Alignment

The user-facing change is one logger warning at server start for affected dependency pairs. The PR adds no public API, config option, CLI flag, or rendered UI.

No product spec on develop covers this, and none is required. This is a diagnostic for an existing compatibility bug, which specs/AGENTS.md treats as a small non-controversial enhancement. The PR body explicitly chooses a warning over raising the uvicorn floor. The implementation matches that decision: it logs and still starts.

The warning fits the principles that apply here:

  • Graceful Evolution and Minimize Migration Distance: installs on uvicorn 0.30–0.51 stay resolvable.
  • Fail Fast, Fail Helpfully, applied through the logging guidance in lib/streamlit/AGENTS.md: the server still works, so this is a log-only case. The message names /_stcore/stream, the non-ASCII proxy-header trigger, and an upgrade to uvicorn >= 0.52.0. An in-app st.warning would be invisible to CLI users and agents.

The warning can also fire when no non-ASCII header is present. The PR body accepts that tradeoff, and all four reviewers agree the extra log line is acceptable because the alternative is a floor bump that breaks currently legal installs. Covering websockets 16.1 as well as 17+ is the right behavior: 16.1 remains a legal install under websockets>=12.0.0,<18 and is the release that introduced the decode. The title and description still say only 17+. That is a description mismatch, covered under Readability.

Code Quality

The change is proportionate: two private helpers, the existing is_version_less_than helper, and no new dependency, config, or abstraction. packaging is already a runtime dependency.

_get_uvicorn_config_kwargs() calls the check once, before the port-retry loops in both UvicornServer.start() (around line 399) and UvicornRunner.run() (around line 596). Both entry points share that builder, so the warning is not duplicated and does not repeat on retries. A side effect inside a function named like a config builder is an accepted tradeoff; the wiring test pins it.

The version window is [16.1, 16.1.1) plus >= 17, combined with uvicorn < 0.52.0. That matches the websockets changelog (16.1 switched to ISO-8859-1, 16.1.1 reverted it, 17.0 restored it and requires Python >= 3.11) and uvicorn 0.52.0 (Kludex/uvicorn#3036). PackageNotFoundError and InvalidVersion return before the log call, so a missing or non-PEP 440 version cannot block startup.

_get_websocket_protocol() still reads uvicorn.__version__, while this check reads importlib.metadata.version("uvicorn"). On a normal install those sources agree. Aligning them can wait for a follow-up.

Performance

There is no meaningful performance impact. The check does two importlib.metadata lookups and a handful of version parses, once per server start, outside the port-retry loop and outside the backend hot paths in lib/streamlit/AGENTS.md. There is no frontend work, no per-rerun cost, and no need for performance coverage.

Test Coverage

Unit coverage is sufficient, and all four reviewers agree e2e coverage is unnecessary. The behavior is a startup log that depends on installed versions the e2e harness does not vary.

TestWarnUvicornWebsocketsMismatch covers the matrix that matters: websockets 17.0.0 and 16.1 warn with uvicorn 0.51.0; websockets 17.0.0 with uvicorn 0.52.0, websockets 16.0.0, and websockets 16.1.1 stay silent. The warning tests also check the message for /_stcore/stream, 0.52.0, and the interpolated versions. Missing metadata and a non-PEP 440 version stay silent, and _get_uvicorn_config_kwargs() actually invokes the helper.

gemini-3.8-flash-high suggested a second invalid-version case where uvicorn, rather than websockets, is non-PEP 440. Both lookups share one except (PackageNotFoundError, InvalidVersion), and the existing case already exercises that handler. A second case would not change the conclusion.

Backwards Compatibility

Dependency ranges, protocol selection, and request handling stay the same. Installs outside websockets 16.1 or 17+ with uvicorn < 0.52.0 see nothing new. Affected installs still start and gain one warning. Log pipelines that alert on any warning will see that line; that is the intended signal.

Security & Risk

Low risk. The patch reads installed distribution versions and logs them. It does not change the WebSocket handshake, routes, headers, authentication, sessions, cookies, CORS, or XSRF. Those version strings are not secrets. Swallowing PackageNotFoundError and InvalidVersion keeps a diagnostic from becoming a startup failure.

External test recommendation

  • Recommend external_test: No
  • Triggered categories: None
  • Evidence:
    • lib/streamlit/web/server/starlette/starlette_server.py: adds a startup log based on installed package versions. Routes, the WebSocket handshake, subprotocols, ping and timeout settings, message size limits, cookies, CORS, CSP, embedding, and asset serving are unchanged. Category 3 (websocket handshake and session transport) stays clear because the warning mentions the handshake and leaves handshake processing as it is.
    • lib/tests/streamlit/web/server/starlette/starlette_server_test.py: unit tests mock package metadata and the logger only.
  • Suggested external_test focus areas: None for this PR. A future change that modifies the handshake should validate a proxied non-ASCII identity header against externally hosted deployments.
  • Confidence: High
  • Assumptions and gaps: The websockets 16.1 / 16.1.1 / 17.0 changelog and the cited uvicorn 0.52.0 fix match the version window in this diff. The server was not run behind a reverse proxy. A proxy that forwards non-ASCII identity headers can still drop the handshake on the affected pair; this PR only warns about that.

Accessibility

Not applicable. The PR has no frontend or rendered UI changes.

Readability

Reviewers agreed the internal docs and the PR text understate websockets 16.1. They differed on how to split that context between the two helpers. The version predicate should state the version window. The warning function should own the handshake consequence and the issue link. That split matches how the functions are used. A one-line warning docstring that omits the versions, and a helper docstring that keeps both the window and the failure mode, each leave one of those jobs unfinished.

lib/streamlit/web/server/starlette/starlette_server.py

  • _websockets_uses_latin1_header_decode (lines 219–224). The second paragraph mixes version history with the uvicorn handshake consequence. Proposed rewrite:

    """Return True if this websockets version decodes headers as ISO-8859-1.
    
    websockets 16.1 and 17+ decode headers this way; 16.1.1 reverted the
    change for the 16.x line.
    """
  • _maybe_warn_uvicorn_websockets_mismatch (line 233). "an affected websockets" does not name the versions. Proposed rewrite:

    """Warn when websockets 16.1 or 17+ is installed with uvicorn older than 0.52.0.
    
    Those releases decode headers as latin-1, so uvicorn < 0.52.0 can abort
    the /_stcore/stream handshake when a reverse proxy forwards non-ASCII
    identity headers (#16030).
    """

lib/tests/streamlit/web/server/starlette/starlette_server_test.py

  • TestWarnUvicornWebsocketsMismatch (line 430). The class docstring repeats the private helper name. gpt-5.6-sol-high and grok-4.7-xhigh both flagged this. Proposed rewrite:

    """Startup warnings when websockets latin-1 header decode meets uvicorn older than 0.52.0."""

PR title and description

  • Title. [chore] Warn when websockets 17 pairs with old uvicorn omits websockets 16.1, and "old uvicorn" is vague. This string becomes the squash-merge subject. Proposed rewrite (61 characters): [chore] Warn when websockets 16.1/17+ runs with uvicorn <0.52.

  • Description. The opening sentence says the warning applies to websockets 17+. The last sentence states that unaffected operators can still see the warning, and leaves out why that noise is acceptable. Required template sections are present. Proposed rewrite of the change description:

    Logs a startup warning when `websockets` 16.1 or 17+ is paired with `uvicorn` < 0.52.0, instead of raising Streamlit's published uvicorn floor (`>=0.30.0`).
    
    Follow-up to allowing websockets 17.x (#17113). Those websockets releases decode handshake headers as ISO-8859-1. 16.1.1 reverted that, and 17.0 restored it. With uvicorn < 0.52.0, a reverse proxy that forwards non-ASCII identity headers can abort `/_stcore/stream` (#16030). uvicorn fixed the round-trip in 0.52.0 ([Kludex/uvicorn#3036](https://github.com/Kludex/uvicorn/pull/3036)).
    
    The warning also fires for deployments that never forward non-ASCII headers. That noise is acceptable because the fix is a uvicorn upgrade, while raising the floor would break existing installs on uvicorn 0.30–0.51.

Recommendations

  1. Update the PR title and description so they include websockets 16.1 and uvicorn < 0.52.0, using the rewrites in Readability. Optional, and worth doing before squash-merge because the title is what the commit log keeps.
  2. Optionally apply the docstring rewrites above.
  3. Optionally read uvicorn's version the same way in _get_websocket_protocol() and in this check.

Verdict

APPROVED: All four reviewers approved, and the diagnostic targets the real websockets 16.1 and 17+ plus uvicorn < 0.52.0 window, fails soft on bad metadata, and stays covered by unit tests.


This is an automated AI review consolidated by grok-4.7-xhigh. Please verify the feedback and use your judgment.

This review also includes 3 inline comment(s) on specific code lines.

@github-actions github-actions 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.

Auto-approved by AI final review (workflow run).

@sfc-gh-lwilby-1
sfc-gh-lwilby-1 merged commit 0a8df36 into develop Oct 8, 2026
38 checks passed
@sfc-gh-lwilby-1
sfc-gh-lwilby-1 deleted the chore/warn-uvicorn-websockets-17-mismatch branch October 8, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:chore PR contains maintenance or housekeeping change impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant