Skip to content

Prevent MCP stdout truncation by avoiding forced process exit on normal serve shutdown - #3

Merged
Ramachandrajoshi merged 2 commits into
mainfrom
copilot/fix-test-job-failure
Nov 8, 2026
Merged

Ramachandrajoshi merged 2 commits into
mainfrom
copilot/fix-test-job-failure

Conversation

Copilot AI commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

The macOS Node 22.13 CI job failed in mcp.test.js with non-JSON on stdout (corrupts the protocol) during a large map impact response. The failure was caused by the MCP server process being force-exited on the normal completion path.

  • Root cause

    • src/cli/commands/serve.js always called shutdown() after await ctx.server.start().
    • shutdown() invoked process.exit(0), which can terminate before stdout fully flushes, corrupting newline-delimited JSON-RPC output.
  • Change

    • Split shutdown behavior into:
      • cleanup() for resource disposal (refresher.dispose(), store.close()).
      • shutdown() for signal-driven termination (cleanup() + process.exit(0)).
    • On normal server completion, call cleanup() only (no forced exit).
  • Effect

    • Preserves protocol integrity on normal termination, especially for large tool responses, while retaining immediate termination behavior for SIGINT/SIGTERM.
await ctx.server.start();
// normal completion path: release resources only
cleanup();

Co-authored-by: Ramachandrajoshi <14068607+Ramachandrajoshi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix failing GitHub Actions job test (node 22.13, macos-latest) Prevent MCP stdout truncation by avoiding forced process exit on normal serve shutdown Nov 8, 2026
@Ramachandrajoshi
Ramachandrajoshi marked this pull request as ready for review November 8, 2026 05:58
Copilot AI balanced review requested due to automatic review settings November 8, 2026 05:58
@Ramachandrajoshi
Ramachandrajoshi merged commit 5a28ed4 into main Nov 8, 2026
12 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Ramachandrajoshi
Ramachandrajoshi deleted the copilot/fix-test-job-failure branch November 8, 2026 06:00
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.

3 participants