Skip to content

fix: stage remote home clones before publication - #5733

Merged
kunchenguid merged 6 commits into
mainfrom
fm/fm-remote-seed-clone-flake-r1
Sep 26, 2026
Merged

kunchenguid merged 6 commits into
mainfrom
fm/fm-remote-seed-clone-flake-r1

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

Fix the flaky CI failure in tests/fm-spawn-compact-adviser-disable-remote.test.sh where provisioning a remote seed home intermittently dies with 'fatal: failed to copy file to /.git/objects/...: No such file or directory'. Reliability policy: fix the cause, never retries, sleeps, or looser thresholds. Root fix: fm-remote-home-provision.sh clones the code root into a private staging directory beside the target home and publishes it with an atomic rename only once the clone completes, so no cleanup (its own rollback, a competing provision, or an external rm -rf of the public path) can remove a directory a live clone is still writing; a sentinel file written inside the stage proves after the rename that the published home is ours, so a home appearing mid-provision dies cleanly without adopting, altering, or nesting into the foreign path. Regression coverage in fm-remote-secondmate-lifecycle-e2e.test.sh holds a real clone mid-copy through a git shim (SIGSTOP verified via ps state), removes the public home path, and requires an intact published clone (rev-parse, fsck, clean status, content compare); a second scenario proves a foreign home created during the hold survives untouched while the provision dies cleanly. Verified to fail pre-fix and pass post-fix. Deliberately out of scope: a sibling 'rm: Directory not empty' cleanup failure in CI run 36202051270 is not proven to share this cause.

What Changed

  • Clone new remote homes into private staging directories and publish them only after cloning completes, so cleanup of the public path cannot interrupt a live clone.
  • Detect a home that appears before publication and fail without altering it; document the behavior and add lifecycle regression coverage for both races.

Risk Assessment

✅ Low: The staged clone, post-rename ownership check, rollback path, and behavioral regression coverage are bounded and show no substantiated new defect.

Testing

The focused lifecycle races and compact-adviser regression passed. Direct CLI checks confirmed an intact published clone, clean refusal of a competing home, and ordinary seed convergence. The broader lifecycle run timed out after its provisioning checks passed; its later coverage is not claimed. No worktree artifacts remain.

  • Live validation: ✅ go - 3 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Provision a remote seed home and converge it without damaging its checkout ✅ pass live direct-cli.log: published identity, matching tracked content, clean Git status, successful fsck and second provision
Remove the public home while a real clone is stopped, then receive an intact published checkout ✅ pass live direct-races.log: Git child verified stopped; published HEAD, fsck, clean status, and content match
Create a competing home during the stopped clone and retain it untouched when provision fails ✅ pass live direct-races.log: ownership refusal, foreign content intact, no nested stage or staging residue
Overlap two provisions without cloning the published home twice ⏸️ untested no A live concurrent remote-host run was not available; provide an authorized disposable remote host to exercise both provisions outside the fixture.
Seed and launch a remote second mate with the compact adviser disabled ⏸️ untested no An authorized remote Mac and its real Herdr login were not provided for a live remote launch; provide a disposable host and login.
Evidence: Live clone-race CLI transcript

Source: Live clone-race CLI transcript

removed held real git child: 29173 T ~/.no-mistakes/worktrees/52b07e9083e7/01M3DMQT0WSYWHWAWC3C51SZVG/.live-races.LKgAt9/.fm-home-provisioning.wpHqOp
removed outcome=success
removed: complete HEAD, fsck, clean status, content match; marker=race
foreign held real git child: 34104 T ~/.no-mistakes/worktrees/52b07e9083e7/01M3DMQT0WSYWHWAWC3C51SZVG/.live-races.LKgAt9/.fm-home-provisioning.TG9b2a
foreign outcome=failure
error: remote home appeared while it was being provisioned
foreign: operator-owned content intact and no nested stage
no staging residue
Evidence: Live seed and foreign-home CLI transcript

Source: Live seed and foreign-home CLI transcript

