copilot-cli icon indicating copy to clipboard operation
copilot-cli copied to clipboard

Post-authentication MCP client rebuild at startup leaves orphaned stdio MCP server processes

Open michael3lyb opened this issue 3 months ago • 4 comments

Describe the bug

At startup, the CLI spawns its configured MCP servers, then — once GitHub authentication completes — tears down and rebuilds the entire MCP client, re-spawning every configured server. The first generation of stdio child processes is neither killed nor reaped, so each affected session permanently leaks one orphaned MCP server process.

Remote HTTP MCP servers simply reconnect and leave no trace, so the leak is invisible unless you have a local/stdio server configured.

This appears to be a race: only servers that finish their handshake before the post-auth rebuild get orphaned. Servers still cold-starting at that moment are unaffected.

Affected version

GitHub Copilot CLI 1.0.78 (Node v24.18.1)

Steps to reproduce the behavior

My setup: one local (stdio) MCP server (a Python CLI with a slow cold start, roughly 6–50 s) plus two remote HTTP MCP servers.

  1. Configure a stdio MCP server in ~/.copilot/mcp-config.json that completes its handshake within a few seconds of launch.
  2. Start copilot interactively and wait until the session is ready.
  3. Count the child processes for that server: ps -eo pid,ppid,lstart,command | grep <server>
  4. Observe two live child processes under the same CLI pid, spawned roughly 15–50 s apart. Only the second one is actually in use.

Note on reproduction: I could not produce a minimal repro on this machine, because my org's managed MCP allow list rejects any server not on the corporate whitelist (Skipping MCP server "<name>": not permitted by enterprise managed allow list), so a throwaway stdio test server never gets spawned at all. Anyone on an unrestricted account should be able to reproduce with any trivial stdio MCP server.

Expected behavior

When the MCP client is rebuilt after authentication, the previous generation of stdio child processes should be terminated and reaped — the same teardown that 1.0.51 added for session.disconnect().

Ideally the post-authentication reconfiguration would only (re)start the GitHub MCP server rather than recycling every configured server, since the other servers' configuration has not changed.

Additional context

Timeline from one real session (1.0.78), from --log-level debug:

17:16:11  spawn stdio server #1 (pid A); connect HTTP servers
17:17:02  stdio server #1 completes handshake ("Service initialized as client")
17:17:02  [ERROR] GitHub MCP server configured after authentication
17:17:03  → entire MCP client rebuilt:
             - spawn stdio server #2 (pid B)
             - HTTP servers: "worker quit with fatal: Transport channel closed"
             - "Handling tools refresh for <server>"
17:17:14  stdio server #2 completes handshake

pid A is never killed. It keeps running with its stdin pipe dangling.

Decisive evidence that the child is abandoned, not merely idle:

I killed the 6 suspected orphans across my running sessions. All 6 became Z+ (zombie) rather than disappearing:

$ kill 29835 56680 26768 92092 83359 43758
$ ps -p 29835 -o pid=,stat=
29835 Z+

A child only stays a zombie if its parent never called wait()/waitpid(). The CLI processes were still running and still owned these PIDs, but had no outstanding wait on them. After the kill, every session was left with exactly one live MCP child and all sessions kept working normally — confirming the killed ones were dropped, not in use.

Correlation check. Across 4 sessions I compared, the counts matched exactly every time:

occurrences of "GitHub MCP server configured after authentication"
  == number of "Service initialized as client" handshakes for that server
  == number of spawned child processes

Impact. 18 concurrent interactive sessions accumulated 6 orphans. Because this particular stdio server is heavyweight (~25 MB idle, ~570 MB warm), total MCP server residency reached ~3 GB, of which the orphans were pure waste. Long-lived terminal sessions make this monotonically worse — the oldest orphan had been running for 2 days 15 hours before I noticed.

Related issues:

  • #3440 — session.disconnect() does not kill stdio MCP server processes. Closed as fixed in 1.0.51 for the SDK path, but a later comment reports the same leak on 1.0.68 via /new and /resume. This report is a third trigger path: the automatic post-authentication rebuild at startup, which affects plain interactive use with no user action at all. It may be worth fixing the teardown at the MCP-client-rebuild layer rather than per-entry-point.
  • #4206 — quotes the same GitHub MCP server configured after authentication log line for a different symptom, which may help locate the code path.

Environment: macOS 26.6 (darwin-arm64), Node v24.18.1, zsh, Ghostty/iTerm2.

michael3lyb avatar Aug 06 '26 23:08 michael3lyb

