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
+25
View File
@@ -151,3 +151,28 @@ func TestWorkspaceOverlapIncludesParentsDescendantsAndSymlinks(t *testing.T) {
}
}
}
// A hub folder holding separate repositories (the operator's ~/caplens with
// clones under repos/) must not block, nor be blocked by, a run inside one of
// those repositories; the same repository still overlaps itself.
func TestWorkspaceOverlapSeparatesNestedRepositories(t *testing.T) {
hub := t.TempDir()
repo := filepath.Join(hub, "repos", "fix-d")
inner := filepath.Join(repo, "src")
nested := filepath.Join(repo, "vendor", "lib")
for _, dir := range []string{filepath.Join(repo, ".git"), inner, filepath.Join(nested, ".git")} {
if err := os.MkdirAll(dir, 0700); err != nil {
t.Fatal(err)
}
}
for _, pair := range [][2]string{{hub, repo}, {repo, hub}, {hub, inner}, {repo, nested}} {
if workspacesOverlap(pair[0], pair[1]) {
t.Fatal("separate repositories falsely overlap", pair)
}
}
for _, pair := range [][2]string{{repo, repo}, {repo, inner}, {inner, repo}} {
if !workspacesOverlap(pair[0], pair[1]) {
t.Fatal("one repository does not overlap itself", pair)
}
}
}
+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) {