The Fix
Upgrade to version 0.13.4 or later.
Based on closed Kludex/starlette issue #330 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -100,6 +100,7 @@ from starlette.responses import PlainTextResponse
class App:
def __init__(self, scope):
+ assert scope['type'] == 'http'
self.scope = scope
from starlette.responses import PlainTextResponse
class App:
def __init__(self, scope):
self.scope = scope
async def __call__(self, receive, send):
response = PlainTextResponse('Hello, world!')
await response(receive, send)
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\nUpgrade to version 0.13.4 or later.\nWhen NOT to use: This fix is not applicable if the application needs to handle lifespan messages.\n\n
Why This Fix Works in Production
- Trigger: ERROR: Exception in 'lifespan' protocol
- Mechanism: The ASGI app did not assert that the scope type was 'http', causing runtime errors
- Why the fix works: The example ASGI apps now ensure that the scope['type'] is the expected type, preventing runtime errors related to lifespan messages. (first fixed release: 0.13.4).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- Shows up under Python 3.7 in real deployments (not just unit tests).
- The ASGI app did not assert that the scope type was 'http', causing runtime errors
- Surfaces as: INFO: Started server process [18742]
Proof / Evidence
- GitHub issue: #330
- Fix PR: https://github.com/kludex/starlette/pull/348
- First fixed release: 0.13.4
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.48
Verified Execution
We executed the runnable minimal repro in a temporary environment and captured exit codes + logs.
- Status: PASS
- Ran: 2026-02-11T16:52:29Z
- Package: starlette
- Fixed: 0.13.4
- Mode: fixed_only
- Outcome: ok
Logs
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Labelling this up as a bug, although it's a documentation bug rather than an implementation issue.”
“We should probably change the example to..”
Failure Signature (Search String)
- ERROR: Exception in 'lifespan' protocol
Error Message
Stack trace
Error Message
-------------
INFO: Started server process [18742]
INFO: Waiting for application startup.
ERROR: Exception in 'lifespan' protocol
Traceback (most recent call last):
File "/home/matthew/.virtualenvs/dummy/lib/python3.7/site-packages/uvicorn/lifespan.py", line 29, in run
await self.asgi(self.receive, self.send)
File "./app.py", line 10, in __call__
await response(receive, send)
File "/home/matthew/.virtualenvs/dummy/lib/python3.7/site-packages/starlette/responses.py", line 124, in __call__
"headers": self.raw_headers,
File "/home/matthew/.virtualenvs/dummy/lib/python3.7/site-packages/uvicorn/lifespan.py", line 50, in send
raise RuntimeError(error % message['type'])
RuntimeError: Got invalid message type on lifespan protocol "http.response.start"
ERROR: Application startup failed. Exiting.
Minimal Reproduction
from starlette.responses import PlainTextResponse
class App:
def __init__(self, scope):
self.scope = scope
async def __call__(self, receive, send):
response = PlainTextResponse('Hello, world!')
await response(receive, send)
Environment
- Python: 3.7
What Broke
Application startup failed with a runtime error, preventing the server from running.
Why It Broke
The ASGI app did not assert that the scope type was 'http', causing runtime errors
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.13.4 or later.
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/kludex/starlette/pull/348
First fixed release: 0.13.4
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not applicable if the application needs to handle lifespan messages.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
- Pin production dependencies and upgrade only with a reproducible test that hits the failing path.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.13.4 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.