Skip to content

Commit fd975c7

Browse files
fix(setup): stop remaining uninstall removals after a client fails
A configuration that passes the preflight can still fail when uninstall rereads it to edit, for example when it changes concurrently. Rereading keeps that edit from overwriting the newer file; stopping at the failure keeps later clients, the skill, and REA data from being removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5cc841d commit fd975c7

3 files changed

Lines changed: 80 additions & 3 deletions

File tree

‎docs/installation.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ rea uninstall --purge-data
574574
Uninstall preserves Hopper, Node.js, Evidence files, captures, unrelated skills
575575
and other MCP servers. Purging removes only REA's cache and state under
576576
`~/.rea`. A client configuration that is malformed, unreadable, or at an unsafe
577-
path stops the operation before anything is removed; a purge path that is a
577+
path stops the operation before anything is removed, and a client that fails
578+
while being updated stops the remaining removals. A purge path that is a
578579
symbolic link is retained and reported rather than followed. See the
579580
[CLI guide](cli.md#output-and-exit-status) for exit statuses.
580581

‎src/application/Uninstall.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export interface UninstallHost {
9191
/**
9292
* Remove only REA-owned registrations and managed files, optionally including
9393
* local state. A client configuration that cannot be read safely stops the
94-
* operation before anything is removed.
94+
* operation before anything is removed; one that fails during removal stops
95+
* the remaining removals.
9596
*/
9697
export const runUninstall = async (
9798
purgeData: boolean,
@@ -127,13 +128,29 @@ export const runUninstall = async (
127128
};
128129
};
129130

131+
/**
132+
* Each client is reread when it is edited, so a concurrent change is never
133+
* overwritten. A client that fails then still stops the remaining removals.
134+
*/
130135
const removeAll = async (
131136
clients: readonly SetupClient[],
132137
purgeData: boolean,
133138
host: UninstallHost,
134139
): Promise<UninstallItem[]> => {
135140
const items: UninstallItem[] = [];
136-
for (const client of clients) items.push(await host.removeClient(client));
141+
for (const client of clients) {
142+
const removed = await host.removeClient(client);
143+
items.push(removed);
144+
if (removed.status === "failed")
145+
return [
146+
...items,
147+
item(
148+
"uninstall",
149+
"skipped",
150+
"Uninstall stopped at this failure; the items above report what changed. Repair the failed configuration, then rerun uninstall.",
151+
),
152+
];
153+
}
137154
items.push(await host.removeSkill());
138155
if (purgeData) items.push(...(await host.purgeData()));
139156
return items;

‎tests/boundary/filesystem/clientLifecycle.test.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,65 @@ describe("client configuration filesystem removal", () => {
14671467
});
14681468
});
14691469

1470+
describe("client configuration changed during uninstall", () => {
1471+
it("stops the remaining removals when a configuration fails after preflight", async () => {
1472+
const home = await createTestTempDirectory("rea-uninstall-race-");
1473+
roots.push(home);
1474+
const codex = join(home, ".codex/config.toml");
1475+
const cursor = join(home, ".cursor/mcp.json");
1476+
const skill = join(
1477+
home,
1478+
".agents/skills/reverse-engineer-anything/SKILL.md",
1479+
);
1480+
const cursorConfig = JSON.stringify({
1481+
mcpServers: { rea: { command: "rea", args: ["mcp"] } },
1482+
});
1483+
for (const path of [codex, cursor, skill])
1484+
await mkdir(dirname(path), { recursive: true });
1485+
await writeFile(
1486+
codex,
1487+
'[mcp_servers.rea]\ncommand = "rea"\nargs = ["mcp"]\n',
1488+
);
1489+
await writeFile(cursor, cursorConfig);
1490+
await writeFile(skill, "managed");
1491+
let codexReads = 0;
1492+
const fileSystem: UninstallFileSystem = {
1493+
...testFileSystem,
1494+
// The preflight read succeeds; the removal reread finds a broken file.
1495+
readText: (path) => {
1496+
if (path !== codex) return readFile(path, "utf8");
1497+
codexReads += 1;
1498+
return codexReads === 1
1499+
? readFile(path, "utf8")
1500+
: Promise.resolve("[mcp_servers.rea]\ncommand = [broken\n");
1501+
},
1502+
};
1503+
1504+
const result = await runUninstall(
1505+
false,
1506+
systemUninstallHost(home, fileSystem),
1507+
);
1508+
1509+
expect(result.status).toBe("failed");
1510+
// Clients ordered before Codex have no configuration in this home.
1511+
expect(
1512+
result.items
1513+
.filter(({ status }) => status !== "skipped")
1514+
.map(({ name, status }) => [name, status]),
1515+
).toEqual([
1516+
["codex", "failed"],
1517+
["analysis_engine", "retained"],
1518+
]);
1519+
expect(result.items.map(({ name }) => name)).not.toContain("cursor");
1520+
expect(result.items.at(-2)).toMatchObject({
1521+
name: "uninstall",
1522+
status: "skipped",
1523+
});
1524+
expect(await readFile(cursor, "utf8")).toBe(cursorConfig);
1525+
expect(await readFile(skill, "utf8")).toBe("managed");
1526+
});
1527+
});
1528+
14701529
describe("client configuration filesystem failure reporting", () => {
14711530
it.each([
14721531
[

0 commit comments

Comments
 (0)