Skip to content

Commit 329d5e7

Browse files
committed
fix(state): tolerate vanished sqlite sidecars in agent-db permission sweep
existsSync+chmodSync raced SQLite's own WAL/SHM cleanup: a checkpoint or close between the two calls throws ENOENT (observed from the transcript reconcile worker in server-startup-web-fetch-bind on CI). chmod directly and swallow only ENOENT, which removes the TOCTOU window.
1 parent b26d338 commit 329d5e7

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/state/openclaw-agent-db.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,16 @@ export function ensureOpenClawAgentDatabasePermissions(
577577
chmodSync(dir, OPENCLAW_AGENT_DB_DIR_MODE);
578578
}
579579
for (const candidate of resolveSqliteDatabaseFilePaths(pathname)) {
580-
if (existsSync(candidate)) {
580+
try {
581581
chmodSync(candidate, OPENCLAW_AGENT_DB_FILE_MODE);
582+
} catch (error) {
583+
// WAL/SHM/journal sidecars are transient: SQLite removes them at
584+
// checkpoint/close, so a concurrent worker can race this sweep. A
585+
// vanished sidecar needs no tightening; an existsSync guard would just
586+
// reintroduce the TOCTOU window.
587+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
588+
throw error;
589+
}
582590
}
583591
}
584592
}

0 commit comments

Comments
 (0)