Repository navigation
fix(bin): fold path spellings in worktree and watcher identity checks - #2705
chappellerj wants to merge 3 commits into
Conversation
Two safety checks compared paths as raw strings, so one directory reached under two spellings read as two different locations. Worktree isolation: fm-spawn's assertion canonicalized with `cd … && pwd -P`, which resolves symlinks but preserves the caller's spelling of each component. On a case-insensitive filesystem a session opened as .../Firstmate and a treehouse path spelled .../firstmate are the same directory, so the guard compared them as distinct and accepted the primary clone as an isolated worktree. realpath(1) folds the spelling to the on-disk name; Perl's Cwd::realpath and Python's os.path.realpath share pwd -P's behavior and are unsuitable. fm_canonical_path now owns this and is used on both sides of the isolation assertion and of the watcher lock's home and watcher-path identity comparison, which produced false "watcher down" alarms after a session resume. Pool slot reuse: a treehouse slot is a reusable lease, so the recorded worktree= can name a slot already re-leased to another task. fm-spawn now records the canonical path the lease actually settled on and warns when another task's metadata claims the same slot; cleanup refuses outright when the recorded worktree holds a different task's fm/<id> branch, since its next steps delete that branch and reset the worktree. The refusal needs positive proof of a conflict, so a detached HEAD or a non-fm/ branch does not block routine cleanup, and --force does not override it: --force authorizes discarding this task's own work, never another task's. Tests cover the case-variant identity match (with an unrelated home still rejected), fm_canonical_path's folding, and the cleanup refusal, all skipping where the filesystem is case-sensitive and the case cannot arise.
…ard and pool-lease safety
|
Speaking as Kun's firstmate: Scheduled firstmate-oss pass. Diff reviewed against main (head Classification: corrective. Physical-dir identity was comparing caller spelling ( VISION:
Merge-eligible: YES. Same physical-dir class as earlier #2692. Overlap: teardown identity matches only |
kunchenguid
left a comment
There was a problem hiding this comment.
Speaking as Kun's firstmate: reviewed the full diff. No security risk. Corrective path-identity / pool-slot teardown guards. Approve pending first-time fork CI.
Summary
Two safety checks in firstmate's own tooling compared paths as raw strings, so one directory reached under two spellings read as two different locations. Both defeat checks that protect the never-write-to-projects prime directive.
Defect 1: case-variant home path defeats identity checks
A finding that departs from the original framing: the task prescribed normalizing with
pwd -P, andfm-spawnalready did that (landed in #294, a month before the incident).pwd -Presolves symlinks but preserves the caller's spelling of each component:Perl's
Cwd::realpathand Python'sos.path.realpathbehave likepwd -P, so the new helper deliberately shells out torealpath(1)despite an existing perl-realpath idiom elsewhere in the repo.Reproduced the near-miss: a worktree pointed at the primary clone with a case-variant project path was ACCEPTED before the fix, REFUSED after.
New
fm_canonical_path/fm_canonical_file_pathinfm-wake-lib.share applied on both sides of the spawn isolation assertion and both watcher-lock identity comparisons (fm-wake-lib.shandfm-watch-arm.shshared the weakness). The guard failure produced false "watcher down" alarms after a session resume.Defect 2: pool slot reuse leaves stale meta worktree pointers
fm-spawnnow records the canonical path the lease actually settled on.fm-teardownrefuses when the recorded worktree holds a different task'sfm/<id>branch, before the step that deletes that branch and resets the worktree.Deliberate design decisions
HEAD(how a landed task legitimately ends) or a non-fm/branch name does not block cleanup.--forcedeliberately does not override the refusal: it authorizes discarding this task's own work, never another task's.Review round
The review gate caught that the guard covered only the non-orca destructive path while the orca branch ran the identical
checkout --detach+branch -Dsequence unguarded. Extended to orca, pluscanonical_existing_dir(feeding orca's path-match equality check) had the samepwd -Pweakness and could cause a spurious refusal on a legitimate orca teardown. The hazard class is now closed on every supported backend.Verification
bin/fm-lint.shpasses (pinned ShellCheck 0.11.0, actionlint 1.7.12).fm-teardownherdr-preflight,fm-watch-arm,fm-wake-queue,fm-backend-orcametadata-write) were each confirmed failing identically on the clean baseline viagit stash/git checkout— unrelated to this change.