From e9fba667f311d8a249d05d661646cea5ba929bce Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Thu, 5 Nov 2026 21:27:39 +0000 Subject: [PATCH 01/14] tests: an update that removes a signed-in MCP server keeps its credentials (red) --- .../agentPlugins/installService.test.ts | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/src/node/services/agentPlugins/installService.test.ts b/src/node/services/agentPlugins/installService.test.ts index bfbb8a4208d..33f1f8931cd 100644 --- a/src/node/services/agentPlugins/installService.test.ts +++ b/src/node/services/agentPlugins/installService.test.ts @@ -4568,6 +4568,118 @@ describe("AgentPluginInstallService", () => { await oauth.dispose(); }); + describe("an update that removes a signed-in MCP server", () => { + const docsUrl = "https://docs.example.com/mcp"; + const keepUrl = "https://keep.example.com/mcp"; + const oauthEntry = (url: string, clientId: string) => ({ + type: "streamable-http", + url, + extensions: { + "com.openai": { auth: { type: "oauth", client: { mode: "provided", clientId } } }, + }, + }); + /** Commits the plugin's MCP file with `servers`, or without the file when `servers` is undefined. */ + const writeServers = async (servers: Record | undefined) => { + const file = path.join(remoteDir, "mcp.json"); + if (servers === undefined) await fsPromises.rm(file); + else + await fsPromises.writeFile( + file, + JSON.stringify({ $schema: AGENT_PLUGIN_MCP_SCHEMA_ID_1_0_0, mcpServers: servers }) + ); + await commitAll(remoteDir, Object.keys(servers ?? {}).join(" ") || "no MCP file"); + }; + const signedInStore = (urls: string[]) => + JSON.stringify({ + version: 2, + entries: Object.fromEntries( + urls.map((serverUrl) => [ + serverUrl, + { + serverUrl, + updatedAtMs: Date.now(), + clientInformation: { client_id: "client-a" }, + tokens: { access_token: "at", token_type: "Bearer" }, + }, + ]) + ), + }); + /** Installs `servers`, then signs in to `signedInUrls` with the real sign-in service. */ + const installSignedIn = async (servers: Record, signedInUrls: string[]) => { + const updater = new AgentPluginInstallService(config, { + mcpServerManager: { + stopServersWithKeyPrefix: () => Promise.resolve(), + } as unknown as MCPServerManager, + }); + await writeServers(servers); + const preview = await updater.preview({ input: remoteDir }); + await updater.install({ source: preview.source, expectedSha: preview.lockedSha }); + await fsPromises.writeFile(path.join(muxRoot, "mcp-oauth.json"), signedInStore(signedInUrls)); + const oauth = new McpOauthService(config, new MCPConfigService(config)); + const logout = spyOn(oauth, "logout"); + updater.setMcpOauthService(oauth); + const update = async (servers: Record | undefined) => { + await writeServers(servers); + const review = await updater.previewUpdate({ name: "demo-plugin" }); + await updater.update({ + name: "demo-plugin", + consent: { fromSha: review.fromSha, toSha: review.toSha }, + }); + }; + return { oauth, logout, update }; + }; + + test("signs out the removed server, so a later server at its URL does not inherit the credentials", async () => { + const { oauth, update } = await installSignedIn( + { docs: oauthEntry(docsUrl, "client-a"), keep: oauthEntry(keepUrl, "client-k") }, + [docsUrl, keepUrl] + ); + await update({ keep: oauthEntry(keepUrl, "client-k") }); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); + // A server the update keeps stays signed in. + expect(await oauth.hasAuthTokens({ serverUrl: keepUrl })).toBe(true); + // The URL comes back under another client: nothing of the old sign-in is left to reuse. + await update({ + keep: oauthEntry(keepUrl, "client-k"), + docs: oauthEntry(docsUrl, "client-b"), + }); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); + await oauth.dispose(); + }); + + test("signs out every server when the update drops the plugin's MCP file", async () => { + const { oauth, update } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + await update(undefined); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); + await oauth.dispose(); + }); + + test("keeps the credentials of a server that is renamed with its URL and client unchanged", async () => { + const { oauth, logout, update } = await installSignedIn( + { docs: oauthEntry(docsUrl, "client-a") }, + [docsUrl] + ); + await update({ docs2: oauthEntry(`${docsUrl}/`, "client-a") }); + expect(logout).not.toHaveBeenCalled(); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(true); + await oauth.dispose(); + }); + + test("does not sign out when the removed server has no sign-in (stdio)", async () => { + const stdio = { type: "stdio", command: "node", args: ["${PLUGIN_ROOT}/server.js"] }; + const { oauth, logout, update } = await installSignedIn( + { local: stdio, docs: oauthEntry(docsUrl, "client-a") }, + [docsUrl] + ); + await update({ docs: oauthEntry(docsUrl, "client-a") }); + expect(logout).not.toHaveBeenCalled(); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(true); + await oauth.dispose(); + }); + }); + test("an update review reads a Codex .mcp.json once per tree, not once per server", async () => { await fsPromises.rm(path.join(remoteDir, "mcp.json")); const servers = (secret: string) => From a8f54f1a66fc6008b8c3560d866b04186894add9 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Thu, 5 Nov 2026 21:36:48 +0000 Subject: [PATCH 02/14] fix: sign out OAuth credentials of MCP servers that a plugin update removes --- .../agentPlugins/installService.test.ts | 87 +++++++++++------ .../services/agentPlugins/installService.ts | 94 ++++++++++++++----- 2 files changed, 128 insertions(+), 53 deletions(-) diff --git a/src/node/services/agentPlugins/installService.test.ts b/src/node/services/agentPlugins/installService.test.ts index 33f1f8931cd..ba18d189a25 100644 --- a/src/node/services/agentPlugins/installService.test.ts +++ b/src/node/services/agentPlugins/installService.test.ts @@ -32,6 +32,7 @@ import { import { AgentPluginInstallService, describeSignInChanges, + signInResetUrls, withDiskQuotaWatchdog, } from "./installService"; import { @@ -4616,7 +4617,6 @@ describe("AgentPluginInstallService", () => { await updater.install({ source: preview.source, expectedSha: preview.lockedSha }); await fsPromises.writeFile(path.join(muxRoot, "mcp-oauth.json"), signedInStore(signedInUrls)); const oauth = new McpOauthService(config, new MCPConfigService(config)); - const logout = spyOn(oauth, "logout"); updater.setMcpOauthService(oauth); const update = async (servers: Record | undefined) => { await writeServers(servers); @@ -4626,9 +4626,11 @@ describe("AgentPluginInstallService", () => { consent: { fromSha: review.fromSha, toSha: review.toSha }, }); }; - return { oauth, logout, update }; + return { oauth, update }; }; + // The 20 s limits: each test installs and updates a plugin over git, which takes more than the + // default 5 s on a loaded runner. test("signs out the removed server, so a later server at its URL does not inherit the credentials", async () => { const { oauth, update } = await installSignedIn( { docs: oauthEntry(docsUrl, "client-a"), keep: oauthEntry(keepUrl, "client-k") }, @@ -4645,7 +4647,7 @@ describe("AgentPluginInstallService", () => { }); expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); await oauth.dispose(); - }); + }, 20_000); test("signs out every server when the update drops the plugin's MCP file", async () => { const { oauth, update } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ @@ -4654,30 +4656,7 @@ describe("AgentPluginInstallService", () => { await update(undefined); expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); await oauth.dispose(); - }); - - test("keeps the credentials of a server that is renamed with its URL and client unchanged", async () => { - const { oauth, logout, update } = await installSignedIn( - { docs: oauthEntry(docsUrl, "client-a") }, - [docsUrl] - ); - await update({ docs2: oauthEntry(`${docsUrl}/`, "client-a") }); - expect(logout).not.toHaveBeenCalled(); - expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(true); - await oauth.dispose(); - }); - - test("does not sign out when the removed server has no sign-in (stdio)", async () => { - const stdio = { type: "stdio", command: "node", args: ["${PLUGIN_ROOT}/server.js"] }; - const { oauth, logout, update } = await installSignedIn( - { local: stdio, docs: oauthEntry(docsUrl, "client-a") }, - [docsUrl] - ); - await update({ docs: oauthEntry(docsUrl, "client-a") }); - expect(logout).not.toHaveBeenCalled(); - expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(true); - await oauth.dispose(); - }); + }, 20_000); }); test("an update review reads a Codex .mcp.json once per tree, not once per server", async () => { @@ -8991,6 +8970,60 @@ describe("describeSignInChanges", () => { }); }); +describe("signInResetUrls", () => { + // The credential key drops a trailing slash, as McpOauthService.credentialKey does. + const key = (url: string): string | null => url.replace(/\/$/, ""); + const tree = (servers: Record) => + new Map( + Object.entries(servers).map(([name, signIn]) => [name, signIn === null ? {} : { signIn }]) + ); + const at = (url: string, identity: string) => ({ url, identity }); + const mcp = "https://mcp.example.com/mcp"; + + test("resets a server whose identity changes, and no server whose identity stays", () => { + expect(signInResetUrls(tree({ a: at(mcp, "x") }), tree({ a: at(mcp, "y") }), key)).toEqual([ + mcp, + ]); + expect(signInResetUrls(tree({ a: at(mcp, "x") }), tree({ a: at(mcp, "x") }), key)).toEqual([]); + }); + + test("matches by credential key: a respelled URL with the same identity is not a removal", () => { + expect( + signInResetUrls(tree({ a: at(mcp, "x") }), tree({ b: at(`${mcp}/`, "x") }), key) + ).toEqual([]); + expect( + signInResetUrls(tree({ a: at(mcp, "x") }), tree({ b: at(`${mcp}/`, "y") }), key) + ).toEqual([`${mcp}/`]); + }); + + test("a sibling that already has the new identity does not mask a change", () => { + const current = tree({ a: at(mcp, "x"), b: at(mcp, "y") }); + expect(signInResetUrls(current, tree({ a: at(mcp, "y"), b: at(mcp, "y") }), key)).toEqual([ + mcp, + ]); + // A renamed entry has no previous self: any other identity at the key resets it. + expect(signInResetUrls(current, tree({ c: at(mcp, "y"), b: at(mcp, "y") }), key)).toEqual([ + mcp, + ]); + expect( + signInResetUrls(tree({ a: at(mcp, "y"), b: at(mcp, "y") }), tree({ c: at(mcp, "y") }), key) + ).toEqual([]); + }); + + test("resets the URL of each server the update removes, and no other", () => { + const other = "https://other.example.com/mcp"; + const current = tree({ a: at(mcp, "x"), b: at(other, "x"), local: null }); + expect(signInResetUrls(current, tree({ b: at(other, "x") }), key)).toEqual([mcp]); + expect(signInResetUrls(current, tree({}), key)).toEqual([mcp, other]); + }); + + test("a server added at a new key, a tree with no current servers and an unkeyed URL reset nothing", () => { + expect(signInResetUrls(tree({}), tree({ a: at(mcp, "x") }), key)).toEqual([]); + expect(signInResetUrls(undefined, tree({ a: at(mcp, "x") }), key)).toEqual([]); + expect(signInResetUrls(tree({ a: at(mcp, "x") }), tree({}), () => null)).toEqual([]); + }); +}); + describe("file review of a Cursor plugin with a runnable command hook (D1, D30)", () => { let muxRoot: string; let remoteDir: string; diff --git a/src/node/services/agentPlugins/installService.ts b/src/node/services/agentPlugins/installService.ts index 34910914704..3f630080890 100644 --- a/src/node/services/agentPlugins/installService.ts +++ b/src/node/services/agentPlugins/installService.ts @@ -1750,6 +1750,73 @@ export function describeSignInChanges(before?: SurfaceSignIn, after?: SurfaceSig return lines; } +/** One tree's sign-ins by credential key: the URL, and the identity of each server name there. */ +interface SignInKeyEntry { + url: string; + identities: Map; +} + +function indexSignIns( + servers: ReadonlyMap | undefined, + credentialKey: (url: string) => string | null +): Map { + const index = new Map(); + for (const [serverName, { signIn }] of servers ?? []) { + const key = signIn && credentialKey(signIn.url); + if (!key || !signIn) continue; + const entry = index.get(key) ?? { url: signIn.url, identities: new Map() }; + entry.identities.set(serverName, signIn.identity); + index.set(key, entry); + } + return index; +} + +/** + * Compare an entry with its own previous identity (same name, same key): when two servers share + * a URL, another entry already using the new identity must not mask the change. A renamed (or + * added) entry has no previous self, and the stored credentials cannot be traced to one entry: + * it changed whenever any identity at the key differs. + */ +function signInIdentityChanged( + before: ReadonlyMap, + serverName: string, + identity: string +): boolean { + const previous = before.get(serverName); + return previous !== undefined + ? previous !== identity + : [...before.values()].some((other) => other !== identity); +} + +/** + * The server URLs whose stored credentials an update must sign out: a key whose sign-in identity + * changes, and a key the update removes. A removed server keeps its credentials under its URL, + * and a later update can add a server at that URL under another identity with no current server + * left to show the change, so the removal is the only moment to sign out. A needless sign-out is + * acceptable; stale credentials offered under a new identity are not. + */ +export function signInResetUrls( + current: ReadonlyMap | undefined, + staged: ReadonlyMap, + credentialKey: (url: string) => string | null +): string[] { + const before = indexSignIns(current, credentialKey); + const after = indexSignIns(staged, credentialKey); + const resets: string[] = []; + for (const [key, now] of after) { + const was = before.get(key); + if ( + was !== undefined && + [...now.identities].some(([serverName, identity]) => + signInIdentityChanged(was.identities, serverName, identity) + ) + ) + resets.push(now.url); + } + for (const [key, was] of before) if (!after.has(key)) resets.push(was.url); + return resets; +} + const LOGO_MAX_BYTES = 512 * 1024; // No SVG: a data-URL cannot run script, but raster-only keeps the // renderer away from markup altogether. No GIF: OpenAI does not list it, and it @@ -3251,32 +3318,7 @@ export class AgentPluginInstallService { // respelled URL (`/mcp` vs `/mcp/`) with a new identity still resets. const credentialKey = (url: string): string | null => this.mcpOauthService?.credentialKey(url) ?? null; - // Compare each entry with its own previous identity (same name, same key): when two - // servers share a URL, another entry already using the new identity must not mask the - // change. A renamed (or added) entry has no previous self, and the stored credentials - // cannot be traced to one entry: reset whenever any identity at the key differs. A - // needless sign-out is acceptable; stale credentials offered under a new identity are not. - const currentIdentities = new Map>(); - const currentEntryIdentity = new Map(); - for (const [serverName, server] of current?.servers ?? []) { - const key = server.signIn && credentialKey(server.signIn.url); - if (!key || !server.signIn) continue; - const identities = currentIdentities.get(key) ?? new Set(); - identities.add(server.signIn.identity); - currentIdentities.set(key, identities); - currentEntryIdentity.set(`${serverName}\0${key}`, server.signIn.identity); - } - for (const [serverName, server] of staged.servers) { - const key = server.signIn && credentialKey(server.signIn.url); - if (!key || !server.signIn) continue; - const previous = currentEntryIdentity.get(`${serverName}\0${key}`); - const identity = server.signIn.identity; - const changed = - previous !== undefined - ? previous !== identity - : [...(currentIdentities.get(key) ?? [])].some((other) => other !== identity); - if (changed) signInResets?.push(server.signIn.url); - } + signInResets?.push(...signInResetUrls(current?.servers, staged.servers, credentialKey)); // Skill advertisements interpolate into the model-visible skill index on // every request, so a new skill — or a reworded description — can inject // instructions without the user ever invoking it. Gate both. From ef602f8ee80ac1184cfeebc6eb3dd773ad33357f Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Thu, 5 Nov 2026 21:49:20 +0000 Subject: [PATCH 03/14] tests: an uninstall leaves the plugin's OAuth credentials stored (red) --- .../agentPlugins/installService.test.ts | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/node/services/agentPlugins/installService.test.ts b/src/node/services/agentPlugins/installService.test.ts index ba18d189a25..4ccb4825c1c 100644 --- a/src/node/services/agentPlugins/installService.test.ts +++ b/src/node/services/agentPlugins/installService.test.ts @@ -4569,7 +4569,7 @@ describe("AgentPluginInstallService", () => { await oauth.dispose(); }); - describe("an update that removes a signed-in MCP server", () => { + describe("stored sign-ins of plugin MCP servers that an update removes or an uninstall deletes", () => { const docsUrl = "https://docs.example.com/mcp"; const keepUrl = "https://keep.example.com/mcp"; const oauthEntry = (url: string, clientId: string) => ({ @@ -4626,7 +4626,7 @@ describe("AgentPluginInstallService", () => { consent: { fromSha: review.fromSha, toSha: review.toSha }, }); }; - return { oauth, update }; + return { updater, oauth, update }; }; // The 20 s limits: each test installs and updates a plugin over git, which takes more than the @@ -4657,6 +4657,52 @@ describe("AgentPluginInstallService", () => { expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); await oauth.dispose(); }, 20_000); + + test("an uninstall signs out the plugin's servers, so a reinstall under another client does not inherit them", async () => { + const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + await updater.uninstall({ name: "demo-plugin", deletePluginData: false }); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); + await writeServers({ docs: oauthEntry(docsUrl, "client-b") }); + const preview = await updater.preview({ input: remoteDir }); + await updater.install({ source: preview.source, expectedSha: preview.lockedSha }); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); + await oauth.dispose(); + }, 20_000); + + test("an uninstall that fails keeps the sign-in and records no sign-out", async () => { + const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + const internals = updater as unknown as { + writeRegistry: (envelope: Record, entries: unknown[]) => Promise; + }; + const writeSpy = spyOn(internals, "writeRegistry").mockImplementationOnce(() => + Promise.reject(new Error("ENOSPC: no space left on device")) + ); + try { + await expect( + updater.uninstall({ name: "demo-plugin", deletePluginData: false }) + ).rejects.toThrow(/persist the plugin registry/); + } finally { + writeSpy.mockRestore(); + } + expect(await registry()).toHaveLength(1); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(true); + expect(await pathExists(path.join(muxRoot, "plugin-sign-outs-pending.json"))).toBe(false); + await oauth.dispose(); + }, 20_000); + + test("a plugin whose MCP file cannot be read can still be uninstalled", async () => { + const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + await fsPromises.writeFile(path.join(pluginsDir(), "demo-plugin", "mcp.json"), "{ not json"); + await updater.uninstall({ name: "demo-plugin", deletePluginData: false }); + expect(await registry()).toEqual([]); + await oauth.dispose(); + }, 20_000); }); test("an update review reads a Codex .mcp.json once per tree, not once per server", async () => { From 87524166647437dfa8656f1ca6e786b0e3934427 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Thu, 5 Nov 2026 21:51:39 +0000 Subject: [PATCH 04/14] fix: sign out OAuth credentials of a plugin's MCP servers when it is uninstalled --- docs/config/mcp-servers.mdx | 2 +- .../services/agentPlugins/installService.ts | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/docs/config/mcp-servers.mdx b/docs/config/mcp-servers.mdx index 9b0f2fc1a9f..ea8c8290177 100644 --- a/docs/config/mcp-servers.mdx +++ b/docs/config/mcp-servers.mdx @@ -68,7 +68,7 @@ A remote plugin server can declare OAuth sign-in settings (a client, scopes, an Stdio plugin servers launch with the spec's `PLUGIN_ROOT` and `PLUGIN_DATA` environment variables; per-plugin data directories live under `~/.xum/plugin-data/`. -**Settings → Plugins** installs plugins from git into `~/.xum/plugins` (paste a git URL or `owner/repo[/path/to/plugin][@ref]`); the exact location derives from the active Xum home (a legacy `~/.mux` home keeps working) and is shown in the section. Before anything is written, a consent preview lists the plugin's manifest, every skill, and every MCP server command line. Installs are pinned to the resolved commit; update checks compare the tracked branch or tag against the pinned commit and never auto-apply. With a monorepo subpath (for example `cursor/plugins/pstack`; for a full git URL, enter the folder in the **Plugin folder** field), Xum downloads only that folder's files (a sparse, partial clone) and installs it as the plugin, and the consent preview and update reviews cover only that folder: an upstream commit that changes only files outside it still shows as an update, but applies without a new review. Applying an update replaces the plugin directory wholesale — local edits to a managed plugin directory are discarded — and restarts that plugin's running MCP servers. Uninstalling removes the directory, the registry entry, and the plugin's global enablement and per-workspace server overrides, but keeps `~/.xum/plugin-data/` unless you opt in to deleting it. +**Settings → Plugins** installs plugins from git into `~/.xum/plugins` (paste a git URL or `owner/repo[/path/to/plugin][@ref]`); the exact location derives from the active Xum home (a legacy `~/.mux` home keeps working) and is shown in the section. Before anything is written, a consent preview lists the plugin's manifest, every skill, and every MCP server command line. Installs are pinned to the resolved commit; update checks compare the tracked branch or tag against the pinned commit and never auto-apply. With a monorepo subpath (for example `cursor/plugins/pstack`; for a full git URL, enter the folder in the **Plugin folder** field), Xum downloads only that folder's files (a sparse, partial clone) and installs it as the plugin, and the consent preview and update reviews cover only that folder: an upstream commit that changes only files outside it still shows as an update, but applies without a new review. Applying an update replaces the plugin directory wholesale — local edits to a managed plugin directory are discarded — and restarts that plugin's running MCP servers. An update also signs out of a remote server whose sign-in settings change or that the update removes. Uninstalling removes the directory, the registry entry, the plugin's global enablement and per-workspace server overrides, and the stored sign-in of each remote MCP server it declares, but keeps `~/.xum/plugin-data/` unless you opt in to deleting it. Stored sign-ins are keyed by server URL, so another server at the same URL is signed out too. ### Plugin server environment diff --git a/src/node/services/agentPlugins/installService.ts b/src/node/services/agentPlugins/installService.ts index 3f630080890..fa0bca7a18f 100644 --- a/src/node/services/agentPlugins/installService.ts +++ b/src/node/services/agentPlugins/installService.ts @@ -5579,6 +5579,34 @@ export class AgentPluginInstallService { return urls; } + /** + * The remote MCP server URLs of an installed plugin's tree: what an uninstall signs out. A + * server that fails to load never ran and holds no sign-in, so it is not listed. A tree Xum + * cannot read lists none and is logged: it must stay removable. + */ + private async installedServerUrls(name: string): Promise { + try { + const { plugin } = await discoverAgentPluginAt({ + pluginDir: this.targetPathFor(name), + scope: "global", + }); + if (plugin?.mcpConfigPath === undefined) return []; + const { servers } = await loadPluginMcpServers(plugin, { + xumHome: this.config.rootDir, + instanceId: this.instanceIdFor(name), + }); + return Object.values(servers).flatMap((info) => + info.transport === "stdio" ? [] : [info.url] + ); + } catch (error) { + log.warn("Could not list the MCP servers of a plugin that is being uninstalled", { + plugin: name, + error: getErrorMessage(error), + }); + return []; + } + } + /** One plugin tree's remote MCP server URLs; throws when the tree's servers cannot be read. */ private async pluginTreeServerUrls(dirName: string, installed: boolean): Promise { // Plugin trees are directories (or links to one), dot-prefixed names included, as discovery @@ -5798,6 +5826,8 @@ export class AgentPluginInstallService { const targetPath = this.targetPathFor(entry.name); const instanceId = this.instanceIdFor(entry.name); const serverKeyPrefix = buildPluginServerKey(instanceId, ""); + // Read before the tree moves: its servers' stored sign-ins are keyed by URL and outlive it. + const signOutUrls = await this.installedServerUrls(entry.name); // Enumerate pruning targets BEFORE committing anything: if this fails, // the uninstall aborts with the install fully intact (retryable from @@ -5934,7 +5964,11 @@ export class AgentPluginInstallService { } else { delete commitEnvelope.pendingOverridePrunes; } + let recordedSignOuts: string[] = []; try { + // Recorded before the commit, like an update's: a crash after it leaves the sign-outs for + // the next start (#6122). A failed write aborts the uninstall with the install intact. + recordedSignOuts = await this.recordPendingSignOuts(signOutUrls); // Before the commit, so a failure leaves trust and approved copies cleared (fail closed) // rather than kept for a later install under this name. await removePluginHookTrust(this.config.rootDir, this.instanceIdFor(entry.name)); @@ -5944,6 +5978,8 @@ export class AgentPluginInstallService { rawRegistry.filter((rawEntry) => this.rawEntryName(rawEntry) !== entry.name) ); } catch (error) { + // The plugin stays installed: its servers keep their sign-ins. + await this.forgetPendingSignOuts(recordedSignOuts); const treeRestored = await restoreTree("failed registry write"); let dataRestored = true; if (stagedData) { @@ -6024,6 +6060,10 @@ export class AgentPluginInstallService { await consumeJournal(); } + // Signed out before the final stop, like an update: a startup that raced the sign-out is + // invalidated too. A sign-out that fails stays pending for the next pass. + await this.signOutAndSettle(entry.name, signOutUrls); + // Re-invalidate AFTER the tree is gone: a getToolsForWorkspace call // that started right after the pre-rename stop snapshots the new epoch, // and can still have discovered the plugin before the rename — its From 36f0393e68975398a07ac5afee0438e5dac6e44c Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Thu, 5 Nov 2026 22:04:24 +0000 Subject: [PATCH 05/14] =?UTF-8?q?=F0=9F=A4=96=20chore:=20drop=20narrating?= =?UTF-8?q?=20comments=20from=20the=20plugin=20sign-out=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delete comments that restate the code or a callee's contract. Keep the comments that explain ordering, the removal rationale, and test timeouts. --- src/node/services/agentPlugins/installService.test.ts | 5 ----- src/node/services/agentPlugins/installService.ts | 10 ++++------ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/node/services/agentPlugins/installService.test.ts b/src/node/services/agentPlugins/installService.test.ts index 4ccb4825c1c..680f65ea306 100644 --- a/src/node/services/agentPlugins/installService.test.ts +++ b/src/node/services/agentPlugins/installService.test.ts @@ -4579,7 +4579,6 @@ describe("AgentPluginInstallService", () => { "com.openai": { auth: { type: "oauth", client: { mode: "provided", clientId } } }, }, }); - /** Commits the plugin's MCP file with `servers`, or without the file when `servers` is undefined. */ const writeServers = async (servers: Record | undefined) => { const file = path.join(remoteDir, "mcp.json"); if (servers === undefined) await fsPromises.rm(file); @@ -4605,7 +4604,6 @@ describe("AgentPluginInstallService", () => { ]) ), }); - /** Installs `servers`, then signs in to `signedInUrls` with the real sign-in service. */ const installSignedIn = async (servers: Record, signedInUrls: string[]) => { const updater = new AgentPluginInstallService(config, { mcpServerManager: { @@ -4638,9 +4636,7 @@ describe("AgentPluginInstallService", () => { ); await update({ keep: oauthEntry(keepUrl, "client-k") }); expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(false); - // A server the update keeps stays signed in. expect(await oauth.hasAuthTokens({ serverUrl: keepUrl })).toBe(true); - // The URL comes back under another client: nothing of the old sign-in is left to reuse. await update({ keep: oauthEntry(keepUrl, "client-k"), docs: oauthEntry(docsUrl, "client-b"), @@ -9047,7 +9043,6 @@ describe("signInResetUrls", () => { expect(signInResetUrls(current, tree({ a: at(mcp, "y"), b: at(mcp, "y") }), key)).toEqual([ mcp, ]); - // A renamed entry has no previous self: any other identity at the key resets it. expect(signInResetUrls(current, tree({ c: at(mcp, "y"), b: at(mcp, "y") }), key)).toEqual([ mcp, ]); diff --git a/src/node/services/agentPlugins/installService.ts b/src/node/services/agentPlugins/installService.ts index fa0bca7a18f..40a1c5642a5 100644 --- a/src/node/services/agentPlugins/installService.ts +++ b/src/node/services/agentPlugins/installService.ts @@ -1750,7 +1750,6 @@ export function describeSignInChanges(before?: SurfaceSignIn, after?: SurfaceSig return lines; } -/** One tree's sign-ins by credential key: the URL, and the identity of each server name there. */ interface SignInKeyEntry { url: string; identities: Map; @@ -5580,9 +5579,8 @@ export class AgentPluginInstallService { } /** - * The remote MCP server URLs of an installed plugin's tree: what an uninstall signs out. A - * server that fails to load never ran and holds no sign-in, so it is not listed. A tree Xum - * cannot read lists none and is logged: it must stay removable. + * A server that fails to load never ran and holds no sign-in, so it is not listed. A tree Xum + * cannot read lists none: it must stay removable. */ private async installedServerUrls(name: string): Promise { try { @@ -5967,7 +5965,7 @@ export class AgentPluginInstallService { let recordedSignOuts: string[] = []; try { // Recorded before the commit, like an update's: a crash after it leaves the sign-outs for - // the next start (#6122). A failed write aborts the uninstall with the install intact. + // the next start (#6122). recordedSignOuts = await this.recordPendingSignOuts(signOutUrls); // Before the commit, so a failure leaves trust and approved copies cleared (fail closed) // rather than kept for a later install under this name. @@ -6061,7 +6059,7 @@ export class AgentPluginInstallService { } // Signed out before the final stop, like an update: a startup that raced the sign-out is - // invalidated too. A sign-out that fails stays pending for the next pass. + // invalidated too. await this.signOutAndSettle(entry.name, signOutUrls); // Re-invalidate AFTER the tree is gone: a getToolsForWorkspace call From 15d9cb7713489df51f950d4ba2b15bde1591da40 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Thu, 5 Nov 2026 22:15:59 +0000 Subject: [PATCH 06/14] refactor: name the sign-in identity map by server name, fix sign-out docs --- .../agentPlugins/installService.test.ts | 4 ++++ .../services/agentPlugins/installService.ts | 23 +++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/node/services/agentPlugins/installService.test.ts b/src/node/services/agentPlugins/installService.test.ts index 680f65ea306..6cfbb22c9fd 100644 --- a/src/node/services/agentPlugins/installService.test.ts +++ b/src/node/services/agentPlugins/installService.test.ts @@ -9043,6 +9043,10 @@ describe("signInResetUrls", () => { expect(signInResetUrls(current, tree({ a: at(mcp, "y"), b: at(mcp, "y") }), key)).toEqual([ mcp, ]); + }); + + test("a renamed entry has no previous self: any other identity at the key resets it", () => { + const current = tree({ a: at(mcp, "x"), b: at(mcp, "y") }); expect(signInResetUrls(current, tree({ c: at(mcp, "y"), b: at(mcp, "y") }), key)).toEqual([ mcp, ]); diff --git a/src/node/services/agentPlugins/installService.ts b/src/node/services/agentPlugins/installService.ts index 40a1c5642a5..5b02e7742c1 100644 --- a/src/node/services/agentPlugins/installService.ts +++ b/src/node/services/agentPlugins/installService.ts @@ -1752,7 +1752,7 @@ export function describeSignInChanges(before?: SurfaceSignIn, after?: SurfaceSig interface SignInKeyEntry { url: string; - identities: Map; + identityByServerName: Map; } function indexSignIns( @@ -1763,8 +1763,11 @@ function indexSignIns( for (const [serverName, { signIn }] of servers ?? []) { const key = signIn && credentialKey(signIn.url); if (!key || !signIn) continue; - const entry = index.get(key) ?? { url: signIn.url, identities: new Map() }; - entry.identities.set(serverName, signIn.identity); + const entry = index.get(key) ?? { + url: signIn.url, + identityByServerName: new Map(), + }; + entry.identityByServerName.set(serverName, signIn.identity); index.set(key, entry); } return index; @@ -1806,8 +1809,8 @@ export function signInResetUrls( const was = before.get(key); if ( was !== undefined && - [...now.identities].some(([serverName, identity]) => - signInIdentityChanged(was.identities, serverName, identity) + [...now.identityByServerName].some(([serverName, identity]) => + signInIdentityChanged(was.identityByServerName, serverName, identity) ) ) resets.push(now.url); @@ -5254,8 +5257,8 @@ export class AgentPluginInstallService { } /** - * Removes `urls` from the pending sign-outs: they finished, or the update rolled back before - * the new tree was live. Best effort: a leftover URL only signs the server out once more. + * Removes `urls` from the pending sign-outs: they finished, or the update or uninstall rolled + * back before it took effect. Best effort: a leftover URL only signs the server out once more. */ private async forgetPendingSignOuts(urls: readonly string[]): Promise { if (urls.length === 0) return; @@ -5267,7 +5270,7 @@ export class AgentPluginInstallService { } } - /** Signs out `urls` after an update; the ones that failed stay pending. */ + /** Signs out `urls` after an update or an uninstall; the ones that failed stay pending. */ private async signOutAndSettle(name: string, urls: string[]): Promise { const done: string[] = []; // One deadline for every wait of this update: N hung logouts must not hold the lock N times. @@ -5579,8 +5582,8 @@ export class AgentPluginInstallService { } /** - * A server that fails to load never ran and holds no sign-in, so it is not listed. A tree Xum - * cannot read lists none: it must stay removable. + * A server that fails to load is not listed. A tree Xum cannot read lists none: it must stay + * removable. */ private async installedServerUrls(name: string): Promise { try { From d34850422750d07b054da269a2d444e8a5832e87 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Thu, 5 Nov 2026 22:17:15 +0000 Subject: [PATCH 07/14] tests: an uninstall whose sign-out fails leaves the URL pending --- .../services/agentPlugins/installService.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/node/services/agentPlugins/installService.test.ts b/src/node/services/agentPlugins/installService.test.ts index 6cfbb22c9fd..77e167797f2 100644 --- a/src/node/services/agentPlugins/installService.test.ts +++ b/src/node/services/agentPlugins/installService.test.ts @@ -4667,6 +4667,21 @@ describe("AgentPluginInstallService", () => { await oauth.dispose(); }, 20_000); + test("an uninstall whose sign-out fails leaves the URL pending for the next pass", async () => { + const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + spyOn(oauth, "logout").mockResolvedValue({ success: false, error: "disk full" }); + await updater.uninstall({ name: "demo-plugin", deletePluginData: false }); + expect(await registry()).toEqual([]); + const record = await fsPromises.readFile( + path.join(muxRoot, "plugin-sign-outs-pending.json"), + "utf8" + ); + expect(JSON.parse(record)).toEqual({ version: 1, urls: [docsUrl] }); + await oauth.dispose(); + }, 20_000); + test("an uninstall that fails keeps the sign-in and records no sign-out", async () => { const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ docsUrl, From bec72577caaf4d35eabdf07efebfdb1682e4ddf2 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Thu, 5 Nov 2026 22:40:19 +0000 Subject: [PATCH 08/14] tests: mark the equivalent mutants of the sign-in helpers --- src/node/services/agentPlugins/installService.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/node/services/agentPlugins/installService.ts b/src/node/services/agentPlugins/installService.ts index 5b02e7742c1..8bf4ef3221f 100644 --- a/src/node/services/agentPlugins/installService.ts +++ b/src/node/services/agentPlugins/installService.ts @@ -1760,9 +1760,11 @@ function indexSignIns( credentialKey: (url: string) => string | null ): Map { const index = new Map(); + // mutation-equivalent: a Map is never falsy, so ?? and || agree for (const [serverName, { signIn }] of servers ?? []) { const key = signIn && credentialKey(signIn.url); if (!key || !signIn) continue; + // mutation-equivalent: an entry object is never falsy, so ?? and || agree const entry = index.get(key) ?? { url: signIn.url, identityByServerName: new Map(), @@ -5591,6 +5593,7 @@ export class AgentPluginInstallService { pluginDir: this.targetPathFor(name), scope: "global", }); + // mutation-equivalent: a null plugin throws a TypeError, and the catch also returns [] if (plugin?.mcpConfigPath === undefined) return []; const { servers } = await loadPluginMcpServers(plugin, { xumHome: this.config.rootDir, From 9909513969da00337afe8e3578f7d6a27be55ddf Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Thu, 5 Nov 2026 23:28:05 +0000 Subject: [PATCH 09/14] chore: sync the built-in docs skill content with the MCP docs --- src/node/services/agentSkills/builtInSkillContent.generated.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/services/agentSkills/builtInSkillContent.generated.ts b/src/node/services/agentSkills/builtInSkillContent.generated.ts index a2e210c6d31..566d88304cc 100644 --- a/src/node/services/agentSkills/builtInSkillContent.generated.ts +++ b/src/node/services/agentSkills/builtInSkillContent.generated.ts @@ -4974,7 +4974,7 @@ export const BUILTIN_SKILL_FILES: Record> = { "", "Stdio plugin servers launch with the spec's `PLUGIN_ROOT` and `PLUGIN_DATA` environment variables; per-plugin data directories live under `~/.xum/plugin-data/`.", "", - "**Settings → Plugins** installs plugins from git into `~/.xum/plugins` (paste a git URL or `owner/repo[/path/to/plugin][@ref]`); the exact location derives from the active Xum home (a legacy `~/.mux` home keeps working) and is shown in the section. Before anything is written, a consent preview lists the plugin's manifest, every skill, and every MCP server command line. Installs are pinned to the resolved commit; update checks compare the tracked branch or tag against the pinned commit and never auto-apply. With a monorepo subpath (for example `cursor/plugins/pstack`; for a full git URL, enter the folder in the **Plugin folder** field), Xum downloads only that folder's files (a sparse, partial clone) and installs it as the plugin, and the consent preview and update reviews cover only that folder: an upstream commit that changes only files outside it still shows as an update, but applies without a new review. Applying an update replaces the plugin directory wholesale — local edits to a managed plugin directory are discarded — and restarts that plugin's running MCP servers. Uninstalling removes the directory, the registry entry, and the plugin's global enablement and per-workspace server overrides, but keeps `~/.xum/plugin-data/` unless you opt in to deleting it.", + "**Settings → Plugins** installs plugins from git into `~/.xum/plugins` (paste a git URL or `owner/repo[/path/to/plugin][@ref]`); the exact location derives from the active Xum home (a legacy `~/.mux` home keeps working) and is shown in the section. Before anything is written, a consent preview lists the plugin's manifest, every skill, and every MCP server command line. Installs are pinned to the resolved commit; update checks compare the tracked branch or tag against the pinned commit and never auto-apply. With a monorepo subpath (for example `cursor/plugins/pstack`; for a full git URL, enter the folder in the **Plugin folder** field), Xum downloads only that folder's files (a sparse, partial clone) and installs it as the plugin, and the consent preview and update reviews cover only that folder: an upstream commit that changes only files outside it still shows as an update, but applies without a new review. Applying an update replaces the plugin directory wholesale — local edits to a managed plugin directory are discarded — and restarts that plugin's running MCP servers. An update also signs out of a remote server whose sign-in settings change or that the update removes. Uninstalling removes the directory, the registry entry, the plugin's global enablement and per-workspace server overrides, and the stored sign-in of each remote MCP server it declares, but keeps `~/.xum/plugin-data/` unless you opt in to deleting it. Stored sign-ins are keyed by server URL, so another server at the same URL is signed out too.", "", "### Plugin server environment", "", From c6d743cd62f4a278a64ee1847b344c97941b36ed Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Fri, 6 Nov 2026 00:57:37 +0000 Subject: [PATCH 10/14] tests: pin record-before-commit for uninstall and update, and the uninstall catch --- .../agentPlugins/installService.test.ts | 82 ++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/src/node/services/agentPlugins/installService.test.ts b/src/node/services/agentPlugins/installService.test.ts index 77e167797f2..37d777b47e8 100644 --- a/src/node/services/agentPlugins/installService.test.ts +++ b/src/node/services/agentPlugins/installService.test.ts @@ -4604,10 +4604,19 @@ describe("AgentPluginInstallService", () => { ]) ), }); - const installSignedIn = async (servers: Record, signedInUrls: string[]) => { + const pendingRecord = (): Promise => + fsPromises.readFile(path.join(muxRoot, "plugin-sign-outs-pending.json"), "utf8").then( + (text) => JSON.parse(text) as unknown, + () => null + ); + const installSignedIn = async ( + servers: Record, + signedInUrls: string[], + onStop?: () => Promise + ) => { const updater = new AgentPluginInstallService(config, { mcpServerManager: { - stopServersWithKeyPrefix: () => Promise.resolve(), + stopServersWithKeyPrefix: () => onStop?.() ?? Promise.resolve(), } as unknown as MCPServerManager, }); await writeServers(servers); @@ -4714,6 +4723,75 @@ describe("AgentPluginInstallService", () => { expect(await registry()).toEqual([]); await oauth.dispose(); }, 20_000); + test("an update records its sign-outs before the old tree stops and moves", async () => { + let armed = false; + let atFirstStop: unknown = "not read"; + const { update, oauth } = await installSignedIn( + { docs: oauthEntry(docsUrl, "client-a") }, + [docsUrl], + async () => { + if (armed && atFirstStop === "not read") atFirstStop = await pendingRecord(); + } + ); + armed = true; + await update({ docs: oauthEntry(docsUrl, "client-b") }); + expect(atFirstStop).toEqual({ version: 1, urls: [docsUrl] }); + await oauth.dispose(); + }, 20_000); + + test("an uninstall records its sign-outs before the registry commit", async () => { + const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + const internals = updater as unknown as { + writeRegistry: (envelope: Record, entries: unknown[]) => Promise; + }; + const realWrite = internals.writeRegistry.bind(internals); + let atCommit: unknown = "not read"; + const writeSpy = spyOn(internals, "writeRegistry").mockImplementation( + async (envelope, entries) => { + if (atCommit === "not read") atCommit = await pendingRecord(); + return realWrite(envelope, entries); + } + ); + try { + await updater.uninstall({ name: "demo-plugin", deletePluginData: false }); + } finally { + writeSpy.mockRestore(); + } + expect(atCommit).toEqual({ version: 1, urls: [docsUrl] }); + await oauth.dispose(); + }, 20_000); + + test("an uninstall refuses while the pending sign-out record is corrupt, and leaves the install", async () => { + const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + await fsPromises.writeFile(path.join(muxRoot, "plugin-sign-outs-pending.json"), "{ not json"); + await expect( + updater.uninstall({ name: "demo-plugin", deletePluginData: false }) + ).rejects.toThrow(/Sign out of plugin MCP servers/); + expect(await registry()).toHaveLength(1); + expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(true); + await oauth.dispose(); + }, 20_000); + + test("a plugin whose servers cannot be listed can still be uninstalled", async () => { + const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ + docsUrl, + ]); + const discover = spyOn(discoveryModule, "discoverAgentPluginAt").mockRejectedValueOnce( + new Error("EACCES: permission denied") + ); + try { + await updater.uninstall({ name: "demo-plugin", deletePluginData: false }); + expect(discover).toHaveBeenCalled(); + } finally { + discover.mockRestore(); + } + expect(await registry()).toEqual([]); + await oauth.dispose(); + }, 20_000); }); test("an update review reads a Codex .mcp.json once per tree, not once per server", async () => { From 24b2414bacf598446313b94fc3fe7b072777d66d Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Fri, 6 Nov 2026 02:26:41 +0000 Subject: [PATCH 11/14] tests: an uninstall refuses early on a corrupt pending sign-out record (red) --- .../agentPlugins/installService.test.ts | 57 +++++++++++++++---- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/src/node/services/agentPlugins/installService.test.ts b/src/node/services/agentPlugins/installService.test.ts index 37d777b47e8..2e6e9df31be 100644 --- a/src/node/services/agentPlugins/installService.test.ts +++ b/src/node/services/agentPlugins/installService.test.ts @@ -4612,12 +4612,15 @@ describe("AgentPluginInstallService", () => { const installSignedIn = async ( servers: Record, signedInUrls: string[], - onStop?: () => Promise + hooks: { onStop?: () => Promise; mcpConfigService?: MCPConfigService } = {} ) => { const updater = new AgentPluginInstallService(config, { mcpServerManager: { - stopServersWithKeyPrefix: () => onStop?.() ?? Promise.resolve(), + stopServersWithKeyPrefix: () => hooks.onStop?.() ?? Promise.resolve(), } as unknown as MCPServerManager, + ...(hooks.mcpConfigService !== undefined + ? { mcpConfigService: hooks.mcpConfigService } + : {}), }); await writeServers(servers); const preview = await updater.preview({ input: remoteDir }); @@ -4729,8 +4732,10 @@ describe("AgentPluginInstallService", () => { const { update, oauth } = await installSignedIn( { docs: oauthEntry(docsUrl, "client-a") }, [docsUrl], - async () => { - if (armed && atFirstStop === "not read") atFirstStop = await pendingRecord(); + { + onStop: async () => { + if (armed && atFirstStop === "not read") atFirstStop = await pendingRecord(); + }, } ); armed = true; @@ -4763,14 +4768,44 @@ describe("AgentPluginInstallService", () => { await oauth.dispose(); }, 20_000); - test("an uninstall refuses while the pending sign-out record is corrupt, and leaves the install", async () => { - const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ - docsUrl, - ]); + test("an uninstall refuses at once while the pending sign-out record is corrupt, and changes nothing", async () => { + const mcpConfigService = new MCPConfigService(config, { + agentPluginsMcpProvider: createAgentPluginsMcpProvider({ xumHome: muxRoot }), + }); + let armed = false; + let stops = 0; + const { updater, oauth } = await installSignedIn( + { docs: oauthEntry(docsUrl, "client-a") }, + [docsUrl], + { + mcpConfigService, + onStop: async () => { + if (armed) stops++; + }, + } + ); + const key = buildPluginServerKey( + computePluginInstanceId(path.join(pluginsDir(), "demo-plugin")), + "docs" + ); + expect(await mcpConfigService.setServerEnabled(key, true)).toEqual({ + success: true, + data: undefined, + }); await fsPromises.writeFile(path.join(muxRoot, "plugin-sign-outs-pending.json"), "{ not json"); - await expect( - updater.uninstall({ name: "demo-plugin", deletePluginData: false }) - ).rejects.toThrow(/Sign out of plugin MCP servers/); + armed = true; + const failure = await updater + .uninstall({ name: "demo-plugin", deletePluginData: false }) + .then( + () => undefined, + (error: unknown) => error as Error + ); + // The record's own error, naming the Settings recovery step, before anything moves. + expect(failure?.message).toMatch( + /^The pending plugin sign-out record .*Sign out of plugin MCP servers/ + ); + expect(stops).toBe(0); + expect((await mcpConfigService.listServers())[key]?.disabled).toBe(false); expect(await registry()).toHaveLength(1); expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(true); await oauth.dispose(); From 3dc05b84ef987917517764f7d808edff506482e0 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Fri, 6 Nov 2026 02:28:12 +0000 Subject: [PATCH 12/14] fix: an uninstall reads the pending sign-out record before anything stops or moves --- src/node/services/agentPlugins/installService.test.ts | 6 +++++- src/node/services/agentPlugins/installService.ts | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/node/services/agentPlugins/installService.test.ts b/src/node/services/agentPlugins/installService.test.ts index 2e6e9df31be..509e9582eab 100644 --- a/src/node/services/agentPlugins/installService.test.ts +++ b/src/node/services/agentPlugins/installService.test.ts @@ -4805,7 +4805,11 @@ describe("AgentPluginInstallService", () => { /^The pending plugin sign-out record .*Sign out of plugin MCP servers/ ); expect(stops).toBe(0); - expect((await mcpConfigService.listServers())[key]?.disabled).toBe(false); + // The record fences plugin discovery, so read the global enablement from its file. + const globalConfig = jsonc.parse( + await fsPromises.readFile(path.join(muxRoot, "mcp.jsonc"), "utf8") + ) as { enabledPluginServers?: string[] }; + expect(globalConfig.enabledPluginServers).toEqual([key]); expect(await registry()).toHaveLength(1); expect(await oauth.hasAuthTokens({ serverUrl: docsUrl })).toBe(true); await oauth.dispose(); diff --git a/src/node/services/agentPlugins/installService.ts b/src/node/services/agentPlugins/installService.ts index 7d4539cc852..af2feea721c 100644 --- a/src/node/services/agentPlugins/installService.ts +++ b/src/node/services/agentPlugins/installService.ts @@ -5589,6 +5589,15 @@ export class AgentPluginInstallService { return urls; } + /** + * Throws the pending record's own error when an uninstall that will record sign-outs cannot + * read it. It runs before anything stops or moves: a failure at the commit would roll the tree + * back but not the global MCP enablement. + */ + private async assertPendingSignOutsReadable(urls: readonly string[]): Promise { + if (urls.length > 0) await this.readPendingSignOuts(); + } + /** * A server that fails to load is not listed. A tree Xum cannot read lists none: it must stay * removable. @@ -5838,6 +5847,7 @@ export class AgentPluginInstallService { const serverKeyPrefix = buildPluginServerKey(instanceId, ""); // Read before the tree moves: its servers' stored sign-ins are keyed by URL and outlive it. const signOutUrls = await this.installedServerUrls(entry.name); + await this.assertPendingSignOutsReadable(signOutUrls); // Enumerate pruning targets BEFORE committing anything: if this fails, // the uninstall aborts with the install fully intact (retryable from From a4d83f6c830f4a7cdb4866403935c8ecbb955bca Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Fri, 6 Nov 2026 02:28:50 +0000 Subject: [PATCH 13/14] tests: an uninstall of a stdio-only plugin ignores a corrupt pending record --- src/node/services/agentPlugins/installService.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/node/services/agentPlugins/installService.test.ts b/src/node/services/agentPlugins/installService.test.ts index 509e9582eab..bebd8d42d4f 100644 --- a/src/node/services/agentPlugins/installService.test.ts +++ b/src/node/services/agentPlugins/installService.test.ts @@ -4815,6 +4815,14 @@ describe("AgentPluginInstallService", () => { await oauth.dispose(); }, 20_000); + test("an uninstall of a plugin with no remote servers ignores a corrupt pending record", async () => { + const preview = await service.preview({ input: remoteDir }); + await service.install({ source: preview.source, expectedSha: preview.lockedSha }); + await fsPromises.writeFile(path.join(muxRoot, "plugin-sign-outs-pending.json"), "{ not json"); + await service.uninstall({ name: "demo-plugin", deletePluginData: false }); + expect(await registry()).toEqual([]); + }, 20_000); + test("a plugin whose servers cannot be listed can still be uninstalled", async () => { const { updater, oauth } = await installSignedIn({ docs: oauthEntry(docsUrl, "client-a") }, [ docsUrl, From 788d67042370b31f6336141ccfe44ccdcd573d67 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Fri, 6 Nov 2026 02:45:37 +0000 Subject: [PATCH 14/14] tests: satisfy require-await in the early-refusal test --- src/node/services/agentPlugins/installService.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node/services/agentPlugins/installService.test.ts b/src/node/services/agentPlugins/installService.test.ts index bebd8d42d4f..0facbeb452d 100644 --- a/src/node/services/agentPlugins/installService.test.ts +++ b/src/node/services/agentPlugins/installService.test.ts @@ -4779,8 +4779,9 @@ describe("AgentPluginInstallService", () => { [docsUrl], { mcpConfigService, - onStop: async () => { + onStop: () => { if (armed) stops++; + return Promise.resolve(); }, } );