JuliusBrussee/caveman · error · Error
changed during MCP update; refusing removal
Error message
${path} changed during MCP update; refusing removal What it means
Thrown when the CLI is removing an MCP config entry and re-reads the file immediately before unlinking, finding its bytes no longer match the expected snapshot. This second check guarantees the file was not modified between the initial comparison and its deletion.
Solutions
- Re-run the removal command when nothing else is watching/writing the config
- Stop file watchers or generators (e.g. config sync daemons) that rewrite the file on change
- Check whether another caveman instance is running and wait for it to finish
- Retry the removal; verify the entry state afterwards
Example fix
// before config-watcher --watch ~/.codex & caveman mcp remove ... // after pkill config-watcher && caveman mcp remove ...
Defensive patterns
Strategy: retry
Validate before calling
// confirm the entry to remove still matches expectations before removal const bytes = fs.existsSync(configPath) ? fs.readFileSync(configPath) : null; // compare bytes to your snapshot before calling the removal
Type guard
null
Try / catch
try {
runMcpRemove();
} catch (e) {
if (String(e.message).includes("refusing removal")) {
console.error("File changed mid-removal; nothing was deleted. Retry when the file is stable.");
}
} Prevention
- Stop config-watching daemons before removing entries
- Run removals sequentially, not concurrently with other CLI instances
- Verify expected file content matches your snapshot before deleting
When it happens
Trigger: durableReplaceFileIfUnchanged called with next===null; after the first equality check passes, fileBytes(path) (atDelete) differs from `expected` right before unlinkSync.
Common situations: Another process rewrote or recreated the config file in the microseconds between checks — e.g. a watcher that regenerates config files on change, or concurrent CLI runs.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- changed during MCP update; refusing overwrite
- MCP transaction state kept changing; refusing mutation
- changed while planning MCP update; refusing overwrite
- changed while planning MCP update; refusing overwrite
- MCP config change already running for
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/fd1f5f12140ed824.
Report an issue: GitHub.
Appendix: source
Thrown at packages/cli/src/index.ts:6937
durableAtomicWriteFile(temp, bytes, mode);
linkSync(temp, path);
fsyncParentDirectory(path);
} finally {
try { unlinkSync(temp); } catch { /* published or failed before temp creation */ }
}
}
function optionalBytesEqual(left: Buffer | null, right: Buffer | null): boolean {
return left === null ? right === null : right !== null && left.equals(right);
}
function durableReplaceFileIfUnchanged(path: string, expected: Buffer | null, next: Buffer | null, mode = 0o600): void {
const current = fileBytes(path);
if (!optionalBytesEqual(current, expected)) throw new Error(`${path} changed during MCP update; refusing overwrite`);
if (next === null) {
if (current !== null) {
const atDelete = fileBytes(path);
if (!optionalBytesEqual(atDelete, expected)) throw new Error(`${path} changed during MCP update; refusing removal`);
unlinkSync(path);
fsyncParentDirectory(path);
}
return;
}
// Prepare durable replacement first, then run final compare immediately
// before rename. Per-agent lock serializes Caveman writers; this CAS catches
// external edits observed before commit without erasing them.
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
const temp = join(dirname(path), `.${basename(path)}.caveman-cas-${process.pid}-${randomUUID()}.tmp`);
let fd: number | undefined;
try {
fd = openSync(temp, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY, mode);
writeFileSync(fd, next);
fchmodSync(fd, mode);
fsyncSync(fd);
closeSync(fd);View on GitHub (pinned to 3ee70a1026)