Repository navigation
fix(bin): require explicit per-home authority to retire secondmates in teardown - #4219
RooseveltAdvisors wants to merge 15 commits into
Conversation
c0a1108 to
963ccc3
Compare
A caller built a cleanup target list by matching worktree path suffix */firstmate. That suffix matches both a crewmate worktree of the firstmate project and a persistent secondmate home, because homes are laid out .treehouse/<...>/N/firstmate, and every idle seat passed the existing in-flight guard - an idle queue is a healthy second mate's normal state, not evidence it is finished. Roughly 17 standing second mates were retired in one unattended batch. The homes survived with charter, backlog, learnings, and clones intact, so recovery through the registry respawn path worked; that was luck, not a guarantee. Three refusals close the gap: - Per-target authority. A kind=secondmate teardown now requires --retire-secondmate <task-id> naming the exact home being retired, so a list a caller assembled cannot retire one as a side effect. --force does not substitute for it, because discarding work and choosing which home to retire are separate decisions. Offering the flag for any other kind also refuses, since that mismatch means the target was selected wrong. - Loop-shape refusal. Teardown acts on one target per invocation, and extra task ids are now refused before anything is locked, naming the count and any secondmates among them, so a mistaken selection list is caught while every seat is still alive. Previously a trailing id was silently ignored and the first target was torn down anyway. - Kind-scoped selection. bin/fm-fleet-view.sh --cleanup-candidates renders the existing fleet snapshot as a kind-labeled report - id, kind, persistent or disposable, and the teardown command that kind takes - so no caller has to infer persistence from a worktree path. This extends the existing fleet inventory owner rather than adding a new script. Every non-destructive path is unchanged: ordinary ship and scout teardowns take no new flag, and the landed-work, scout-report, captain-hold, public-followup, and forced-discard gates are untouched. The remote retirement path carries the authority through to the host-side cleanup of the same record. The first argument is collected as a target unconditionally before the option loop begins, so a task id that spells --force or --retire-secondmate stays tearable exactly as it was at the base commit.
…ter targets refuse as a batch A selection list whose later ids spell option names was read as flags: the multi-target refusal saw one target and proceeded, and a later --force could silently discard the first target's work. After --, every argument is a target, so the mistaken list reaches the refusal naming all of its ids; flag meanings before -- are unchanged.
963ccc3 to
ed9c890
Compare
…erial 4' check: tests/fm-teardown-endpoint-safety.test.sh failed its assertion 'the refusal did not name the child whose endpoint could not be closed'. Root cause: this PR (commit 644ed57) added a per-target retire guard so a kind=secondmate teardown now requires --retire-secondmate <task-id> naming that exact home, with --force explicitly not substituting (per the PR contract and review ruling). Commit da0173e updated one pre-existing forced-secondmate test to pass that authority (tests/fm-secondmate-safety.test.sh), but test_forced_secondmate_child_close_failure_still_refuses in tests/fm-teardown-endpoint-safety.test.sh was missed, so its `--force`-only invocation was correctly refused by the new guard before ever reaching the child endpoint close path it exists to exercise. Reproduced locally (the refusal was 'REFUSED: task mate-task is a persistent secondmate home...'), and fixed the test with the same pattern as da0173e: the teardown invocation now passes --retire-secondmate "$parent" alongside --force, with an updated comment explaining that the per-target authority is what reaches the forced path. No production code changed - the guard behaves exactly as specified. Verified: tests/fm-teardown-endpoint-safety.test.sh now passes all 25 assertions including 'fm-teardown: forced secondmate cleanup still refuses on a child endpoint close that failed'; sibling contract suites tests/fm-teardown.test.sh (90 ok) and tests/fm-secondmate-safety.test.sh (0 failures) also pass
…unchenguid#3657) Upstream: kunchenguid#3657 State: open Slug: retire-secondmate-authority Upstream PR kunchenguid#3657 (open); duplicate tracker kunchenguid#4219. Teardown --retire-secondmate implementation lives in the kunchenguid#4225 commit (shared bin/fm-teardown.sh); this commit carries the rest of the authority surface (fleet-view, remote control, docs, safety tests). House tracking: one commit ↔ one upstream PR. When this PR merges to origin/main, drop this commit from house main (rebase onto new origin/main or reset residue without this feature).
|
| def persistence($t): if $t.kind == "secondmate" then "persistent" else "disposable" end; | ||
| def teardown_for($t): | ||
| if $t.kind == "secondmate" then "retire only by an explicit decision naming this home - see .agents/skills/secondmate-provisioning" | ||
| else "bin/fm-teardown.sh \($t.id)" end; |
There was a problem hiding this comment.
Unknown kinds appear disposable
This report treats every kind other than the exact value secondmate as disposable and prints a runnable teardown command. The snapshot passes through non-empty, noncanonical kind values without validation, so a malformed or future kind would be presented as safe to remove instead of unknown. Please emit teardown commands only for known disposable kinds such as ship and scout, and fail closed for everything else.
| def persistence($t): if $t.kind == "secondmate" then "persistent" else "disposable" end; | |
| def teardown_for($t): | |
| if $t.kind == "secondmate" then "retire only by an explicit decision naming this home - see .agents/skills/secondmate-provisioning" | |
| else "bin/fm-teardown.sh \($t.id)" end; | |
| def persistence($t): | |
| if $t.kind == "secondmate" then "persistent" | |
| elif $t.kind == "ship" or $t.kind == "scout" then "disposable" | |
| else "unknown" end; | |
| def teardown_for($t): | |
| if $t.kind == "secondmate" then "retire only by an explicit decision naming this home - see .agents/skills/secondmate-provisioning" | |
| elif $t.kind == "ship" or $t.kind == "scout" then "bin/fm-teardown.sh \($t.id)" | |
| else "refuse cleanup until this task kind is understood" end; |
Knowledge Base Used: Secondmate coordination
…-teardown.sh (+119/-19 lines for the retire-secondmate authority and end-of-options parsing) pushed its ShellCheck analysis over fm-lint's per-root memory envelope. Evidence: the run's telemetry sidecar (artifact fm-lint-telemetry-1) records `end ... bin/fm-teardown.sh ... rc=251 reason=memory rss_kib=8388016`, and the job exits 251 after `shellcheck: out of memory`. Reproduced exactly: under the CI envelope (ulimit -v 12582912, `shellcheck --norc --external-sources`) the base-commit bin/fm-teardown.sh passes at 8,263,224 KiB RSS while the PR head fails with rc 251; head passes uncapped (8,448,828 KiB) and at 12.5/13 GiB caps - so the root needs just over the 12 GiB cap's ~8 GiB GHC heap, i.e. the envelope (not the script) is the shared boundary at fault. Invariant: every canonical root's full source-aware analysis must fit inside FM_LINT_ROOT_MEMORY_KIB so a required-bounds partition run completes; it must hold for all 451 roots in both partitions under CI's FM_LINT_REQUIRE_BOUNDS=1. Fix at that one shared boundary: bin/fm-lint.sh default FM_LINT_ROOT_MEMORY_KIB 12582912 -> 14680064 (14 GiB, following this file's documented precedent of raising the wall when a root outgrows it, e.g. 8 -> 12 GiB) with the sizing rationale updated to the measured ~8.4 GiB resident peak, plus the roots-sidecar contract value updated in tests/fm-lint.test.sh:1697. Verification: bounded single-root run of bin/fm-teardown.sh now rc=0 (sidecar records 14680064, result_exit 0); full CI-parity local runs of `FM_LINT_REQUIRE_BOUNDS=1 FM_LINT_JOBS=1 bin/fm-lint.sh --partition 1of2` (rc=0, 226/226 roots ok) and `--partition 2of2` (rc=0, 225/225 ok) covering all 451 canonical roots with zero abnormal ends, backend-purity clean and actionlint validating 3 workflow files; `tests/fm-lint.test.sh` passes end to end. No other check, doc, or config pins the old constant. Only ci-1 was addressed; the declined round-1 findings and the unselected Greptile P2 were left untouched as instructed
…-delta-read.test.sh: 'not ok - no attempt landed the rewrite in the same ctime second' (job 110751921321, run 36979934096, exit=1 at 07:57:36, the shard's only failed=1). The test is not in the PR diff: it landed on main via kunchenguid#6363 (65e2aa4) and reaches this PR only through the pull_request merge ref, which is also why it appears in shard 4 (after merging origin/main locally, bin/fm-test-run.sh --list --lane portable-serial-4of9 reproduces CI's exact 25-test order). It is a real flake in that new test, not an infra/stale check: it fails ~80% of local runs on pure main content (4/5 and later 1/5 pre-fix), main's own run 36978723064 passed it, and an unrelated branch failed the same assertion in run 36979550661. Root cause, measured in-process: the retry loop aligns the first write to a second boundary with perl sleep(1-(time-int(time))) (wake lands at X.0000x), but the filesystem stamps inode mtime/ctime from the kernel's coarse timestamp clock, which trails the process clock by ~4ms (observed: write at now=X.003489 recorded mtime=X-1.999419), so the initial write is stamped in the previous whole second while the rewrite 0.15s later lands in the new one; every one of the 3 attempts repeats the same systematic race, so the retry never saves it (probe: before=...0555 while the wall clock already read ...0556.006 on every attempt). Invariant: for both same-second writes to compare equal, the first write's filesystem stamp must fall after the boundary in whole-second terms, i.e. the write must be issued past the coarse-clock lag; the only site with this boundary-aligned same-second pattern is this test's retry loop (grep 'sleep(1 - (time' and 'ctime_second' find no siblings), so the fix is that one write site: sleep 0.05 after the boundary wake and before the first printf, well past the measured ~5ms lag yet far short of the next boundary (first write ~0.05s, rewrite ~0.23s, still the same second; any genuine overrun is still handled by the existing BEFORE!=AFTER retry). The merge of origin/main (dd5a4a7) was required to ship this file: the branch pre-merge lacked it, so adding it fresh would have been an add/add conflict against main in the pull_request merge ref; the merge touched no PR-owned file (git diff 604042b HEAD intersects the PR's changed-file set in zero files) and CI already ran this exact merged content green for all other 24 shard-4 tests. Verification: tests/fm-remote-delta-read.test.sh passes 16/16 consecutive runs post-fix (pre-fix 4/5 failed), bash -n clean, shellcheck -x clean, bin/fm-lint.sh tests/fm-remote-delta-read.test.sh rc=0 with pinned ShellCheck 0.11.0 full dataflow; the declined round-1 findings and the unselected Greptile P2 remain untouched
…replies refusal tests
…ire-validation-r2 # Conflicts: # tests/fm-remote-delta-read.test.sh
Intent
Captain, via main: in the same pass as the 3682 rebase, check the other parked upstream PRs for drift from the 12-commit advance and rebase any that went conflicting. Force-push to OUR fork branch is authorized; CI re-greens; then the babysit continues.
Context to read that: firstmate ran the drift sweep. 3552, 3543 and 3417 are clean. This PR, 3657, went CONFLICTING - and it is the messier of the two conflicting ones.
What Changed
bin/fm-teardown.shnow refuses to retire akind=secondmatetask and changes nothing unless it gets--retire-secondmate <id>naming that exact home.--forcedoes not stand in for the flag. Teardown also refuses when the flag is passed for a non-secondmate task or names a different id. A request with more than one target is rejected before anything is locked, and the error names any secondmate homes in the list.bin/fm-remote-secondmate-control.shnow passes the flag on its own retire calls.bin/fm-fleet-view.shgains a--cleanup-candidatesmode. It lists each live task with its kind and whether it is persistent or disposable. It prints a runnablefm-teardown.shcommand only for disposable tasks. Secondmate homes get a pointer to the retirement contract instead.bin/fm-lint.shgoes from 12 GiB to 14 GiB.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The merge with main left main's 12-commit content intact and touched no file this PR owns. The new teardown logic only adds refusals, and they all fire before anything destructive runs: a secondmate home now needs per-target authority, and more than one target is refused. Every in-repo caller that tears down a secondmate (fm-remote-secondmate-control.sh and the affected tests) passes the flag naming that exact home. The fleet-view cleanup report is read-only, and the lint memory cap goes up from 12 GiB to 14 GiB, documented with measured numbers.
Testing
I ran the real teardown and fleet-view scripts against a throwaway lab home made with
bin/fm-lab-home.sh, seeded with one secondmate record and one ship record, then deleted the lab. The new report labels each task's kind and gives no runnable command for the persistent home. A secondmate teardown with no flag, with only--force, with the flag naming another task, or with the flag missing its value is refused and nothing changes. A two-target call is refused and names the secondmate. Arguments after--are read as targets, not options, so-- --forceis refused as a two-target call. Putting the flag on a ship task is refused. The correctly authorized retirement removed the home, the record and its report row. The plain ship teardown got past the new check and then stopped because my fixture worktree isn't managed by treehouse, so its full cleanup is untested live and rests on the suite tests. Of five targeted suites, fleet-snapshot-view and secondmate-lifecycle-e2e finished with rc=0. teardown, secondmate-safety and teardown-endpoint-safety were still running at my last check, with no failing case so far. This is a shell tool, so there is no visual surface; the CLI transcripts are the evidence.treehouse returnbecause the lab worktree isn't managed by treehouse. Creating a…Evidence: Live refusal scenarios transcript (S1-S7)
Source: Live refusal scenarios transcript (S1-S7)
Evidence: Ordinary ship teardown (stopped at treehouse return) and first retirement attempt (stopped by the home-location check)
Source: Ordinary ship teardown (stopped at treehouse return) and first retirement attempt (stopped by the home-location check)
Evidence: Authorized secondmate retirement and cleanup-candidates afterwards
Source: Authorized secondmate retirement and cleanup-candidates afterwards
Evidence: fm-teardown suite log (still running at last check)
Source: fm-teardown suite log (still running at last check)
Evidence: fm-secondmate-safety suite log (still running at last check)
Source: fm-secondmate-safety suite log (still running at last check)
Evidence: fm-fleet-snapshot-view suite log
Source: fm-fleet-snapshot-view suite log
Evidence: fm-secondmate-lifecycle-e2e suite log
Source: fm-secondmate-lifecycle-e2e suite log
Evidence: fm-teardown-endpoint-safety suite log (still running at last check)
Source: fm-teardown-endpoint-safety suite log (still running at last check)
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.
treehouse returnbecause the lab worktree isn't managed by treehouse. Creating a…bin/fm-lab-home.sh create $LAB, then seeded one secondmate record (mate-a) and one ship record (crew-b) with a real git worktreeFM_HOME=$LAB bin/fm-fleet-view.sh --cleanup-candidates(before and after retirement)FM_HOME=$LAB bin/fm-teardown.sh mate-a(no authority flag)FM_HOME=$LAB bin/fm-teardown.sh mate-a --forceFM_HOME=$LAB bin/fm-teardown.sh mate-a --retire-secondmate crew-bFM_HOME=$LAB bin/fm-teardown.sh mate-a --retire-secondmate(flag with no value)FM_HOME=$LAB bin/fm-teardown.sh crew-b mate-aFM_HOME=$LAB bin/fm-teardown.sh crew-b -- --forceFM_HOME=$LAB bin/fm-teardown.sh crew-b --retire-secondmate crew-bFM_HOME=$LAB bin/fm-teardown.sh crew-bFM_HOME=$LAB bin/fm-teardown.sh mate-a --retire-secondmate mate-a(home moved outside FM_HOME)bash tests/fm-teardown.test.shbash tests/fm-secondmate-safety.test.shbash tests/fm-fleet-snapshot-view.test.shbash tests/fm-secondmate-lifecycle-e2e.test.shbash tests/fm-teardown-endpoint-safety.test.shrm -rf $LABlab teardown✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.