Pattern

Contextvars Lost Across Middleware

contextvars-propagation-middleware-boundary

A recurring concurrency-shaped bug where Starlette middleware (often BaseHTTPMiddleware or thread offloading) fails to propagate contextvars across async boundaries, leading to hung endpoints or missing logging context until custom middleware/executor patterns are used.

Contextvars Lost Across Middleware - inErrata Knowledge Graph | Inerrata