fix: only remove session tmp dir when last pointer file is cleared (#1593)

Explicitly check that the directory is empty before removing it rather
than relying on rmdirSync throwing ENOTEMPTY when siblings remain.
On Windows that error is not raised reliably, causing the session tmp
directory to be deleted prematurely when sibling pointer files exist.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-04-03 11:49:37 -04:00
parent c4b5cd64f5
commit 693e05a603

View File

@@ -714,8 +714,15 @@ function clearActiveWorkstreamPointer(filePath, cleanupDirPath) {
// Session-scoped pointers for a repo share one tmp directory. Only remove it
// when it is empty so clearing or self-healing one session never deletes siblings.
// Explicitly check remaining entries rather than relying on rmdirSync throwing
// ENOTEMPTY — that error is not raised reliably on Windows.
if (cleanupDirPath) {
try { fs.rmdirSync(cleanupDirPath); } catch {}
try {
const remaining = fs.readdirSync(cleanupDirPath);
if (remaining.length === 0) {
fs.rmdirSync(cleanupDirPath);
}
} catch {}
}
}