From 6c3c4919ffec6f708fb81751135688833381d006 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 20:54:04 +0000 Subject: [PATCH] fix(mcpx): make supervised stdio opt-in again #9963 made supervised stdio the default, and about 20 mcpx e2e tests have failed on main since. The supervisor socket is keyed by server name only (SupervisorSocketPath), so a server's second scoped instance (another session, repo or worktree scope) attached to the first instance's supervisor and was refused ("supervisor refused attach: already attached"), and supervisors outlived `mcpx stop`, leaving sockets and child processes behind. Stop materializing the default at file load: "supervised": true still opts in and everything #9963 added for it (restart through the supervisor, adopt-or-reap scan) is unchanged. The default can return once sockets are keyed per instance and stop reaps supervisors. Co-Authored-By: Claude Opus 5.5 --- pkgs/mcpx/internal/config/config.go | 21 +++++++------------ .../config/supervised_default_test.go | 19 +++++++++-------- .../internal/pool/supervised_default_test.go | 8 +++---- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/pkgs/mcpx/internal/config/config.go b/pkgs/mcpx/internal/config/config.go index cc369fe107..b19ca53880 100644 --- a/pkgs/mcpx/internal/config/config.go +++ b/pkgs/mcpx/internal/config/config.go @@ -1588,20 +1588,13 @@ func parse(b []byte) (*Config, error) { if s.URL != "" && s.Transport == "" { s.Transport = "http" } - // Phase 3 of #1384 (#9963): supervised stdio is the default. - // Materialize it here, at file load, so every consumer of a - // parsed config (daemon, CLI, settings views) sees the same - // resolved value and an explicit "supervised": false remains - // the one opt-out into the legacy direct-spawn path. - if s.Command != "" { - if s.Mcpx == nil { - s.Mcpx = &Extras{} - } - if s.Mcpx.Supervised == nil { - tr := true - s.Mcpx.Supervised = &tr - } - } + // Supervised stdio is opt-in again ("supervised": true). #9963 + // made it the default, but the supervisor socket is keyed by + // server name alone, so a server's second scoped instance + // (another session, repo or worktree) attached to the first + // one's supervisor and was refused, and supervisors outlived + // `mcpx stop`. The default returns once sockets are keyed per + // instance and stop reaps them. } return c, nil } diff --git a/pkgs/mcpx/internal/config/supervised_default_test.go b/pkgs/mcpx/internal/config/supervised_default_test.go index b7fb62c7b3..0868fff5d2 100644 --- a/pkgs/mcpx/internal/config/supervised_default_test.go +++ b/pkgs/mcpx/internal/config/supervised_default_test.go @@ -6,10 +6,11 @@ import ( "github.com/developing-today/code/pkgs/mcpx/internal/config" ) -// Phase 3 of #1384 (#9963): a config loaded from a file defaults its -// stdio servers to supervised; "supervised": false is the opt-out -// into the legacy direct-spawn path, and HTTP servers are untouched. -func TestSupervisedDefaultsOnForStdioFromFile(t *testing.T) { +// Supervised stdio is opt-in: a stdio server with no supervised key +// runs direct-spawn; "supervised": true opts in, false stays out, and +// HTTP servers are untouched. (#9963 made it the default; that is +// paused until the supervisor socket is keyed per instance.) +func TestSupervisedIsOptInForStdioFromFile(t *testing.T) { dir := t.TempDir() p := write(t, dir, "c.json", `{ "mcpServers": { @@ -23,11 +24,11 @@ func TestSupervisedDefaultsOnForStdioFromFile(t *testing.T) { if err != nil { t.Fatal(err) } - if !c.MCPServers["plain"].Mcpx.SupervisedEnabled() { - t.Fatal("a stdio server with no supervised key should default to supervised after a file load") + if c.MCPServers["plain"].Mcpx.SupervisedEnabled() { + t.Fatal("a stdio server with no supervised key should not be supervised") } if c.MCPServers["optout"].Mcpx.SupervisedEnabled() { - t.Fatal("supervised:false should opt out of the default") + t.Fatal("supervised:false should not be supervised") } if !c.MCPServers["optin"].Mcpx.SupervisedEnabled() { t.Fatal("supervised:true should stay supervised") @@ -35,11 +36,11 @@ func TestSupervisedDefaultsOnForStdioFromFile(t *testing.T) { if c.MCPServers["web"].Mcpx != nil && c.MCPServers["web"].Mcpx.SupervisedEnabled() { t.Fatal("an HTTP server should not be defaulted to supervised") } - r, err := c.Resolve("plain") + r, err := c.Resolve("optin") if err != nil { t.Fatal(err) } if !r.Mcpx.SupervisedEnabled() { - t.Fatal("the resolved config should carry the supervised default to the pool") + t.Fatal("the resolved config should carry the supervised opt-in to the pool") } } diff --git a/pkgs/mcpx/internal/pool/supervised_default_test.go b/pkgs/mcpx/internal/pool/supervised_default_test.go index 1dd9ecadaa..1d96748785 100644 --- a/pkgs/mcpx/internal/pool/supervised_default_test.go +++ b/pkgs/mcpx/internal/pool/supervised_default_test.go @@ -17,8 +17,8 @@ import ( ) // Phase 3 of #1384 (#9963), the headline acceptance: a fresh daemon -// start with a default config — loaded from a file, no supervised -// key anywhere — runs its stdio servers supervised. The pool is what +// start with a config loaded from a file that opts its stdio server +// in runs it supervised (opt-in while sockets are keyed by name). The pool is what // a daemon start builds from the resolved config, so the proof is: // load, resolve, acquire, and a supervisor socket exists with the // instance's child behind it. @@ -28,7 +28,7 @@ func TestDefaultConfigStdioRunsSupervised(t *testing.T) { bin := testsupport.EraMCPBinary(t) log := filepath.Join(t.TempDir(), "frames") cfgPath := filepath.Join(t.TempDir(), "mcpx.json") - body := `{"mcpServers": {"era": {"command": "` + bin + `", "env": {"ERAMCP_MODE": "modern", "ERAMCP_LOG": "` + log + `"}}}}` + body := `{"mcpServers": {"era": {"command": "` + bin + `", "env": {"ERAMCP_MODE": "modern", "ERAMCP_LOG": "` + log + `"}, "mcpx": {"supervised": true}}}}` if err := os.WriteFile(cfgPath, []byte(body), 0o644); err != nil { t.Fatal(err) } @@ -41,7 +41,7 @@ func TestDefaultConfigStdioRunsSupervised(t *testing.T) { t.Fatal(err) } if !r.Mcpx.SupervisedEnabled() { - t.Fatal("default config should resolve to supervised") + t.Fatal("an opted-in config should resolve to supervised") } p := pool.New(r) defer p.Close()