daemon: the shared-checkout guard is racy between the lock and the create #71

Closed
opened 2026-08-24 00:41:38 +01:00 by naps62-yolo · 1 comment
Collaborator

crates/maestro-daemon/src/session.rs — the "two sessions must not share a checkout" check is racy.

create takes the sessions lock, tests whether any live record already owns the planned worktree path, then releases the lock before calling add_new/add_existing.

Two concurrent POST /api/sessions for the same base repo and branch both pass the test. The first creates the worktree; the second reaches run_add, finds the path present and registered for that branch, and adopts it. Two live sessions then run in one checkout — exactly what the check was added to prevent.

Hold the lock across the create, or reserve the planned path in the map before releasing it.

`crates/maestro-daemon/src/session.rs` — **the "two sessions must not share a checkout" check is racy.** `create` takes the sessions lock, tests whether any live record already owns the planned worktree path, then releases the lock before calling `add_new`/`add_existing`. Two concurrent `POST /api/sessions` for the same base repo and branch both pass the test. The first creates the worktree; the second reaches `run_add`, finds the path present and registered for that branch, and adopts it. Two live sessions then run in one checkout — exactly what the check was added to prevent. Hold the lock across the create, or reserve the planned path in the map before releasing it.
naps62-yolo added this to the Spawn v2 milestone 2026-08-24 00:41:38 +01:00
naps62-yolo added the area/daemondifficulty/mediumtype/fix labels 2026-08-24 00:41:38 +01:00
Author
Collaborator

Superseded by the Worktree lifecycle milestone, specifically #77.

This dissolves rather than gets fixed: once nothing is ever adopted and a path collision is sidestepped with a numeric suffix, there is no adoption path that could take over a hand-made worktree, and no single directory for two concurrent creates to contend over.

Superseded by the **Worktree lifecycle** milestone, specifically #77. This dissolves rather than gets fixed: once nothing is ever adopted and a path collision is sidestepped with a numeric suffix, there is no adoption path that could take over a hand-made worktree, and no single directory for two concurrent creates to contend over.
This repo is archived. You cannot comment on issues.
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: naps62/maestro#71