Skip to content

fix(engine): refresh pooled worktree ownership - #2348

Merged
gsxdsm merged 3 commits into
mainfrom
fix/pool-worktree-ownership-refresh
Jul 20, 2026
Merged

fix(engine): refresh pooled worktree ownership#2348
gsxdsm merged 3 commits into
mainfrom
fix/pool-worktree-ownership-refresh

Conversation

@gsxdsm

@gsxdsm gsxdsm commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Pooled worktrees no longer retain the previous task's identity after reassignment, preventing valid commits from being rejected when the checked-out branch and stale ownership marker disagree. Fusion now refreshes the identity guard immediately after the pool prepares the new branch and before the checkout is exposed to the task, preserving the cross-task commit safety check. Regression coverage exercises the pooled acquisition path and confirms the new task identity is installed.

Related: FN-8400

Validation

  • 85 focused engine tests passed across executor worktree and acquisition coverage.
  • @fusion/engine typecheck passed.
  • Changed implementation lint and changeset validation passed.

Summary by CodeRabbit

  • Bug Fixes

    • Prevented stale pooled worktree ownership metadata from blocking commits after a pooled checkout is reassigned.
    • Refreshed task identity metadata when pooled worktrees are reused across task branches, ensuring hooks/attribution settings are correctly applied.
  • Tests

    • Added/updated coverage to confirm the task identity guard is reinstalled when acquiring pooled worktrees (including a real-git scenario proving commits succeed after stale identity is cleared).

Reinstall the task identity guard after a pooled checkout switches branches so stale ownership metadata cannot block the new task's commits.

Fusion-Task-Id: FN-8400
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 67cc80de-ac47-4124-96a7-8ae23018eebd

📥 Commits

Reviewing files that changed from the base of the PR and between 532b39c and e85d217.

📒 Files selected for processing (1)
  • packages/engine/src/__tests__/reliability-interactions/precommit-identity-guard.real-git.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/engine/src/tests/reliability-interactions/precommit-identity-guard.real-git.test.ts

📝 Walkthrough

Walkthrough

Pooled worktree acquisition now refreshes task identity and attribution guard metadata before reuse. Unit and real-git tests verify reassigned worktrees reject stale-owner commits and accept commits for the new task. A patch changeset documents the fix.

Changes

Pooled worktree identity refresh

Layer / File(s) Summary
Refresh pooled worktree identity
packages/engine/src/worktree-acquisition.ts, packages/engine/src/__tests__/executor-worktree.test.ts, packages/engine/src/__tests__/reliability-interactions/precommit-identity-guard.real-git.test.ts, .changeset/fix-pooled-worktree-ownership.md
Usable pooled worktrees refresh task identity and hook attribution settings before acquisition. Unit and real-git tests verify guard installation, stale-owner rejection, successful reassignment, and updated metadata; the changeset declares a patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: refreshing pooled worktree ownership handling in the engine.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pool-worktree-ownership-refresh

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refreshes ownership metadata when a pooled worktree is assigned to a new task. The main changes are:

  • Reinstalls the task identity guard after pooled branch preparation.
  • Adds pooled acquisition coverage for the new task ID and worktree path.
  • Adds a real-Git test for stale-owner rejection and successful ownership refresh.
  • Adds a patch changeset for the published package.

Confidence Score: 5/5

This looks safe to merge.

  • The pooled path refreshes ownership after changing branches and before exposing the checkout.
  • The real-Git test confirms that replacing the stale owner marker allows the new task to commit.
  • No blocking issue remains in the changed code.

Important Files Changed

Filename Overview
packages/engine/src/worktree-acquisition.ts Refreshes the identity guard after pooled branch preparation and before returning the worktree.
packages/engine/src/tests/executor-worktree.test.ts Checks that pooled acquisition requests an identity refresh for the new task.
packages/engine/src/tests/reliability-interactions/precommit-identity-guard.real-git.test.ts Reproduces stale-owner commit rejection with real Git and verifies that refreshing ownership permits the commit.
.changeset/fix-pooled-worktree-ownership.md Adds the required patch release note for the pooled worktree fix.

