Repository navigation
feat(pool): seed ignored files from .worktreeinclude - #48
nikolauska wants to merge 37 commits into
Conversation
mbrookson
left a comment
There was a problem hiding this comment.
Nice implementation — using git ls-files + check-ignore for pattern matching is the right call over rolling our own glob expansion. A few observations from independently building the same feature (closed #50 in favour of this):
Seeding runs inside the state lock
Both call sites invoke SeedWorktree inside the WithStateLock closure, which means the flock is held for the duration of the file copies. For repos with large ignored files this could block concurrent treehouse commands unnecessarily. The post-create hooks already run after the lock is released — seeding feels like it belongs there too, since it's not mutating pool state. Something like:
// after WithStateLock returns, before hooks.Run
if err := git.SeedWorktree(repoRoot, acquired); err != nil {
fmt.Fprintf(os.Stderr, "warning: .worktreeinclude: %v\n", err)
}(Whether to warn or hard-fail is a separate question — see below.)
excludedIncludeSubtree only handles !dir/ negations, not !file
The custom parser skips lines matching !<dir>/ but a bare negation like !.env.local won't be excluded. Given the function comment says "Git does not descend into an excluded directory", I think this is intentional — but it's worth a doc comment clarifying that file-level negations aren't supported so users don't write !secrets/prod.json and wonder why it still gets copied.
Seed errors abort acquire for the missing-file case
If .worktreeinclude lists .env but a contributor doesn't have that file locally (common on a fresh clone), git ls-files returns nothing for it and the seed silently skips it — so this is actually fine in practice. The error path that would bite is an OS-level failure mid-copy. Current behaviour (abort acquire) is defensible, though a warning-and-continue would be more resilient. Worth a deliberate decision either way.
|
Thanks for the review. I moved seeding outside the state lock and changed OS-level copy failures to warn without failing the acquire. I also clarified that Git handles file-level negations directly and added coverage for |
f7b2fe2 to
4f7b2a7
Compare
|
Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch. When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again. Noted for treehouse#48 at |
2bdbbfe to
c650ff6
Compare
|
Rebased onto the latest main and fixed several issues found during review of
|
|
@kunchenguid can this be added to the next release? 🙏 |
|
Speaking as Kun's firstmate: this branch currently has a merge conflict with main ( |
eacd8c8 to
7f6df41
Compare
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (45): Last reviewed commit: "no-mistakes(review): Quarantine release ..." | Re-trigger Greptile |
f2cc1b9 to
a1a6e95
Compare
|
Speaking as Kun's firstmate: thanks for the rebase. This is now mergeable (not dirty). I approved fork CI for
|
|
Speaking as Kun's firstmate: newer activity is the no-mistakes raise (Pipeline section is now on the body) plus Greptile still 5/5 on 573e7c6. Opt-in VISION (per rule):
Approved current-head CI 32408269816 and no-mistakes 32408269766. Not merging until those runs are actually green. Helping this PR; not opening a second path for #39. |
2821c7d to
bbe58c4
Compare
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
bbe58c4 to
52e6b80
Compare
4875fc3 to
c2c9479
Compare
|
Speaking as Kun's firstmate: newer head fa1052c (title now Inspected on this SHA:
VISION (per rule):
|
|
Speaking as Kun's firstmate: stale-restamp pass. This is not a 14-day author close — last author push was 2026-08-22, and the last triage stamp was contract-class: opt-in (missing VISION (per rule, pre-resolve):
Resolving conflicts now; will re-approve fork CI and continue toward merge only if still opt-in + green + safe Greptile. |
|
Speaking as Kun's firstmate: closing in favor of last-resort port #129, which just landed on main as |
Intent
Add .worktreeinclude support so newly created pooled worktrees can be seeded from explicitly listed repository files while preserving Treehouse's safety guarantees across Git and Jujutsu backends. Seed only ignored files, validate and authenticate persisted seed inventories, fail closed or quarantine unsafe, corrupt, unknown, or legacy inventory state, recover cleanly from state-persistence and missing-state failures, keep reset/release/prune/destroy behavior safe, document the feature and recovery constraints, and retain Linux, macOS, and Windows compatibility.
What Changed
.worktreeincludeinto newly created and reused Git worktrees and Jujutsu workspaces.Risk Assessment
Testing
Focused Git, Jujutsu, pool-state, quarantine, recovery, persistence-failure, symlink-safety, and Windows compilation checks passed; the saved end-to-end CLI transcript demonstrates selected ignored-file seeding and refresh on reuse.
Evidence: CLI seeding and reuse transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed (9) ✅
internal/vcs/jjvcs/jjvcs.go:334- Intent requires safety “across Git and Jujutsu backends,” but a seeded jj workspace cannot be released or reused.ResetWorktreeWithSeededPathsresets the workspace and then callsgitvcs.RemoveSeededPaths; that helper requires a regular.gitmarker and backlink, while pooled jj workspaces are.jj-only. Sequence: acquire a jj workspace with one selected ignored file → callreturnor reacquire it → cleanup returns “refusing to clean unregistered worktree” → the seed remains and the workspace stays unavailable. Add backend-aware cleanup authentication at the shared cleanup boundary, validating jj’s.jj/repopointer for jj workspaces, and cover a successful seeded jj reset/release (current tests cover only cleanup after reset failures).🔧 Fix: Authenticate Jujutsu workspaces during seeded cleanup
1 error still open:
internal/vcs/gitvcs/gitvcs.go:789- The required safety guarantee “across Git and Jujutsu backends” remains incomplete.authenticateJJWorkspaceaccepts any directory containing a regular.jj/repopointer to an existing store; unlike Git cleanup, it never proves that the marker belongs to this managed path. Sequence: replace a managed jj workspace beforereturnwith another directory containing a copied.jjmarker and a user file whose name is in the signed seed inventory → jj reset can recognize the copied workspace metadata → this guard succeeds → cleanup silently deletes that user file. Authenticate the workspace against its expected registration/identity at the earliest cleanup boundary, and add the jj equivalent of the existing unregistered-replacement test.🔧 Fix: Bind Jujutsu cleanup to original workspace identity
2 errors still open:
internal/vcs/gitvcs/gitvcs.go:764- The required “safety guarantees across Git and Jujutsu backends” are violated because this unconditionally deletes an adjacent path that was never authenticated as Treehouse-owned. Sequence: a file already exists at<workspace>.treehouse-jj-seed-auth→ destroying any jj workspace callsRemoveWorktree→ the workspace is removed and this function silently deletes that unrelated file. Create authentication state in a collision-safe managed location and remove it only after verifying its identity/ownership.internal/vcs/jjvcs/jjvcs.go:202- The requirement to “fail closed or quarantine unsafe” state is contradicted because a failed authentication-sidecar creation discards the partial seed inventory. Sequence: seeding copies one or more files →PrepareJJSeededCleanupfails (for example, the sidecar path already exists) → this returnsnil, err→ if worktree removal also fails, pool quarantine records a verified empty inventory → a laterreturncan release the workspace without deleting the copied ignored files. Returnseeded, errso quarantine preserves every path already copied.🔧 Fix: Secure Jujutsu authentication state and preserve inventory
1 warning still open:
internal/vcs/jjvcs/jjvcs.go:288- A seeded jj workspace deleted outside Treehouse leaves its hard-linked authentication file behind. The nextgetself-heals the stale workspace registration and recreates the workspace at the same path, butPrepareJJSeededCleanuprejects the stale authentication link; cleanup then reaches this call, which also rejects it because it does not match the new.jj/repo, leaving the recreated workspace quarantined and the slot unusable. Handle authentication state for an already-missing workspace at the managed cleanup boundary so stale state cannot block safe path reuse.🔧 Fix: Clean authenticated stale Jujutsu state before recreation
1 error still open:
internal/vcs/gitvcs/gitvcs.go:821- The required criterion to preserve “safety guarantees across Git and Jujutsu backends” is still contradicted byreturn os.Remove(authPath): ownership is inferred only from attacker-controlled file contents. Sequence: while the workspace path is absent, create the predictable auth file as an ordinary user file containing this repository’s valid jj store path →AddWorktreecalls this helper → every check succeeds → Treehouse silently deletes the unrelated file. The new wrong-store test misses this same-store forgery. Authenticate stale state using signed pool-owned metadata at the managed pool boundary before deleting it; otherwise fail closed.🔧 Fix: Authorize stale Jujutsu cleanup with signed state
1 error still open:
internal/pool/pool.go:629- The required “recover cleanly from ... missing-state failures” behavior remains broken because stale jj authentication is cleaned only at the start ofacquire. Concrete sequence: a seeded jj workspace is deleted externally →status,prune, ordestroycallshealStateand persists the state without the missing entry (orreturnclears its signed inventory) → the authentication hard link remains but its signed authorization is lost → the nextgetrecreates the same path, seeding collides with the stale link, and removal refuses the mismatched new workspace, leaving the slot quarantined. Move authenticated stale cleanup to the shared boundary before every operation that discards a missing entry or its inventory; otherwise preserve the signed entry until cleanup succeeds.🔧 Fix: Consume stale authorization before healing state
1 error still open:
internal/pool/pool.go:654- The required safety guarantee is violated because signed seed inventory authenticates the worktree entry, not the file being deleted. Concrete path: a seeded Git worktree is deleted externally, and an unrelated regular file exists at its predictable.treehouse-jj-seed-auth/<digest>path →healStatecannot determine the missing worktree’s backend and calls this helper for every signed non-empty inventory →RemoveStaleJJSeedAuthenticationdeletes that file solely because it is regular. The same replacement is possible for a jj auth hard link after workspace deletion. Persist authenticated auth-file identity/backend metadata and verify it before deletion; otherwise fail closed. The new test currently codifies the unsafe result by replacing the auth link withforged user dataand then expectingListto delete it.🔧 Fix: Authenticate stale Jujutsu files by signed identity
1 error still open:
internal/vcs/gitvcs/gitvcs.go:817- The required “safety guarantees across Git and Jujutsu backends” remain vulnerable to a pathname race.RemoveStaleJJSeedAuthenticationverifies the file’s identity, checks that the workspace is absent, and then deletes by pathname; a concurrent process can replace the authentication path after verification, causingos.Remove(authPath)to delete the replacement without error.RemoveJJSeedAuthenticationhas the same check-then-remove sequence for live workspaces. Move and verify the exact file through a pinned directory handle or otherwise make identity verification and removal one safe operation; add a regression that swaps the path between verification and deletion.🔧 Fix: Quarantine authentication files before verified deletion
1 error still open:
internal/vcs/gitvcs/gitvcs.go:738- The required “safety guarantees across Git and Jujutsu backends” remain violated on the normal reset/release path.RemoveSeededPathsFromJJWorkspaceauthenticates and removes the seeded files, then deletes the authentication pathname directly. Sequence: another local process replaces that authentication path after authentication but before line 738 →os.Removesilently deletes the replacement. The new quarantine logic covers destroy and stale cleanup only. Route this deletion throughRemoveJJSeedAuthentication(or the same quarantine-and-verify boundary) and cover the reset/release path with the concurrent-replacement regression.🔧 Fix: Quarantine release authentication before deletion
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
go test ./internal/pool -run 'Test(Acquire.*(Seed|StateWrite|Quarantine)|Release.*(Seed|Quarantine|Recovered)|ReadState_.*(Inventory|Integrity|Recovered)|StaleJJAuthentication|AcquireDoesNotExecuteSeedFilter|AcquireIgnoresBrokenRequiredSeedFilter)' -count=1go test ./internal/vcs/gitvcs -run 'Test(Seed|ResetWorktree.*Seed|EmptySeedInventory|RemoveSeeded|PrepareJJSeeded|RemoveJJSeed|RemoveStaleJJSeed)' -count=1go test ./internal/vcs/jjvcs -run 'Test(Seed|ResetWorktree.*Seed)' -count=1Built the CLI and exercisedtreehouse get --lease --json --no-fetchplustreehouse return --forceacross initial creation and reuse in an isolated Git repository.GOOS=windows GOARCH=amd64 go test -cfor./internal/pool,./internal/vcs/gitvcs, and./internal/vcs/jjvcs.Verifiedgit status --shortwas clean after removing transient test artifacts.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.