Repository navigation
Description
Summary
convergeWorkspace (harness/src/converge.ts) has two related defects that make a pooled sandbox unable to serve more than one repo, and make concurrent converges on a fresh workspace flaky. Surfaced while wiring the BugStone Archetype-A PoC (which dispatches leaves with a per-run repoUrl) against the shared pool that also serves the experiments' repo.git.
The code
buildConvergeScript(repoUrl, ref, runId) emits (paraphrased):
REPO=/workspace/repo; LOCK=/workspace/.sh-fetch.lock
[ -d "$REPO/.git" ] || git clone --quiet <repoUrl> "$REPO" # (A) clone: NOT under flock; only if .git absent
( flock 9; git -C "$REPO" fetch --quiet origin <ref> ) 9>"$LOCK" # (B) fetch: from `origin`, not <repoUrl>
COMMIT=$(git -C "$REPO" rev-parse FETCH_HEAD)
[ -d "$LEAF" ] || git -C "$REPO" worktree add --detach "$LEAF" "$COMMIT"
Defect 1 — /workspace/repo is bound to the FIRST repoUrl (origin), per-leaf repoUrl ignored on reuse
origin is set by the first git clone (A). Once .git exists, (A) is skipped forever and (B) always fetches from that original origin, ignoring the repoUrl in the current leaf's envelope. So a sandbox that first cloned repo X can never converge repo Y: git fetch origin <ref> runs against X, and if X lacks <ref> it fails with exit 128 (runLeaf → {status:"failed", reason:"error", message:"converge failed (exit 128)"}).
Repro: on a pool where /workspace/repo was cloned from git://gitd…/repo.git (branches branch-0..15, work — no main), dispatch a leaf with repoUrl=git://gitd…/other.git + ref=main:
[exec] git -C /workspace/repo fetch --quiet origin main
fatal: couldn't find remote ref main → exit 128
The leaf's repoUrl was other.git, but converge fetched repo.git's origin.
Defect 2 — the initial clone is not locked (clone race) and not self-healing
(A) is outside the flock. Under async/KEDA concurrency, N leaf-workers pinned to the same sandbox all see no .git on a freshly-reset /workspace/repo and race git clone into the same directory → collisions → several workers exit non-zero (observed: multiple leaf-worker pods Error/BackoffLimitExceeded; KEDA retries and it self-heals only once one clone wins). A clone interrupted mid-flight can also leave a non-git /workspace/repo that then wedges every retry (this is the #59 non-self-healing failure mode).
Impact
Any multi-repo or multi-tenant use of the shared sandbox pool. Two consumers that converge different repos (e.g. the P3/E6 experiments' repo.git and BugStone's per-run target) cannot coexist on the same pool pod, and can't run concurrently against different repos. Today each consumer must pre-reset /workspace on every pool pod and run one-workload-at-a-time (the BugStone PoC does exactly this as a workaround — resets /workspace/{repo,leaves,.sh-fetch.lock} on all pool sandboxes before each run).
Suggested fix
Fetch from the explicit repoUrl (not origin), and do the whole init+fetch under the flock with self-heal, e.g.:
( flock 9
[ -d "$REPO/.git" ] || { rm -rf "$REPO"; git init -q "$REPO"; }
git -C "$REPO" fetch --quiet <repoUrl> <ref>
) 9>"$LOCK"
COMMIT=$(git -C "$REPO" rev-parse FETCH_HEAD)
- fetch-by-URL makes converge honor the per-leaf
repoUrl→ one sandbox can serve many repos (shared object store, cached across leaves); - init+fetch under the lock removes the clone race and the "clone into non-empty dir" failure;
rm -rf + git initwhen.gitis missing/invalid makes it self-healing (closes the #59 partial-/workspace/repowedge too).
If keeping a single shared origin is desired for caching, an alternative is git remote set-url origin <repoUrl> before each fetch — but fetch-by-URL is simpler and inherently multi-repo.
Notes
- Verified against current
mainon Kind (kind-sh-knative) and OpenShift 4.20; both reproduce. - Related: converge.ts not self-healing against a partial/non-git /workspace/repo #59 (converge not self-healing vs a non-git
/workspace/repo). This issue generalizes it: even a valid/workspace/repoof the wrong repo breaks converge, because the per-leafrepoUrlis ignored.
Assisted-By: Claude Code
Activity
fix: Converge fetches per-leaf repoUrl and self-heals (#67)
Merge pull request #68 from kagenti/fix/converge-multirepo-67