Skip to content

Commit bd767cc

Browse files
jasonczcclaude
andcommitted
fix(cli): wipe workspace contents instead of the mount point itself
Regression from the fresh-clone commit: the sync script was doing `rm -rf \$REPO_ROOT` where \$REPO_ROOT = `/workspace` inside the daemon-session container — which is the volume/bind mount point. You can `rm` the CONTENTS of a mount point, but not the directory itself; unlinking the mount fails with EACCES ("Permission denied"). Every spawn hit this, leaving spawn_failed with: rm: cannot remove '/workspace': Permission denied Fix: keep the mount point, nuke its contents. `find -mindepth 1 -maxdepth 1 -exec rm -rf {} +` reaches every direct child including dotfiles (`.git`, `.gitignore`, etc.) and doesn't touch the mount. Also runs `mkdir -p` before the wipe so first-time spawns still work when the directory doesn't exist yet. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0e318a4 commit bd767cc

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

cli/src/cloud/workspace/syncRepositoryInContainer.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,15 @@ function buildRepositorySyncScript(params: {
103103
'echo "[haqi-sync] repoRoot=$REPO_ROOT workspaceBranch=$WORKSPACE_BRANCH baseBranch=$BASE_BRANCH target=$TARGET_LABEL" >&2',
104104
// Fresh-clone contract: nuke whatever the previous session left
105105
// behind so sticky branch state never survives across opens.
106-
'if [ -d "$REPO_ROOT" ]; then',
107-
' echo "[haqi-sync] removing existing $REPO_ROOT for fresh clone" >&2',
108-
' rm -rf "$REPO_ROOT"',
109-
'fi',
106+
// NOTE: `$REPO_ROOT` in daemon-session containers is the volume
107+
// mount point (typically `/workspace`) — you can't `rm` the
108+
// directory itself, only its contents. `find -mindepth 1`
109+
// deletes everything inside while leaving the mount intact.
110110
'mkdir -p "$REPO_ROOT"',
111+
'if [ -n "$(ls -A "$REPO_ROOT" 2>/dev/null)" ]; then',
112+
' echo "[haqi-sync] wiping contents of $REPO_ROOT for fresh clone" >&2',
113+
' find "$REPO_ROOT" -mindepth 1 -maxdepth 1 -exec rm -rf {} +',
114+
'fi',
111115
`git clone ${params.repository.cloneDepth ? `--depth ${params.repository.cloneDepth} ` : ''}"$AUTH_REMOTE_URL" "$REPO_ROOT"`
112116
]
113117

0 commit comments

Comments
 (0)