Reviews (3): Last reviewed commit: "test(FN-8400): tighten ownership guard a..." | Re-trigger Greptile

Comment thread packages/engine/src/__tests__/executor-worktree.test.ts
Reproduce the stale-owner rejection in a recycled linked worktree, then prove reassignment refreshes the marker and permits the new task commit.

Fusion-Task-Id: FN-8400
@gsxdsm

gsxdsm commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

The test checks the call but not the real commit-blocking symptom.

Addressed in 532b39c. The new real-Git regression reproduces a pooled worktree carrying the previous task marker, asserts that the new task commit is rejected, refreshes ownership, and then asserts the same commit path succeeds. The focused pool and identity-guard suite passes 81/81.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/engine/src/__tests__/reliability-interactions/precommit-identity-guard.real-git.test.ts (1)

37-51: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use a more targeted assertion and simplify path resolution.

Two minor improvements to consider:

  1. Since the identity guard hook explicitly exits with 1, you can use .toBe(1) instead of .not.toBe(0) to better align with the coding guidelines' preference for "targeted assertions".
  2. Node's path.resolve automatically treats absolute paths as the new root, making the isAbsolute ternary check redundant.
💡 Proposed tweaks
-      expect(staleOwnerCommit.status).not.toBe(0);
+      expect(staleOwnerCommit.status).toBe(1);
       expect(`${staleOwnerCommit.stderr}${staleOwnerCommit.stdout}`).toContain(
         "fusion: refusing commit — worktree owns FN-OLD but HEAD is fusion/fn-new",
       );
 
       await installTaskWorktreeIdentityGuard({ worktreePath: worktreeDir, taskId: "FN-NEW" });
 
       const refreshedOwnerCommit = spawnSync("git", ["commit", "-m", "fix(FN-NEW): accepted after owner refresh"], {
         cwd: worktreeDir,
         encoding: "utf-8",
       });
       expect(refreshedOwnerCommit.status).toBe(0);
 
       const taskIdPathRaw = git(worktreeDir, "git rev-parse --git-path fusion-task-id");
-      const taskIdPath = isAbsolute(taskIdPathRaw) ? taskIdPathRaw : resolve(worktreeDir, taskIdPathRaw);
+      const taskIdPath = resolve(worktreeDir, taskIdPathRaw);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/engine/src/__tests__/reliability-interactions/precommit-identity-guard.real-git.test.ts`
around lines 37 - 51, Update the staleOwnerCommit assertion to expect an exit
status of exactly 1, matching the identity guard’s contract. Simplify taskIdPath
construction by passing taskIdPathRaw directly to resolve, removing the
isAbsolute check and any now-unused import.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@packages/engine/src/__tests__/reliability-interactions/precommit-identity-guard.real-git.test.ts`:
- Around line 37-51: Update the staleOwnerCommit assertion to expect an exit
status of exactly 1, matching the identity guard’s contract. Simplify taskIdPath
construction by passing taskIdPathRaw directly to resolve, removing the
isAbsolute check and any now-unused import.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d7b60b7f-a3e0-48e4-b0e9-5573786c781f

📥 Commits

Reviewing files that changed from the base of the PR and between 1fd3966 and 532b39c.

📒 Files selected for processing (1)
  • packages/engine/src/__tests__/reliability-interactions/precommit-identity-guard.real-git.test.ts

Assert the exact refusal status and use path resolution directly in the pooled worktree symptom test.

Fusion-Task-Id: FN-8400
@gsxdsm

gsxdsm commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Use a more targeted assertion and simplify path resolution.

Fixed in e85d217: the stale-owner commit now asserts exit status 1, and the task marker path uses resolve(worktreeDir, taskIdPathRaw) directly. The focused real-Git suite passes 4/4.

@gsxdsm
gsxdsm merged commit 3b7680c into main Jul 20, 2026
7 checks passed
@gsxdsm
gsxdsm deleted the fix/pool-worktree-ownership-refresh branch July 20, 2026 00:05
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.

1 participant