Skip to content

fix(mcp): do not await startup lifecycle snapshot on critical path#468

Open
Pitchfork-and-Torch wants to merge 2 commits into
getsentry:mainfrom
Pitchfork-and-Torch:fix/defer-startup-lifecycle-snapshot-461
Open

fix(mcp): do not await startup lifecycle snapshot on critical path#468
Pitchfork-and-Torch wants to merge 2 commits into
getsentry:mainfrom
Pitchfork-and-Torch:fix/defer-startup-lifecycle-snapshot-461

Conversation

@Pitchfork-and-Torch

Copy link
Copy Markdown

Summary

Fixes #461.

After the stdio transport is up, startMcpServer() was still awaiting lifecycle.getSnapshot() before the server could settle into answering the first tools/list. That snapshot work (simulator os_log session enumeration, peer process sample, etc.) is telemetry-only and was delaying the first tools/list by ~10–17s on cold start. Short health-probe clients (e.g. Claude Code claude mcp list) then report Connected · tools fetch failed even though the server is healthy.

Change

Move the startup snapshot off the critical path:

  • Fire-and-forget lifecycle.getSnapshot() with the same start metrics / anomaly logging
  • Skip logging if shutdown was already requested
  • Surface snapshot failures as warnings (same spirit as deferred bootstrap)

This matches the existing deferred-initialization pattern immediately below the old await.

Why not delete the snapshot

The issue asks to keep the telemetry; only readiness should not block on it. Metrics and anomaly warnings still run asynchronously.

Test plan

  • xcodebuildmcp mcp over stdio: initialize then immediate tools/list should return without the multi-second cold-start stall
  • Confirm [mcp-lifecycle] start … still appears in logs shortly after startup
  • In-session tools (list_sims, etc.) still work
  • Startup anomaly warnings (if any) still log

Notes

  • Cannot fully re-time simulator enumeration on this contributor environment; logic change matches the issue’s verified root cause and suggested fix.
  • Minimal one-file change.

getSnapshot() enumerates simulator os_log sessions and peer processes.
Awaiting it after stdio transport start delayed the first tools/list by
~10-17s, so short health-probe clients reported tools fetch failed.

Fire-and-forget the snapshot with the same metrics/anomaly logging;
deferred bootstrap already uses this pattern.

Fixes getsentry#461
Comment thread src/server/start-mcp-server.ts Outdated
When getSnapshot is fire-and-forget, markPhase may advance to
deferred-initialization before the snapshot resolves. Capture the
running phase at schedule time for start metrics/anomaly attribution.

Addresses review feedback on getsentry#468 / getsentry#461.
@Pitchfork-and-Torch

Copy link
Copy Markdown
Author

Pushed a follow-up commit that pins start metrics/anomaly phase to the schedule-time running phase (captured before fire-and-forget getSnapshot()), so deferred snapshot logging is not attributed to deferred-initialization if markPhase advances first.

Addresses the Sentry review note on phase race.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Startup getSnapshot() on the critical path delays the first tools/list ~10s (health-probe clients show 'tools fetch failed')

1 participant