Skip to content

fix(forker): tolerate vanished Git worktree locks - #2623

Merged
jbeda merged 1 commit into
mainfrom
fix/forker-vanished-worktree-lock
Oct 30, 2026
Merged

jbeda merged 1 commit into
mainfrom
fix/forker-vanished-worktree-lock

Conversation

@jbeda

@jbeda jbeda commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix the remaining internal/adapter/forker observation in #2327: TestForkDirtyOverlayConcurrent can fail when copying .git/worktrees/<id>/locked while Git removes that temporary checkout lock.

  • Tolerate ErrNotExist only for the exact .git/worktrees/<single-id>/locked path, both at the walk boundary and after enumeration when opening the source file.
  • Verify source-open error provenance so a destination-side ENOENT remains a failure.
  • Preserve a lock that still exists: locked can also represent an intentional operator-owned worktree lock.
  • Keep the existing maintenance-lock handling and all unrelated copy errors unchanged. No retries or broad missing-file suppression.

Evidence and regression coverage

The original CI attempt reports:

--- FAIL: TestForkDirtyOverlayConcurrent (0.07s)
    dirty_overlay_test.go:456: fork 2: forker: copy base tree: open …/.git/worktrees/mecatlfork-conc-1-3820690495/locked: no such file or directory

A failed worktree creation takes the recursive-copy fallback while other concurrent worktree creations mutate the repository's administrative files. The old copy walker failed if an enumerated locked file disappeared before os.Open.

The deterministic regression saves a real regular-file DirEntry, removes the file, and invokes the production callback. Both walk-time and source-open assertions fail before the fix. Negative controls retain errors for missing worktree HEAD/index locks, malformed/nested paths, ordinary tracked files, walk permission failures, non-ENOENT source-open failures, and destination-side ENOENT. A full copyTree test verifies an existing lock's contents are preserved.

Mutation checks:

  • Removing the source ENOENT guard fails the non-ENOENT source-open regression.
  • Removing source-path verification fails the destination ENOENT regression.

Verification

  • Passed focused race tests with -count=50 -cpu=1,2,4 (150 executions per selected top-level test), including TestForkDirtyOverlayConcurrent, copy-tree regressions, existing maintenance-lock tests, and force-copy maintenance-lock integration.
  • Passed the complete forker package after restoring both mutations.
  • Passed task test.
  • Passed task lint (including after the final test addition).
  • Passed task test:race.
  • Passed go run ./cmd/mecademo: real offline engine tool call, permission ask/approval, and final result; team and background subagent demos also passed.
  • Independent review: Spec, Standards, Test adequacy, Security, Architecture, Library reuse, and Duplication; one test-adequacy finding addressed and re-reviewed, no outstanding findings.

API compatibility

Backward-compatible bug fix restoring successful local environment forking when a Git administrative lock disappears. No client changes, wire schemas, event/control semantics, API major, or feature identifiers change. No exported Go API or persisted-data format changes; no migration or coordinated upgrade required.

This addresses only the related forker observation in #2327. It does not close the umbrella tracker or claim all concurrent Git metadata races are solved.

Handle the remaining concurrent-fork observation in #2327 at both the walk and source-open boundaries. Preserve existing locks and propagate unrelated source and destination failures.

Co-authored-by: Mecatl <[email protected]>
@jbeda
jbeda merged commit cca18a3 into main Oct 30, 2026
38 checks passed
@jbeda
jbeda deleted the fix/forker-vanished-worktree-lock branch October 30, 2026 18:43
@jbeda jbeda mentioned this pull request Oct 31, 2026
10 of 14 tasks
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Nov 18, 2026
2 tasks
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.

2 participants