paperclipai/paperclip · error
Refusing to remove instance directory "${configuredInstanceR
Error message
Refusing to remove instance directory "${configuredInstanceRoot}" because its canonical path changed during cleanup. What it means
Mid-cleanup, re-resolving canonical paths showed the instance directory's realpath (or the managed dir's) changed since cleanup started, so the deletion is refused. The guard defends against symlink/race swaps deleting the wrong directory.
Source
Thrown at server/src/services/workspace-instance-cleanup.ts:381
refusalReason: "canonical_path_outside_managed_instances_dir",
});
return { status: "refused", instanceRoot: configuredInstanceRoot, warning };
}
const dependencies = input.dependencies ?? defaultCleanupDependencies;
let postgresStopped = false;
const cleanup = async () => {
postgresStopped = await dependencies.stopEmbeddedPostgres(path.join(canonicalInstanceRoot, "db"));
const [currentManagedInstancesDir, currentInstanceRoot] = await Promise.all([
fs.realpath(managedInstancesDir),
fs.realpath(configuredInstanceRoot),
]);
if (
currentManagedInstancesDir !== canonicalManagedInstancesDir
|| currentInstanceRoot !== canonicalInstanceRoot
|| !isStrictChildPath(currentInstanceRoot, currentManagedInstancesDir)
) {
throw new Error(`Refusing to remove instance directory "${configuredInstanceRoot}" because its canonical path changed during cleanup.`);
}
await dependencies.removeInstanceRoot(currentInstanceRoot);
};
if (input.recorder) {
await input.recorder.recordOperation({
phase: "workspace_teardown",
cwd: input.workspacePath,
metadata: {
workspaceId: input.workspaceId,
workspacePath: input.workspacePath,
instanceRoot: canonicalInstanceRoot,
managedInstancesDir: canonicalManagedInstancesDir,
cleanupAction: "remove_worktree_instance",
},
run: async () => {
await cleanup();
return {View on GitHub (pinned to a7e689b3c3)
Solutions
- The instance directory's canonical path changed mid-cleanup (possible symlink race). Re-run cleanup after verifying the path is stable and not a symlink attack.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at server/src/services/workspace-instance-cleanup.ts:356 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of paperclipai/paperclip@a7e689b3c3 (2026-08-18).
Data as JSON: /api/errors/fcb5400d1dc3d4c5.
Report an issue: GitHub.