feat(miner-hands): git-worktree-per-attempt isolation primitive - #4547
Conversation
Add packages/gittensory-engine/src/miner/worktree-allocator.ts: the concurrency primitive for parallel coding-agent attempts. Each attempt runs in its own `git worktree` so concurrent attempts (same or different issues) never collide on a shared working directory. The module splits into a PURE planning layer and thin injected-exec wrappers, mirroring the SpawnFn injection convention (JSONbored#4262/JSONbored#4266) so all naming/collision/lifecycle logic is unit-testable without shelling out to git in CI: - planWorktree(): deterministic worktree path + branch, keyed on the attempt id (never a random suffix). Two concurrent attempts with distinct ids get distinct paths/branches; the same id always maps to the same location, so a crashed attempt's worktree stays identifiable and cleanable after the fact. Slugs are sanitized to a filesystem- and git-ref-safe token and length-capped. - addWorktree(): `git worktree add -b <branch> <path> <base>` through the injected exec; returns the plan plus git's stderr on failure. - removeWorktree() + shouldRetainWorktree(): retention policy — a SUCCEEDED attempt's worktree is removed once it concludes; a FAILED attempt's is RETAINED for post-mortem (its deterministic name makes it findable). The exec is injected (a real child_process spawn in prod, a fake in tests), so the driver seam (JSONbored#4262) can accept the planned path as its scoped working directory without retrofitting. Covered by test/unit/worktree-allocator.test.ts (pure naming/collision logic and both exec wrappers via a fake exec; 100% line + branch). Closes JSONbored#4269
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4547 +/- ##
=======================================
Coverage 94.06% 94.07%
=======================================
Files 425 426 +1
Lines 37774 37793 +19
Branches 13794 13800 +6
=======================================
+ Hits 35533 35552 +19
Misses 1586 1586
Partials 655 655
🚀 New features to boost your workflow:
|
|
Tip 🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 ✅ Gittensory review result - approve/merge recommendedReview updated: 2026-07-10 01:08:30 UTC
✅ Suggested Action - Approve/Merge
Review summary Nits — 5 non-blocking
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
What & why
Closes #4269.
The roadmap's stated concurrency primitive for parallel attempts: each coding-agent attempt runs in its own
git worktreeso multiple attempts (same or different issues) never collide on a shared working directory. This is greenfield —grep -rln "worktree" scripts/ .github/has zero hits, so there was no existing pattern in the repo's own tooling to mirror.New file
packages/gittensory-engine/src/miner/worktree-allocator.ts(path coordinated with #4262'ssrc/miner/home), split into a pure planning layer and thin injected-exec wrappers — mirroring theSpawnFninjection convention from #4262/#4266 — so all naming/collision/lifecycle logic is unit-testable without shelling out togitin CI.Deliverables
planWorktree({ repoPath, attemptId })computes the deterministic worktree path (<repo>/.gittensory-worktrees/<slug>) and branch (gittensory/attempt/<slug>). Pure, no IO.addWorktree()runsgit worktree add -b <branch> <path> <base>andremoveWorktree()runsgit worktree remove --force <path>, both through an injectedWorktreeExecFn(a realchild_processspawn in prod, a fake in tests). Failures surface git's stderr with a stablegit_worktree_*_exit_<code>fallback.shouldRetainWorktree(attemptOk)encodes it: a succeeded attempt's worktree is removed once it concludes; a failed attempt's is retained for post-mortem (its deterministic name makes it findable).removeWorktree({ retain })honors it (no exec,removed: falsewhen retained).CodingAgentDriverinterface (feat(miner-hands): define the CodingAgentDriver interface seam #4262) can accept it as its "scoped working directory" with no retrofit.Tests
test/unit/worktree-allocator.test.tscovers the pure naming/collision logic (determinism, sanitization, edge-separator trimming, length cap, empty-id rejection, no-collision across ids) and both exec wrappers via a fake exec that records calls and returns scripted results (exit-0 success, stderr surfacing, empty-stderr fallback, retain-skips-exec, remove success/failure). 100% line + branch coverage of the new module; paths are asserted cross-platform. Because the exec is injected, a follow-up real-gitintegration test (gated ongitavailability, per the issue's optional checkbox) drops in against the same seam without touching the primitive.Notes
src/services/**or any guarded path.