Skip to content

fix: Converge fetches per-leaf repoUrl and self-heals (#67) - #68

Merged
pdettori merged 1 commit into
mainfrom
fix/converge-multirepo-67
Jul 6, 2026
Merged

pdettori merged 1 commit into
mainfrom
fix/converge-multirepo-67

Conversation

@pdettori

@pdettori pdettori commented Jul 5, 2026

Copy link
Copy Markdown
Member

Summary

Fixes the two convergeWorkspace defects in #67 that stop a pooled sandbox from serving more than one repo and race the initial clone.

buildConvergeScript used to git clone once and then always git fetch origin <ref>. origin was pinned to the first repoUrl, so the per-leaf repoUrl was ignored on reuse — a sandbox that first served repo X could never converge repo Y (fetch origin <ref> ran against X → exit 128 couldn't find remote ref). The clone also sat outside the flock, so concurrent leaves on a fresh workspace raced it, and a partial /workspace/repo never self-healed (#59).

Change

harness/src/converge.ts — buildConvergeScript now:

  • fetches by explicit URL: git init + git -C "$REPO" fetch <repoUrl> <ref> instead of git clone + fetch origin. One shared object store at /workspace/repo now serves many repos.
  • does init+fetch entirely under the flock — no clone race.
  • self-heals: rm -rf "$REPO"; git init when .git is absent, and a retry (fetch || { reinit; fetch; }) when a fetch fails against a corrupt .git.
flowchart TD
  A["converge(repoUrl, ref)"] --> B["( flock 9"]
  B --> C{".git present?"}
  C -->|no| D["rm -rf REPO; git init"]
  C -->|yes| E["git fetch repoUrl ref"]
  D --> E
  E -->|ok| G[") close lock"]
  E -->|fail| F["rm -rf REPO; git init; fetch"]
  F --> G
  G --> H["worktree add --detach LEAF FETCH_HEAD"]
Loading

Worktree add, printf output, and single-quote injection escaping are unchanged; buildConvergeScript's signature and all callers are unchanged.

Testing

  • Unit (harness/test/converge.test.ts): updated the buildConvergeScript contract — fetch targets the explicit repoUrl+ref (never origin, no git clone), init+fetch inside the flock, self-heal + fetch-retry, plus the existing worktree/printf/injection assertions. 9/9 green.
  • Behavioral (real git, local): ran the generated converge script against two local bare repos:
  • Full workspace suite + typecheck run in CI (pi-fork built there).

Closes #67. Also closes the non-self-healing wedge in #59.

Assisted-By: Claude Code

buildConvergeScript bound /workspace/repo to the first repoUrl: it cloned
once, then always ran `git fetch origin <ref>`, ignoring the per-leaf
repoUrl on reuse. A pooled sandbox that first served repo X could never
converge repo Y (fetch ran against X's origin -> exit 128 "couldn't find
remote ref"), the initial clone raced under concurrency, and a partial
/workspace/repo did not self-heal.

Fetch by explicit URL (git init + git fetch <repoUrl> <ref>) with the whole
init+fetch under the flock, and self-heal via rm -rf + git init when .git is
absent or a fetch fails. One pooled sandbox now serves many repos from a
shared object store, concurrent converges no longer race the clone, and a
missing or corrupt /workspace/repo recovers automatically.

Verified with the generated script against two local repos: X@work then
Y@main on the same workspace both succeed with correct content, while the
old script fails the second with exit 128; non-git and corrupt-.git repos
self-heal.

Closes #67. Also closes the non-self-healing wedge in #59.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori force-pushed the fix/converge-multirepo-67 branch from 7b4a27e to 4e4e977 Compare July 5, 2026 20:05
@pdettori
pdettori merged commit 923708e into main Jul 6, 2026
9 checks passed
@pdettori
pdettori deleted the fix/converge-multirepo-67 branch July 6, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

converge binds /workspace/repo to the first repoUrl (fetches origin) and races the initial clone — breaks multi-repo shared-pool use

1 participant