Deleting a session while its workspace is stopped orphans the worktree and branch #201

Open
opened 2026-09-24 00:39:12 +02:00 by lz · 0 comments
Owner

deleteSession (nexus/src/lib/server/sessions/service.ts) runs its git cleanup only when the container is running:

const info = await findContainerByWorkerId(docker, row.worker_id);
if (info && info.State === 'running') {
  // kill-window, worktree remove --force, branch -D
}
await db.deleteFrom('sessions').where('id', '=', sessionId).execute();

On a stopped workspace the row is hard-deleted and the worktree at /workspace/.nexus/worktrees/<name> and its branch both stay on the volume, with nothing pointing at them:

  • convergeSessions sees the worktree once the workspace starts again, logs a warning, and never imports it (fact #15), so it doesn't show up anywhere in the UI.
  • Creating a new session with the same name hits createSession's recovery path when git worktree add -b fails. That path runs worktree remove --force, branch -D and rm -rf on the orphan, so any commits left on it are deleted silently. Nobody confirmed that, and nothing reports it.

Options

  • Refuse the delete while the workspace is stopped. This is what nexus_delete_session does without force (#156, spec docs/superpowers/specs/2026-09-23-mcp-session-tools-design.md), and the UI could do the same with a "start the workspace first" message.
  • Or defer the cleanup: record the orphan and reap it on the next start, which convergence already has a hook for.

The same-name recovery path deserves a look either way: a create should not be able to destroy commits on a branch it did not make.

Found while designing #156.

`deleteSession` (`nexus/src/lib/server/sessions/service.ts`) runs its git cleanup only when the container is running: ```ts const info = await findContainerByWorkerId(docker, row.worker_id); if (info && info.State === 'running') { // kill-window, worktree remove --force, branch -D } await db.deleteFrom('sessions').where('id', '=', sessionId).execute(); ``` On a stopped workspace the row is hard-deleted and the worktree at `/workspace/.nexus/worktrees/<name>` and its branch both stay on the volume, with nothing pointing at them: - `convergeSessions` sees the worktree once the workspace starts again, logs a warning, and never imports it (fact #15), so it doesn't show up anywhere in the UI. - Creating a new session with the **same name** hits `createSession`'s recovery path when `git worktree add -b` fails. That path runs `worktree remove --force`, `branch -D` and `rm -rf` on the orphan, so any commits left on it are deleted silently. Nobody confirmed that, and nothing reports it. ## Options - Refuse the delete while the workspace is stopped. This is what `nexus_delete_session` does without `force` (#156, spec `docs/superpowers/specs/2026-09-23-mcp-session-tools-design.md`), and the UI could do the same with a "start the workspace first" message. - Or defer the cleanup: record the orphan and reap it on the next start, which convergence already has a hook for. The same-name recovery path deserves a look either way: a create should not be able to destroy commits on a branch it did not make. Found while designing #156.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lz/agent-nexus#201
No description provided.