Repository navigation
fix(worktree): evict a stale side-branch checkout from either scope (#1443) - #1445
Conversation
No other confident findings in the specified diff. |
b1b1c00 to
110ec80
Compare
|
Follow-up after the E2E failure: the first version removed any other checkout of the branch, which also deleted a member's manually placed
An arbitrary member worktree is left alone, so the existing
The remaining |
Review limitation: the exact three-dot diff is unavailable because the shallow checkout lacks the merge base, and network lookup failed. These findings use the available PR head-commit diff; no PR code was run, built, or installed. |
Review limitation: the exact three-dot diff is unavailable because the shallow checkout lacks the merge base, and GitHub lookup failed. The code finding uses the available base-to-head diff; a complete review of the requested diff was not possible. No PR code was run, built, or installed. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
@Walternater Thanks, the eviction fix works. With the built CLI on a kind: self team seeded at user scope and in a project partition: on main the user-scope pull fails with 'teamai-reports' is already used by worktree at .../projects/<slug>/reports-wt and keeps its usage local. Here it takes the reports and learnings checkouts back and pushes. The new test fails on main and passes here. self-mode-worktrees-808 passes on both builds, including "publishes from both checkouts".
Two changes before merge:
- [P1 blocking] The body has no real-CLI record. Code Review Rules: a runtime change needs "an end-to-end / real-CLI verification record, not only unit tests or type checks". A full workspace install is not needed. A user-scope
~/.teamai/config.yamlnext to the project config reproduces #1443 with the built CLI. Seeduser-usage.jsonlbefore each user-scope pull, since a user-scope pull never touches the reports branch without it. Please paste themainvs PR output. - [P1 blocking] Each user-scope take-back records a false git-hook failure. When the user scope re-creates
~/.teamai/reports-wtas a worktree of the business repo, git fires the project'spost-checkouthook.isOwnCheckout(src/hook-handlers.ts:233-236) knows only the partition data home andrepo.localPath, so it treats the checkout as a new member worktree. It runsprepareCheckouton the orphan branch, records a hook failure and spawns a detached pull there. Afterwardsteamai doctorin the project exits 1 with✖ Last git hook run failed: post-checkout failed ..., and the next project pull prints the same warning. Onmain,doctorexits 0. This repeats after every user-scope pull that follows a project pull. There are two ways to fix it:- The smallest is to count the user-scope side-branch checkouts as teamai's own in
isOwnCheckout, for exampleWORKTREE_DIRNAMES.map((d) => path.join(getTeamaiHomeDir(), d)). - The better one is option 1 in #1443: give a
kind: selfrepo one side-branch checkout whatever the scope, so both scopes share one checkout and one lock. That also removes the eviction loop below.
- The smallest is to count the user-scope side-branch checkouts as teamai's own in
Non-blocking:
- [P2 non-blocking] The partition match accepts any
.../projects/<x>/<dirname>, not only~/.teamai/projects. A clean member checkout ofteamai-reportsatcode/projects/demo/reports-wtis removed instead of refused, which goes against the body's "a member-placed worktree elsewhere is left alone". Nothing is lost, since there is no--forceand the branch stays. Comparing with the real projects root fixes it. git records realpaths, so resolve that side too:const projectsRoot = await fse.realpath(projectsRootDir()).catch(() => path.resolve(projectsRootDir())); const projectPartition = path.dirname(path.dirname(resolved)) === projectsRoot && path.basename(resolved) === spec.worktreeDirname;
- [P2 non-blocking] The two scopes now evict each other on every alternating pull: each pull removes and re-creates both checkouts, and the scopes use separate lock files. No data is lost, but if symmetric eviction stays, the body should say so. The single-checkout option above removes this too.
CI review: we agree on the missing real-CLI record. We agree the loose partition match is real but rate it P2, since it needs a member to check out teamai's side branch by hand at such a path and loses nothing. It did not see the hook failure.
Verified at ca55ec1: tsc, lint, the related unit tests (38) and the two self-mode e2e files pass. Not run here: Windows, the gitlab and github providers, an evicted checkout with unpushed commits, and concurrent pulls from both scopes.
…encent#1443) The narrowed eviction trusts paths that look like teamai's own, so pin the other half of the contract: a clean checkout of the side branch outside those paths stays, and the checkout that needs the branch reports it.
ca55ec1 to
e069b23
Compare
Review limitation: the requested three-dot diff fails locally with “no merge base.” These findings are confirmed in the two PR-related commits available locally; a complete review of the exact requested range was not possible. No PR code was run, built, or installed. |
|
Addressed the two P1s and the P2 in 2c4e300:
Verification: |
Resolved: the earlier member-owned-worktree deletion finding is fixed in the available PR commits. Partition eviction now checks the actual TeamAI projects root, and a regression test covers a member checkout with the matching suffix outside that root. Review limitation: the requested three-dot diff fails locally with “no merge base,” and GitHub lookup failed. Code assessment uses the three available PR-related commits, not a complete review of the exact requested range. No PR code was run, built, or installed. |
No PR code was run, built, or installed. Please provide the exact diff or a checkout containing its merge base to complete the review. |
ab030f8 to
c75bfc2
Compare
Please provide the exact diff or a checkout containing its merge base to complete the review. No PR code was run, built, or installed. |
Review context for the current head
The branch is 4 commits ahead of Since the 04:03Z review, all three findings have been addressed:
CI on |
|
@SaulMoro friendly nudge — the two P1s and the P2 from your review are addressed on
CI is fully green on |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
@Walternater Thanks, all four items are resolved. With the built CLI on a kind: self team with a user and a project config, plain and with a symlinked HOME:
- After each user-scope pull that follows a project pull,
teamai doctorin the project exits 0, everypost-checkoutdispatch is ok, and nothing is delivered into~/.teamai/reports-wt. - A clean member checkout of
teamai-reportsat a non-teamaicode/projects/demo/reports-wtis refused and kept by both scopes. The new partition test fails on the previous head and passes here. - The body now describes the symmetric eviction between scopes, and it behaves as described.
[P3 nit] The body's record names 2c4e3006; the only later change is a test regex, so it still covers the runtime change.
CI review: we agree the real-CLI record is resolved. Its "no merge base" note comes from its shallow checkout; the merge base is 703d1c93.
Verified at c75bfc2: build, tsc and lint pass; the related unit tests (246, the changed files also under a symlinked TMPDIR), self-mode-worktrees-808 (29) and 6 related e2e files (93) pass; CI is green. Not run here: Windows, the gitlab and github providers, and concurrent pulls from both scopes, which the single-checkout option in #1443 would settle.
…1443) A user-scope `kind: self` install and the repo's project partition computed different reports/learnings worktree paths, so whichever pulled second could take the branch but the other could never take it back. Tencent#1445 made eviction symmetric; each alternating pull still moved both checkouts and the two scopes used separate locks. Resolve one side-branch home per repository from its project anchor, attach it to the config at load time as a runtime-only `branchHome` (never saved), and let `getWorktreeDir` and the lock beside each checkout follow it. The first upgraded pull takes over a checkout left in `~/.teamai/` or a legacy `<checkout>/.teamai/` under the lock beside that checkout, so a command still using it is never deleted from under. Config, state, usage and queue files stay where each scope keeps them; hook ownership and every reader go through the same seam.
…1443) A user-scope `kind: self` install and the repo's project partition computed different reports/learnings worktree paths, so whichever pulled second could take the branch but the other could never take it back. Tencent#1445 made eviction symmetric; each alternating pull still moved both checkouts and the two scopes used separate locks. Resolve one side-branch home per repository from its project anchor, attach it to the config at load time as a runtime-only `branchHome` (never saved), and let `getWorktreeDir` and the lock beside each checkout follow it. The first upgraded pull takes over a checkout left in `~/.teamai/` or a legacy `<checkout>/.teamai/` under the lock beside that checkout, so a command still using it is never deleted from under. Config, state, usage and queue files stay where each scope keeps them; hook ownership and every reader go through the same seam.
…1443) A user-scope `kind: self` install and the repo's project partition computed different reports/learnings worktree paths, so whichever pulled second could take the branch but the other could never take it back. Tencent#1445 made eviction symmetric; each alternating pull still moved both checkouts and the two scopes used separate locks. Resolve one side-branch home per repository from its project anchor, attach it to the config at load time as a runtime-only `branchHome` (never saved), and let `getWorktreeDir` and the lock beside each checkout follow it. The first upgraded pull takes over a checkout left in `~/.teamai/` or a legacy `<checkout>/.teamai/` under the lock beside that checkout, so a command still using it is never deleted from under. Config, state, usage and queue files stay where each scope keeps them; hook ownership and every reader go through the same seam.
…1443) A user-scope `kind: self` install and the repo's project partition computed different reports/learnings worktree paths, so whichever pulled second could take the branch but the other could never take it back. Tencent#1445 made eviction symmetric; each alternating pull still moved both checkouts and the two scopes used separate locks. Resolve one side-branch home per repository from its project anchor, attach it to the config at load time as a runtime-only `branchHome` (never saved), and let `getWorktreeDir` and the lock beside each checkout follow it. The first upgraded pull takes over a checkout left in `~/.teamai/` or a legacy `<checkout>/.teamai/` under the lock beside that checkout, so a command still using it is never deleted from under. Config, state, usage and queue files stay where each scope keeps them; hook ownership and every reader go through the same seam.
…1443) A user-scope `kind: self` install and the repo's project partition computed different reports/learnings worktree paths, so whichever pulled second could take the branch but the other could never take it back. Tencent#1445 made eviction symmetric; each alternating pull still moved both checkouts and the two scopes used separate locks. Resolve one side-branch home per repository from its project anchor, attach it to the config at load time as a runtime-only `branchHome` (never saved), and let `getWorktreeDir` and the lock beside each checkout follow it. The first upgraded pull takes over a checkout left in `~/.teamai/` or a legacy `<checkout>/.teamai/` under the lock beside that checkout, so a command still using it is never deleted from under. Config, state, usage and queue files stay where each scope keeps them; hook ownership and every reader go through the same seam.
…encent#1443) (Tencent#1445) * fix(worktree): let any scope take the side-branch checkout back (Tencent#1443) * test(worktree): cover a member-made checkout teamai must not evict (Tencent#1443) The narrowed eviction trusts paths that look like teamai's own, so pin the other half of the contract: a clean checkout of the side branch outside those paths stays, and the checkout that needs the branch reports it. * fix(worktree): scope eviction to teamai projects and own user checkouts (Tencent#1443) * test(worktree): accept git's 'already used by worktree' phrasing on CI --------- Co-authored-by: wangchongfei <[email protected]>
…1443) A user-scope `kind: self` install and the repo's project partition computed different reports/learnings worktree paths, so whichever pulled second could take the branch but the other could never take it back. Tencent#1445 made eviction symmetric; each alternating pull still moved both checkouts and the two scopes used separate locks. Resolve one side-branch home per repository from its project anchor, attach it to the config at load time as a runtime-only `branchHome` (never saved), and let `getWorktreeDir` and the lock beside each checkout follow it. The first upgraded pull takes over a checkout left in `~/.teamai/` or a legacy `<checkout>/.teamai/` under the lock beside that checkout, so a command still using it is never deleted from under. Config, state, usage and queue files stay where each scope keeps them; hook ownership and every reader go through the same seam.
Problem
A single-repo (
kind: self) team installed at user scope and the project-scope partition of the same repo compute different side-branch worktree paths:~/.teamai/reports-wt~/.teamai/projects/<slug>/reports-wtGit allows
teamai-reportsto be checked out in one worktree only.removeOldCheckoutsInDotTeamaionly removed checkouts whose path ends with/.teamai/<worktree-dirname>. The user-scope path matches that suffix, but the project partition path does not, so:The same applies to
teamai-learnings.Fix
removeOldCheckoutsInDotTeamainow removes a checkout only when it is a path teamai manages:<checkout>/.teamai/<worktree-dirname>, and<projectsRoot>/<slug>/<worktree-dirname>(both sides resolved withrealpath).An arbitrary worktree a member placed elsewhere is left alone: git refuses the second checkout, and the existing
CheckoutRefusedErrorreports it instead of silently deleting the member's checkout (#808 behavior). This closes the P2 gap where any.../projects/<x>/reports-wtwas evicted.isOwnCheckoutnow also recognizes~/.teamai/{reports,learnings,knowledge}-wtas teamai's own. Without this, the user-scope take-back recreates~/.teamai/reports-wtthrough a project git hook, which prepares it as if it were a member worktree, records a falsepost-checkoutfailure, and makesteamai doctorexit 1.This makes eviction symmetric for the user-scope vs project-partition case: whichever scope pulls can take ownership of a managed checkout instead of one scope locking the other out. It still uses
git worktree removewithout--force: a checkout with uncommitted changes stays and the member gets the existing refusal message. Symmetric eviction is intentional: alternating user/project pulls can take the shared checkout back and forth; the single-checkout option in #1443 would remove that loop, but is not part of this PR.Real-CLI verification
Built the CLI from base
703d1c93and PR2c4e3006, then ran a fresh sandbox in Git 2.32 (script hooks): akind: selfteam with a project config and a user config, seeding~/.teamai/user-usage.jsonlbefore each user pull.Base
703d1c93— user scope cannot take the checkout back:PR
2c4e3006— takes it back, publishes usage, clean doctor:False hook failure (A/B): with only the eviction change and
isOwnCheckoutreverted, the same take-back produceddoctor rc=1:With the
isOwnCheckoutchange restored:doctor rc=0,✔ No git hook failure recorded.Testing
npm run typechecknpm run lintnpx vitest run src/__tests__/branch-worktree-scope-eviction.test.ts src/__tests__/hook-handlers.test.ts src/__tests__/git-hook.test.ts— 165 passed, 11 skipped.npx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/self-mode-worktrees-808.test.ts -t "stops maintenance and promote"— 2 passed.leaves a member checkout under a non-teamai projects path aloneuses real git: it fails on110ec80d(the member checkout is evicted and the call resolves) and passes on this PR (the checkout stays, andensureReportsWorktreerefuses). The existingelsewhere-reportstest is kept.Known pre-existing flake:
self-mode-worktrees-808 › publishes from both checkoutsalso fails onorigin/mainin this environment (verified by switching to base), so it is not caused by this change.Refs #1443.