Direct CLI seed from the worktree code root:
provisioned: ~/.no-mistakes/worktrees/52b07e9083e7/01M3DMQT0WSYWHWAWC3C51SZVG/.live-provision.y1exzw/seed projects=0
identity=live-seed
head=31d46ab7
git-status=0
tracked-content=matches
Converge same home:
provisioned: ~/.no-mistakes/worktrees/52b07e9083e7/01M3DMQT0WSYWHWAWC3C51SZVG/.live-provision.y1exzw/seed projects=0
Reject an unmarked foreign home without altering it:
error: existing remote home is not a safe Firstmate checkout
foreign-content=foreign
foreign-entries=1
Evidence: Focused provisioning race checks

Source: Focused provisioning race checks

ok - overlapping remote home provisioning serializes through publication and rollback
ok - competing cleanup of the public home cannot reach a live provisioning clone
ok - a home that appears mid-provision makes the provision die without touching it
ALL TESTS PASSED
Evidence: Remote compact-adviser regression

Source: Remote compact-adviser regression

ok - a remote-routed second mate starts with the compact adviser disabled, from the pane export and from the launch command alike
ok - the remote route keeps the compact-adviser switch through the cleared allowlisted environment
ALL TESTS PASSED
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/pre-rebase: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/pre-applypatch: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/pre-auto-gc: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/pre-merge-commit: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/post-commit: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/sendemail-validate: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/applypatch-msg: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/prepare-commit-msg: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/post-checkout: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/post-applypatch: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/post-rewrite: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/commit-msg: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/pre-push: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/post-merge: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks/pre-commit: Permission denied
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route/ios.git-hooks: Directory not empty
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state/parent-route: Directory not empty
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home/state: Directory not empty
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag/remote-home: Directory not empty
rm: /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-remote-compact-adviser.0dRtag: Directory not empty

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Provision a remote seed home and converge it without damaging its checkout ✅ pass live direct-cli.log: published identity, matching tracked content, clean Git status, successful fsck and second provision
Remove the public home while a real clone is stopped, then receive an intact published checkout ✅ pass live direct-races.log: Git child verified stopped; published HEAD, fsck, clean status, and content match
Create a competing home during the stopped clone and retain it untouched when provision fails ✅ pass live direct-races.log: ownership refusal, foreign content intact, no nested stage or staging residue
Overlap two provisions without cloning the published home twice ⏸️ untested no A live concurrent remote-host run was not available; provide an authorized disposable remote host to exercise both provisions outside the fixture.
Seed and launch a remote second mate with the compact adviser disabled ⏸️ untested no An authorized remote Mac and its real Herdr login were not provided for a live remote launch; provide a disposable host and login.
  • FM_TEST_PROVISION_ONLY=1 tests/fm-remote-secondmate-lifecycle-e2e.test.sh
  • tests/fm-spawn-compact-adviser-disable-remote.test.sh
  • Direct bin/fm-remote-home-provision.sh seed, convergence, and foreign-home refusal using the worktree as the code root
  • Direct provisioning with a verified SIGSTOPed real Git clone, followed by public-path removal and competing-home creation
  • tests/fm-remote-secondmate-lifecycle-e2e.test.sh (timed out after 240 seconds, beyond the targeted provisioning checks)
⏭️ **Document** - skipped

Step was skipped.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A remote home provision cloned the code root directly into the public
FM_HOME path while rollback() claimed rm -rf of that same path on any
failure. Bash defers trapped signals past a foreground child, but any
other cleanup or lifecycle path that removes the home directory races
the live clone's object copy, producing the CI flake "fatal: failed to
copy file to .../.git/objects/...: No such file or directory".

Clone into a private staging directory beside the home and publish with
an atomic rename once complete, so no cleanup can remove a directory a
live clone is still writing; a home that appears mid-provision now dies
cleanly instead of inheriting torn state. The regression coverage holds
a real clone mid-copy, removes the public path, and requires the
provision to finish and publish intact.
@kunchenguid
kunchenguid merged commit ea7c7f7 into main Sep 26, 2026
19 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-remote-seed-clone-flake-r1 branch September 26, 2026 02:43
ashkonmousavi added a commit to ashkonmousavi/firstmate that referenced this pull request Sep 26, 2026