Runs: a hub folder no longer blocks runs in the separate repositories inside it

Retrying the Daily brief (workspace ~/caplens) was refused while a change
run worked in ~/caplens/repos/fix-d, with a message that read as if the
retry reused the next run number. Nested workspaces now overlap only
within one repository, and the refusal names the blocking run's own
workspace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 09:36:54 +00:00
parent b023720617
commit 4d86fe5a7f
2 changed files with 56 additions and 2 deletions
+31 -2
View File
@@ -473,7 +473,7 @@ func (r *runner) checkWorkspaceFree(workspace string) error {
func (r *runner) checkWorkspaceFreeExcept(workspace string, ownGate int64) error {
for id, entry := range r.active {
if workspacesOverlap(entry.workspace, workspace) {
return fmt.Errorf("run %d is already active in workspace %s; wait for it to finish or start this run in a different workspace (for example another checkout of the repository)", id, workspace)
return fmt.Errorf("run %d is already active in %s, which overlaps this run's workspace %s; wait for run %d to finish or use a different workspace (for example another checkout of the repository)", id, entry.workspace, workspace, id)
}
}
check, cancel := context.WithTimeout(context.WithoutCancel(r.ctx), 5*time.Second)
@@ -490,12 +490,41 @@ func (r *runner) checkWorkspaceFreeExcept(workspace string, ownGate int64) error
return nil
}
// workspacesOverlap reports whether two resolved workspaces are the same
// tree or nested in one another within the same repository. A folder that
// merely holds separate repositories (a hub such as ~/project with clones
// under repos/) does not overlap a run inside one of those repositories, and
// neither do two different repositories nested in one another: each run
// works in its own repository.
func workspacesOverlap(a, b string) bool {
within := func(parent, child string) bool {
rel, err := filepath.Rel(parent, child)
return err == nil && rel != ".." && !strings.HasPrefix(rel, ".."+string(os.PathSeparator))
}
return within(a, b) || within(b, a)
switch {
case filepath.Clean(a) == filepath.Clean(b):
return true
case within(a, b):
return repositoryRoot(b) == repositoryRoot(a)
case within(b, a):
return repositoryRoot(a) == repositoryRoot(b)
}
return false
}
// repositoryRoot is the nearest directory at or above dir holding a .git
// entry (a repository or a linked worktree), or "" outside any repository.
func repositoryRoot(dir string) string {
for current := filepath.Clean(dir); ; {
if _, err := os.Lstat(filepath.Join(current, ".git")); err == nil {
return current
}
parent := filepath.Dir(current)
if parent == current {
return ""
}
current = parent
}
}
func (r *runner) getRun(id int64) (*protocol.RunDetail, error) {