Repository navigation
fix(witan): turn off fastmcp's listen streams in the image - #719
Merged
Merged
Conversation
fastmcp 4.2.5 serves the 2026-07-28 `subscriptions/listen` stream by default, and nothing closes an open one on SIGTERM: uvicorn waits on open connections before it runs lifespan shutdown. One listening client then holds a terminating pod for the whole 120s grace window witan sets for in-flight writes. witan publishes no change notifications, so the stream carries nothing. Measured against this image built with fastmcp 4.2.5 and a 30s grace window: with listen on, `docker stop` took 33.1s and uvicorn cancelled the stream at the timeout; with the flag off, listen answered "Method not found" and the stop took 1.6s. Claude-Session: https://claude.ai/code/session_01FGZebCxqhMftSqoiPG9Df5
There was a problem hiding this comment.
Summary
Disables FastMCP listen streams in the Witan image.
Summary of 5e47407 · React 👍 or 👎 on my comments to tune what I raise · Commands · Review config
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
What changed in this PR
Disables fastmcp’s subscriptions/listen stream by default in the witan image to prevent termination delays caused by long-lived open listen connections.
Changes:
- Add
FASTMCP_ENABLE_SUBSCRIPTIONS_LISTEN=falseto the image runtime environment. - Document why the flag is disabled (shutdown behavior, lack of notifications, and compatibility with pre-4.2.5 behavior).
| File | Description |
|---|---|
| docker/witan.Dockerfile | Sets the fastmcp env flag to disable listen streams and documents the rationale. |
Review effort: Lite
Comment on lines
+190
to
+197
| # FASTMCP_ENABLE_SUBSCRIPTIONS_LISTEN=false: fastmcp 4.2.5 serves the | ||
| # 2026-07-28 `subscriptions/listen` stream by default, and nothing closes an | ||
| # open one on SIGTERM (uvicorn waits on connections before lifespan shutdown | ||
| # runs). One listening client then holds every terminating pod for the whole | ||
| # 120s grace window that exists for in-flight writes (DEFAULT_SHUTDOWN_GRACE_SECONDS | ||
| # in witan/cli/__init__.py). witan publishes no change notifications, so the | ||
| # stream carries nothing; off, `subscriptions/listen` answers METHOD_NOT_FOUND | ||
| # and `listChanged` is not advertised, as before 4.2.5. Read at server creation. |
Comment on lines
+196
to
+197
| # stream carries nothing; off, `subscriptions/listen` answers METHOD_NOT_FOUND | ||
| # and `listChanged` is not advertised, as before 4.2.5. Read at server creation. |
Copilot stopped reviewing on behalf of
blarghmatey due to an error
November 23, 2026 16:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


What are the relevant tickets?
N/A. Unblocks #447 (lock maintenance, brings fastmcp 4.2.5). Follow-up spike on using listen: tk-spike-should-witan-push-change-notifications-ove-e2fb08
Description (What does it do?)
fastmcp 4.2.5 serves the 2026-07-28
subscriptions/listenstream by default, and nothing closes an open one on SIGTERM, so one listening client holds a terminating witan pod for the whole 120s shutdown grace. witan publishes no change notifications, so the stream carries nothing. This setsFASTMCP_ENABLE_SUBSCRIPTIONS_LISTEN=falsein the image's runtime env, which makes listen answer "Method not found" and stops advertisinglistChanged, the same as fastmcp 4.1.2 on main today.Implementation details
ListenHandler.close()(mcp/server/subscriptions.py) ends every stream gracefully, but neither fastmcp nor the SDK calls it.Server.shutdownwaits up totimeout_graceful_shutdownfor open connections and only then runs lifespan shutdown, so a lifespan hook can't close the streams in time.uvicorn.Server.handle_exitto end them on SIGTERM. That patch doesn't reach listen streams.How can this be tested?
Built this image locally with #447's
uv.lock(fastmcp 4.2.5, sse-starlette 3.7.0) andWITAN_MCP_SHUTDOWN_GRACE_SECONDS=30, opened a listen stream with fastmcp'sClient.listen(), then timeddocker stop:-e FASTMCP_ENABLE_SUBSCRIPTIONS_LISTEN=true): listen accepted, stop took 33.1s, uvicorn logged "Cancel 1 running task(s), timeout graceful shutdown exceeded"On CI, "the image carries the bundle" builds the image; it doesn't exercise shutdown.
https://claude.ai/code/session_01FGZebCxqhMftSqoiPG9Df5