Skip to content

Commit a41ef89

Browse files
committed
fix(coverage): lax no cover on two matrix-entry-dependent except handlers
Two `except Exception:` handlers fire on some CI matrix entries but not others — not random, but deterministic per {python, deps, os} combo: streamable_http.py:638 — POST handler's outer except. Fires on 3.12 lowest-direct ubuntu (older dep versions, different shutdown exception propagation), not on the other 19 entries. streamable_http.py:721 — standalone SSE writer's except. Fires on 19/20 entries, not on 3.14 locked ubuntu (EventSourceResponse task cancellation wins the race there; the closed-stream error wins elsewhere). Both are concurrent-shutdown handlers. The underlying race is production behavior (client disconnect while server is writing), but whether tests observe it depends on the interpreter's task scheduling and the httpx/sse-starlette versions in play. Previously invisible — subprocess-based tests ran this code in a separate process that coverage.py couldn't see. This is the intended use of lax no cover: coverage that differs across the matrix for reasons outside the test's control.
1 parent 50a2183 commit a41ef89

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/mcp/server/streamable_http.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,9 @@ async def sse_writer(): # pragma: lax no cover
633633
finally:
634634
await sse_stream_reader.aclose()
635635

636-
except Exception as err: # pragma: no cover
636+
# Fires on some CI matrix entries (3.12 lowest-direct ubuntu) but not
637+
# others — concurrent-shutdown exception timing varies by dep version.
638+
except Exception as err: # pragma: lax no cover
637639
logger.exception("Error handling POST request")
638640
response = self._create_error_response(
639641
f"Error handling POST request: {err}",
@@ -714,7 +716,9 @@ async def standalone_sse_writer():
714716
# Send the message via SSE
715717
event_data = self._create_event_data(event_message)
716718
await sse_stream_writer.send(event_data)
717-
except Exception:
719+
# Fires on most CI matrix entries but not 3.14 locked ubuntu —
720+
# EventSourceResponse cancellation vs stream-close ordering varies.
721+
except Exception: # pragma: lax no cover
718722
logger.exception("Error in standalone SSE writer")
719723
finally:
720724
logger.debug("Closing standalone SSE writer")

0 commit comments

Comments
 (0)