Make build/test worktree-aware and add same-worktree lock#737
Make build/test worktree-aware and add same-worktree lock#737johnml1135 wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the repo’s PowerShell build/test tooling to be worktree-aware, enabling safer concurrent workflows across multiple git worktrees while enforcing single active scripted workflow per worktree via a lock.
Changes:
- Add same-worktree exclusivity using a named mutex +
Output/WorktreeRun.lock.jsonmetadata (with optionalFW_BUILD_STARTED_BY/-StartedByactor tagging). - Scope process cleanup and file-lock retry cleanup to the current worktree root (
$PSScriptRoot) so other worktrees aren’t affected. - Change
build.ps1default MSBuild node reuse to-NodeReuse $falseto reduce cross-worktree contention, and document the new behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
build.ps1 |
Acquires worktree lock, scopes cleanup by repo root, defaults -NodeReuse to false, and passes -SkipWorktreeLock to child test.ps1 under -RunTests. |
test.ps1 |
Adds optional -StartedBy, supports -SkipWorktreeLock, scopes cleanup by repo root, and releases lock in finally. |
Build/Agent/FwBuildHelpers.psm1 |
Implements Enter-WorktreeLock/Exit-WorktreeLock, adds worktree-aware filtering to Stop-ConflictingProcesses, and extends Invoke-WithFileLockRetry with optional -RepoRoot. |
.github/instructions/build.instructions.md |
Documents worktree-aware cleanup, same-worktree lock behavior, and -NodeReuse default change. |
.github/instructions/testing.instructions.md |
Documents worktree-aware behavior and lock reuse for build.ps1 -RunTests. |
ReadMe.md |
Adds a concise overview of concurrent worktree behavior and lock tagging. |
| } | ||
| } | ||
| catch { | ||
| if (-not $hasHandle -and $mutex) { |
There was a problem hiding this comment.
In Enter-WorktreeLock, if the mutex has already been acquired ($hasHandle = $true) and an exception occurs after that (e.g., failing to create Output/ or write WorktreeRun.lock.json), the catch block rethrows without releasing/disposing the mutex. In a long-lived PowerShell session this can leave the mutex held and block subsequent build/test runs. Ensure the error path releases the mutex (when owned) and disposes it before throwing (or wrap the whole acquisition/write flow in a try/finally that always cleans up on failure).
| if (-not $hasHandle -and $mutex) { | |
| if ($mutex) { | |
| if ($hasHandle) { | |
| try { | |
| $mutex.ReleaseMutex() | |
| } | |
| catch { | |
| # Ignore release failures on error path | |
| } | |
| } |
Summary
Output/WorktreeRun.lock.jsonmetadata.FW_BUILD_STARTED_BYor-StartedBy.build.ps1 -RunTestsworking by having childtest.ps1reuse the parent lock (-SkipWorktreeLock).build.ps1 -NodeReusetofalsefor safer multi-worktree behavior.Files
build.ps1test.ps1Build/Agent/FwBuildHelpers.psm1.github/instructions/build.instructions.md.github/instructions/testing.instructions.mdReadMe.mdValidation
build.ps1orBuild/Agent/FwBuildHelpers.psm1.test.ps1(vstestOutputassigned but not used).This change is