Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(session): handle transient ENOENT in session directory creation

yushen3039e3b34ca7
diff --git a/src/agent/session/session-manager.ts b/src/agent/session/session-manager.ts
index a820072a8a..ec1c7cd66a 100644
--- a/src/agent/session/session-manager.ts
+++ b/src/agent/session/session-manager.ts
@@ -273,7 +273,10 @@ export class SessionManager {
}
private enqueue(task: () => Promise<void>) {
- this.queue = this.queue.then(task, task);
+ this.queue = this.queue.then(task, task).catch(() => {
+ // Swallow storage errors to prevent unhandled rejections.
+ // The queue must remain settled so subsequent writes can proceed.
+ });
return this.queue;
}
}
diff --git a/src/agent/session/session-write-lock.ts b/src/agent/session/session-write-lock.ts
index c6364e3219..307b99cd56 100644
--- a/src/agent/session/session-write-lock.ts
+++ b/src/agent/session/session-write-lock.ts
@@ -130,7 +130,19 @@ export async function acquireSessionWriteLock(params: {
const staleMs = params.staleMs ?? 30 * 60 * 1000;
const sessionFile = path.resolve(params.sessionFile);
const sessionDir = path.dirname(sessionFile);
- await fs.mkdir(sessionDir, { recursive: true });
+ // Retry mkdir to handle transient ENOENT on macOS APFS race conditions
+ for (let attempt = 0; ; attempt++) {
+ try {
+ await fs.mkdir(sessionDir, { recursive: true });
+ break;
+ } catch (err) {
+ if ((err as NodeJS.ErrnoException).code === "ENOENT" && attempt < 2) {
+ await new Promise((r) => setTimeout(r, 50));
+ continue;
+ }
+ throw err;
+ }
+ }
let normalizedDir = sessionDir;
try {
normalizedDir = await fs.realpath(sessionDir);
diff --git a/src/agent/session/storage.ts b/src/agent/session/storage.ts
index 6391578374..b578f3ab32 100644
--- a/src/agent/session/storage.ts
+++ b/src/agent/session/storage.ts
@@ -24,7 +24,16 @@ export function resolveSessionPath(sessionId: string, options?: SessionStorageOp
export function ensureSessionDir(sessionId: string, options?: SessionStorageOptions) {
const dir = resolveSessionDir(sessionId, options);
if (!existsSync(dir)) {
- mkdirSync(dir, { recursive: true });
+ try {
+ mkdirSync(dir, { recursive: true });
+ } catch (err) {
+ // Retry once on transient ENOENT (macOS APFS race condition)
+ if ((err as NodeJS.ErrnoException).code === "ENOENT") {
+ mkdirSync(dir, { recursive: true });
+ } else {
+ throw err;
+ }
+ }
}
}