Summary
The current lifespan implementation is tied to sessions/transports rather than having distinct scopes. This causes two P0 bugs (#1300, #1304) and makes the model fundamentally wrong for production use.
Problem
Goal
Provide two distinct lifetime scopes:
- Server lifespan — entered once when the server starts, exited when it shuts down. Survives across all sessions and requests. This is where you put database pools, ML models, shared caches.
- Session lifespan — entered when a client session is established, exited when the session ends. This is where you put per-user state, auth context, session-specific resources.
Both should be accessible from handler context. The current single lifespan parameter should be replaced or extended to support both scopes.
Subsumes
AI Disclaimer
Summary
The current lifespan implementation is tied to sessions/transports rather than having distinct scopes. This causes two P0 bugs (#1300, #1304) and makes the model fundamentally wrong for production use.
Problem
streamable-http, the lifespan does not execute on server startup — it only runs when a client connects and a session is created (Lifespan does not execute on startup streamable-http #1300)stateless_http=True, the lifespan enters and exits for every request because each request spins up a new transport (Lifespan enters and exits for each request when stateless_http=True #1304)Goal
Provide two distinct lifetime scopes:
Both should be accessible from handler context. The current single
lifespanparameter should be replaced or extended to support both scopes.Subsumes
AI Disclaimer