[image: Word document] https://docs.google.com/document/d/1Vv7MiZk0pdK_odIWLovY5lMG-QZVwkfT/edit?usp=drivesdk&ouid=108993443380745148471&rtpof=true&sd=true .archivetempmessages.xml.docx https://docs.google.com/document/d/1Vv7MiZk0pdK_odIWLovY5lMG-QZVwkfT/edit?usp=drivesdk&ouid=108993443380745148471&rtpof=true&sd=true

On Fri, 7 Aug 2026 at 12:04 am, Yibai @.***> wrote:

michael3lyb created an issue (github/copilot-cli#4392) https://github.com/github/copilot-cli/issues/4392 Describe the bug

At startup, the CLI spawns its configured MCP servers, then — once GitHub authentication completes — tears down and rebuilds the entire MCP client, re-spawning every configured server. The first generation of stdio child processes is neither killed nor reaped, so each affected session permanently leaks one orphaned MCP server process.

Remote HTTP MCP servers simply reconnect and leave no trace, so the leak is invisible unless you have a local/stdio server configured.

This appears to be a race: only servers that finish their handshake before the post-auth rebuild get orphaned. Servers still cold-starting at that moment are unaffected. Affected version

GitHub Copilot CLI 1.0.78 (Node v24.18.1) Steps to reproduce the behavior

My setup: one local (stdio) MCP server (a Python CLI with a slow cold start, roughly 6–50 s) plus two remote HTTP MCP servers.

  1. Configure a stdio MCP server in ~/.copilot/mcp-config.json that completes its handshake within a few seconds of launch.
  2. Start copilot interactively and wait until the session is ready.
  3. Count the child processes for that server: ps -eo pid,ppid,lstart,command | grep
  4. Observe two live child processes under the same CLI pid, spawned roughly 15–50 s apart. Only the second one is actually in use.

Note on reproduction: I could not produce a minimal repro on this machine, because my org's managed MCP allow list rejects any server not on the corporate whitelist (Skipping MCP server "": not permitted by enterprise managed allow list), so a throwaway stdio test server never gets spawned at all. Anyone on an unrestricted account should be able to reproduce with any trivial stdio MCP server. Expected behavior

When the MCP client is rebuilt after authentication, the previous generation of stdio child processes should be terminated and reaped — the same teardown that 1.0.51 added for session.disconnect().

Ideally the post-authentication reconfiguration would only (re)start the GitHub MCP server rather than recycling every configured server, since the other servers' configuration has not changed. Additional context

Timeline from one real session (1.0.78), from --log-level debug:

17:16:11 spawn stdio server #1 (pid A); connect HTTP servers 17:17:02 stdio server #1 completes handshake ("Service initialized as client") 17:17:02 [ERROR] GitHub MCP server configured after authentication 17:17:03 → entire MCP client rebuilt: - spawn stdio server #2 (pid B) - HTTP servers: "worker quit with fatal: Transport channel closed" - "Handling tools refresh for " 17:17:14 stdio server #2 completes handshake

pid A is never killed. It keeps running with its stdin pipe dangling.

Decisive evidence that the child is abandoned, not merely idle:

I killed the 6 suspected orphans across my running sessions. All 6 became Z+ (zombie) rather than disappearing:

$ kill 29835 56680 26768 92092 83359 43758 $ ps -p 29835 -o pid=,stat= 29835 Z+

A child only stays a zombie if its parent never called wait()/waitpid(). The CLI processes were still running and still owned these PIDs, but had no outstanding wait on them. After the kill, every session was left with exactly one live MCP child and all sessions kept working normally — confirming the killed ones were dropped, not in use.

Correlation check. Across 4 sessions I compared, the counts matched exactly every time:

occurrences of "GitHub MCP server configured after authentication" == number of "Service initialized as client" handshakes for that server == number of spawned child processes

Impact. 18 concurrent interactive sessions accumulated 6 orphans. Because this particular stdio server is heavyweight (~25 MB idle, ~570 MB warm), total MCP server residency reached ~3 GB, of which the orphans were pure waste. Long-lived terminal sessions make this monotonically worse — the oldest orphan had been running for 2 days 15 hours before I noticed.

Related issues:

  • #3440 https://github.com/github/copilot-cli/issues/3440 — session.disconnect() does not kill stdio MCP server processes. Closed as fixed in 1.0.51 for the SDK path, but a later comment reports the same leak on 1.0.68 via /new and /resume. This report is a third trigger path: the automatic post-authentication rebuild at startup, which affects plain interactive use with no user action at all. It may be worth fixing the teardown at the MCP-client-rebuild layer rather than per-entry-point.
  • #4206 https://github.com/github/copilot-cli/issues/4206 — quotes the same GitHub MCP server configured after authentication log line for a different symptom, which may help locate the code path.

Environment: macOS 26.6 (darwin-arm64), Node v24.18.1, zsh, Ghostty/iTerm2.

— Reply to this email directly, view it on GitHub https://github.com/github/copilot-cli/issues/4392?email_source=notifications&email_token=CFAKGEEBGKG4RCDZEBSCS5T5IUFJDA5CNFSL4Z3JMQ5C6L3HNF2C22DVMIXUS43TOVSS6NJQHA2TEOJZGY2DHJTSMVQXG33OVJZXKYTTMNZGSYTFMSSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L, or unsubscribe https://github.com/notifications/unsubscribe-auth/CFAKGEBU7SR7KN5ZNK26OU35IUFJDAVCNFSNUABFKJSXA33TNF2G64TZHM2TQNJYGYYDMNRUHNEXG43VMU5TKMBYGUZDSOJWGQZ2C5QC . You are receiving this because you are subscribed to this thread.Message ID: @.***>

marymcclean80-crypto avatar Aug 06 '26 23:08 marymcclean80-crypto

Confirming this on 1.0.80 (this report was 1.0.78), with an independent reproduction and one extra data point that may help isolate it: two other CLIs spawning the same stdio MCP server on the same machine do not show the behaviour.

Reproduction, 2026-08-18, macOS (darwin-arm64), Node v24.14.1, zsh

One local Python stdio MCP server, configured in ~/.copilot/mcp-config.json. Four interactive Copilot sessions had been open for between 2.6 and 6 days.

The duplicate spawn lands exactly in the window described here. One session (11907, up 6 days) held two live children of that server, born 32 seconds apart:

PID     PPID    STARTED
12290   11907   Aug 12 15:56:19
13048   11907   Aug 12 15:56:51

Both were still alive six days later. The other three sessions held one each.

The unreaped-exit half reproduces too. I sent SIGTERM to ten stale children of that server in one batch: six parented to claude, four (five counting the duplicate) parented to copilot. Result:

parent children signalled outcome
claude 6 reaped within seconds, PIDs gone
copilot 5 Z / <defunct>, still unreaped 4 minutes later, and still now
  PID   STAT  PPID   COMMAND
  12290 Z     11907  <defunct>
  13048 Z     11907  <defunct>
  34170 Z     34050  <defunct>
  59932 Z     59608  <defunct>
  71954 Z     71639  <defunct>

Those five were the only zombie processes on the machine at that moment, which rules out machine-wide reaping pressure as an explanation.

The cross-client contrast

The same stdio MCP server, same binary, same machine, same day, under three different hosts:

  • Copilot CLI: duplicate spawn, and no wait() on exit.
  • Claude Code: one child per session, reaped immediately on exit. It does not eagerly respawn, but it never leaks.
  • Pi: one child per session, and it replaced its own child (a new PID appeared under the same parent) without any intervention.

Since the server being spawned is identical in all three cases, the difference is in the host's child-process lifecycle, not in the server's exit path.

One thing I could not confirm

The report above says only the second child is actually in use. I killed both children of 11907 in the same batch, so I cannot corroborate that half. What I can say is that the session had held two for six days.

Why it is worth more than the PID count suggests

A zombie costs only a process table entry, but the live duplicate is the expensive half, and not only in memory. A long-lived stdio MCP server holds the code it imported at boot, so an abandoned-but-running child keeps answering with whatever it loaded that day. In our case a duplicate that had been up for six days was serving a stale build of tooling that writes to a knowledge store, and the writes it dropped were reported upstream as successful. Detecting the duplicate is not obvious from inside a session either: from the client's point of view everything works, because the child in use is the fresh one.

lucaspretti avatar Aug 18 '26 18:08 lucaspretti

Thanks for the report. We've shipped fixes in this area since this was filed (most recently in Copilot CLI v1.0.98), and we believe this may now be resolved. Could you retest on the latest release (Copilot CLI v1.0.103) and let us know whether you still see it? If we don't hear back in a couple of weeks, we may close this issue — you can always reopen it.

Triaged as part of a Copilot SDK backlog review, with help from GitHub Copilot.

patniko avatar Oct 26 '26 21:10 patniko

Closing this older report as stale: a retest on a current CLI release was requested on October 26, and there has been no follow-up. This does not establish that the underlying problem is fixed. If it still reproduces, please reopen with the CLI version and reproduction details.

hstaudacher avatar Nov 10 '26 16:11 hstaudacher