can1357/oh-my-pi · error · Error
Session file deleted but failed to remove artifacts director
Error message
Session file deleted but failed to remove artifacts directory ${artifactsDir}: ${error.message} What it means
deleteSessionWithArtifacts removes the session file and then its associated artifacts directory. Missing artifact directories are tolerated, but if the recursive rm of an existing artifacts dir fails, this Error is thrown: the session JSONL is already deleted, so only the artifact cleanup failure is reported, with the underlying error as cause.
Source
Thrown at packages/coding-agent/src/session/session-storage.ts:462
/**
* Delete a session file and its artifacts directory.
* Artifacts are stored in a sibling directory with the same name minus .jsonl extension.
*/
async deleteSessionWithArtifacts(sessionPath: string): Promise<void> {
// Delete the session file itself
await this.unlink(sessionPath);
// Compute artifacts directory: /path/to/session.jsonl -> /path/to/session
const artifactsDir = sessionPath.slice(0, -6);
// Delete artifacts directory if it exists. Missing directories are fine, but
// surface real cleanup failures because the session file is already gone.
try {
await fsp.rm(artifactsDir, { recursive: true, force: true });
} catch (err) {
const error = toError(err);
throw new Error(
`Session file deleted but failed to remove artifacts directory ${artifactsDir}: ${error.message}`,
{
cause: error,
},
);
}
}
}
function matchesPattern(name: string, pattern: string): boolean {
if (pattern === "*") return true;
if (pattern.startsWith("*.")) {
return name.endsWith(pattern.slice(1));
}
return name === pattern;
}
class MemorySessionStorageWriter implements SessionStorageWriter {View on GitHub (pinned to 9690622007)
Solutions
- Re-run the delete after closing programs that may hold files in the artifacts directory (editors, terminals cd'd into it, sync clients).
- Manually remove the artifacts directory shown in the message: rm -rf <artifactsDir>, then confirm nothing references it.
- Fix ownership/permissions on the artifacts directory (chown/chmod) before deleting.
- Note the session file itself was already deleted — this error does not mean the delete failed; only cleanup is pending.
Example fix
// manual cleanup after the error rm -rf "~/.omp/artifacts/<session-name>" # path from the error message
Defensive patterns
Strategy: try-catch
Validate before calling
import { access, constants } from "node:fs/promises";
try {
await access(artifactsDir, constants.W_OK);
} catch {
// not writable or missing — either fine (missing is tolerated) or cleanup will fail
} Try / catch
try {
await deleteSessionWithArtifacts(file);
} catch (err) {
if (err.message.includes("failed to remove artifacts directory")) {
logger.warn("Session deleted; artifacts left behind", { cause: err.cause, artifactsDir });
// schedule retry/manual rm -rf of artifactsDir
} else throw err;
} Prevention
- Ensure the process user owns or can delete the artifacts directory.
- Close editors/sync clients that hold files under the artifacts dir before deleting.
- Don't run some sessions with elevated privileges (creates root-owned artifacts others can't delete).
- Remember the session file is already gone — treat this as cleanup warning, not delete failure.
When it happens
Trigger: fsp.rm(artifactsDir, { recursive: true, force: true }) fails with EACCES/EPERM (permission-restricted directory), EBUSY/EPERM (a file inside is open or locked, e.g. by AV or a sync client), or read-only filesystem.
Common situations: Deleting a session on Windows while Defender or an editor holds an artifact file; artifacts dir owned by another user after running with elevated privileges; NFS/network mounts with stale locks.
Related errors
- {}: {error}
- inter-device move failed: {} to {}; unable to remove target:
- Permission denied
- cannot stat {file}: {error}
- failed to read filter definition {}: {e}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/69b857bd6d469add.
Report an issue: GitHub.