fix: remove self-referential .mcpb-cache symlinks before bwrap mount (#342)

Upstream fs-extra can replace .mcpb-cache directories with
self-referential symlinks after repeated Cowork sessions, causing
ELOOP errors on subsequent launches.

Detect and remove these before the bind-mount setup in BwrapBackend
spawn, then let the existing mkdirSync recreate as a proper directory.

Fixes #342

Co-Authored-By: Claude <claude@anthropic.com>
This commit is contained in:
aaddrick
2026-03-25 06:45:19 -04:00
parent 9afacd57e2
commit 8e9a03b6e2

View File

@@ -848,6 +848,22 @@ class BwrapBackend extends LocalBackend {
for (const [mountName, hostPath] of Object.entries(mountMap)) {
try {
// Fix #342: upstream fs-extra can create .mcpb-cache
// as a self-referential symlink after repeated sessions.
// Detect and remove before mkdir so the bind mount works.
try {
const st = fs.lstatSync(hostPath);
if (st.isSymbolicLink()) {
const target = fs.readlinkSync(hostPath);
const resolved = path.resolve(
path.dirname(hostPath), target
);
if (resolved === hostPath) {
log(`BwrapBackend spawn: removing self-referential symlink: ${hostPath}`);
fs.unlinkSync(hostPath);
}
}
} catch { /* ENOENT is fine — path doesn't exist yet */ }
if (!fs.existsSync(hostPath)) {
fs.mkdirSync(hostPath, { recursive: true });
}