Repository navigation
fix(bin): harden operational safety checks - #67
Merged
Merged
Conversation
…chenguid#1847) fm_secondmate_parent_record_parse read the .fm-secondmate-parent record with bash's read, which drops NUL bytes - and different bash generations disagree on the result: 3.2 truncates the value at the NUL while 5.x splices the surrounding bytes together. A NUL-bearing parent_home could therefore resolve to a home the record's bytes never name contiguously, and which home fm-teardown.sh's promised-public-reply resolution read (registration, registry, relay state) - or whether that protection engaged at all - depended on which interpreter ran the cleanup. Reproduced end to end: the same NUL-bearing record cleaned up under bash 5.x by resolving the spliced-together registered parent, while bash 3.2 refused it as unresolved, and a literal truncated path refused under both. Reject any NUL byte in the record before field parsing, putting corrupt records in the same fail-closed bucket as duplicate fields, malformed local bindings, unsupported routes, and symlinked records. The regression test drives the real bin/fm-teardown.sh over the proven clean-cleanup fixture with a NUL spliced mid-path into the recorded parent_home, so before the fix it reproduced the wrong-home cleanup and now it must refuse with the explicit binding refusal. (cherry picked from commit 4cdd0bd)
…2849) * fix(bin): require a clone root before fleet-sync touches a project Git repository discovery walks upward, so `git -C projects/<dir>` on a plain directory nested under projects/ resolves to the enclosing repository - in a firstmate home, the firstmate checkout itself. fm-fleet-sync.sh guarded its candidates with `rev-parse --is-inside-work-tree`, which such a directory passes, so every later git call read, pruned and fast-forwarded firstmate's own default branch and reported it under the project directory's label. A running session's AGENTS.md changed underneath it, and the report named a project that had nothing to do with the change. Require each candidate to be the root of its own work tree before any other git command: compare `rev-parse --show-toplevel` against the directory's own physical path. Both sides are physical, so a symlinked clone still compares equal. Anything else is skipped by name, naming the repository that would have been touched, and bootstrap relays that as a FLEET_SYNC line. Regression coverage reproduces the wrong-repo fast-forward against a home nested inside another repository, in both the whole-fleet and single-project forms, and pins that a symlinked clone dir still syncs. * no-mistakes(review): Keep enclosing fixture clean during clone-root regression (cherry picked from commit 801c083)
… gate (kunchenguid#2838) The unguarded Herdr declaration quoted `{TASK}` in its own prose while the scaffold instructs firstmate to replace every `{TASK}` placeholder. The documented global replace therefore spliced the whole task body into the middle of the safety gate's sentence, silently destroying the one contract that exists precisely because the scaffold cannot inspect the task text. Reword the gate to refer to the task text filled in above, leaving the placeholder only at its genuine fill site. Rewording rather than renaming the token keeps the unfilled-charter guards in fm-home-seed.sh and fm-remote-home-seed.sh working unchanged. Add a regression test that performs the documented global fill on ship and scout scaffolds and asserts the body lands once and the gate survives. (cherry picked from commit 86dd2f6)
…tat form (kunchenguid#2837) The writer lock's stale-lock branch read the lock's mtime with `stat -f %m ... || stat -c %Y ...`. On GNU coreutils `-f` is filesystem stat, so it consumed the format string as a path, complained on stderr, printed a partial filesystem dump (" File: ...") on stdout, and still exited 0. The GNU form in the fallback therefore never ran, and the following arithmetic evaluated the word `File`, aborting the writer under `set -u` with "File: unbound variable". fm-teardown.sh died there after returning the worktree, leaving state/<id>.meta, .status, .busy-gen, .busy-state, .busy-state.lock/ and .turn-ended behind. The surviving metadata kept the watcher monitoring an endpoint whose agent was gone, so a finished task produced stale wakes forever, and every re-run died identically because the abandoned lock was never broken. Detect the platform once and pick the right stat form, the pattern bin/fm-watch.sh already documents, and treat any non-numeric result as "just created" so a future portability surprise degrades to a lock-timeout refusal rather than killing teardown mid-way. (cherry picked from commit 266fdb9)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Port four upstream Firstmate safety fixes confirmed to apply cleanly to this fork's HEAD as fork-native changes: kunchenguid#1847 (4cdd0bd), fail closed on NUL bytes in durable secondmate parent bindings; kunchenguid#2849 (801c083), require a real project clone root during fleet sync so git -C cannot walk upward into the Firstmate checkout; kunchenguid#2838 (86dd2f6), prevent documented global {TASK} replacement from corrupting the hard Herdr safety gate; and kunchenguid#2837 (266fdb9), use the platform-native stat form for busy-lock mtime to avoid false stale state and teardown refusal. Preserve each upstream PR's intent and add or extend a passing behavioral regression for every fix. Do not perform the large upstream merge, do not change ancestry, do not introduce bin/fm-control.sh, and adapt any non-clean hunk to the fork's equivalent code rather than forcing it. Keep the upstream remote read-only for source inspection. Follow firstmate-coding-guidelines for shared tracked material. Open the PR on dnth/firstmate only, never kunchenguid/firstmate, and complete the full No-Mistakes pipeline through green CI. The resulting branch must contain only these four safety ports and their tests, with no ancestry rewrite or control-plane addition.
Firstmate-Validation-Generation: 2e5d9dc7ce57eed6f80f40a510580599
What Changed
{TASK}replacement and use platform-nativestatsyntax for busy-lock expiry.Risk Assessment
✅ Low: The four linear, well-bounded safety ports satisfy the authoritative intent, preserve the required invariants, and include behavioral regressions without introducing material source risk.
Testing
Brief, busy-state, and public-followup suites passed, and the three new fleet-sync regressions passed in isolation with direct CLI evidence for all four safety behaviors. The complete fleet-sync file was also attempted but stopped at an earlier unrelated packed-refs fixture because this environment’s Git accepted the planted lock and fetched successfully; the changed clone-root cases were therefore exercised separately. Scope checks found exactly four intended commits, no control-plane addition, and no testing residue in the worktree.
Evidence: NUL parent-binding teardown refusal
Evidence: Fleet-sync clone-root refusal and unchanged enclosing HEAD
Evidence: Herdr gate after documented global task replacement
Evidence: GNU-stat stale-lock retirement state
Evidence: Isolated fleet-sync clone-root regressions
Evidence: Brief regression suite
Evidence: Busy-state regression suite
Evidence: Public-followup and teardown regression suite
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.
tests/fm-brief.test.shtests/fm-busy-state.test.shtests/fm-public-followup.test.shIsolatedtest_non_clone_dir_never_syncs_the_enclosing_repo,test_non_clone_dir_named_directly_never_syncs_the_enclosing_repo, andtest_symlinked_clone_still_syncsfromtests/fm-fleet-sync.test.shGenerated a real brief withbin/fm-brief.sh, globally replaced{TASK}, and recorded the rendered Herdr gate plus occurrence countsInvokedbin/fm-busy-event.sh arm/retirewith deterministic Linux/GNU-stat shims and recorded pre/post persisted state and idempotent retryInvokedbin/fm-fleet-sync.shin whole-fleet and single-project forms against a nested non-clone, recording the refusal and identical enclosing HEAD hashesExecuted teardown with a NUL-bearing durable secondmate parent record, recording the explicit refusal and preserved child metadatagit diff --name-only 23dbd0fe36cde3a33f931d1a688b984362b385a3..53e5f6b498953b0c80a78d332cd09632e6fb6129,git rev-list --count ...,test ! -e bin/fm-control.sh, andgit status --short✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.