Repository navigation
fix(bin): require per-target authority to retire a secondmate home - #3657
RooseveltAdvisors wants to merge 5 commits into
Conversation
The PR is not yet safe to merge because a later option-shaped task ID can still bypass the multi-target refusal and cause the first task to be torn down with unintended flags. Findings
|
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
|
Two notes for reviewers that belong with this PR rather than in its description. What the new refusals change for existing operator workflows. This PR is not purely additive, and the behaviour change is deliberate rather than incidental. Three invocations that used to work now refuse:
Ordinary A process disclosure about how this branch was validated. While iterating locally I stopped one of my own background test runs with a broad For completeness on the test evidence: the local test step was accepted over eight pre-existing suite failures on that box. Six of them fail with byte-identical messages on unmodified upstream |
9c85b73 to
6eea34b
Compare
6eea34b to
08145cc
Compare
|
Speaking as Kun's firstmate: First stamp on #3657 this fetch (HEAD Contract-class: restore. Retiring a persistent secondmate home now requires per-target authority ( Attestation: MATCH ( VISION verdict (aligns as restore):
Security: clean on reviewed surface. Overlap: Stamp outcome: waiting-author (conflicts). Resolve against main and re-push; do not merge while DIRTY. Not waiting-captain. |
|
Responding to the three inline P1 findings on |
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.
ba9a08b to
f99f09a
Compare
|
Rebased onto main ( Current check state on 904584c: all green except two, neither in this PR's diff:
Happy to help with a shard rebalance if useful, but leaving that decision to you. |
…tire-guard # Conflicts: # docs/scripts.md
| --force) FORCE=--force ;; | ||
| --legacy-record) LEGACY_RECORD_GIVEN=1 ;; | ||
| *) | ||
| echo "error: invalid teardown request" >&2 | ||
| exit 2 | ||
| --retire-secondmate) | ||
| shift |
There was a problem hiding this comment.
Option-shaped targets bypass refusal
When a cleanup list contains a valid later task ID such as --force or --legacy-record, this parser consumes that ID as a flag instead of recording a second target. The multi-target check therefore sees only one target and proceeds with its teardown; --force can additionally discard that first target's work instead of refusing the mistaken list.
…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.
|
Fixed on the head now (58f4fb3): the parser takes a |
| --force) FORCE=--force ;; | ||
| --legacy-record) LEGACY_RECORD_GIVEN=1 ;; | ||
| --retire-secondmate) | ||
| shift | ||
| [ "$#" -gt 0 ] || { | ||
| echo "error: --retire-secondmate needs the exact task id it authorizes" >&2 | ||
| exit 2 | ||
| } | ||
| RETIRE_AUTH=$1 | ||
| RETIRE_AUTH_GIVEN=1 | ||
| ;; | ||
| --retire-secondmate=*) | ||
| RETIRE_AUTH=${1#*=} | ||
| RETIRE_AUTH_GIVEN=1 | ||
| ;; |
There was a problem hiding this comment.
Option-shaped targets bypass refusal
When a mistaken multi-target invocation such as fm-teardown.sh task-x1 --force uses a valid option-shaped ID as the later target, the parser consumes that ID as a flag instead of adding it to TEARDOWN_TARGETS. The target count remains one, so teardown bypasses the multi-target refusal and force-discards the first task's work while silently ignoring the intended second target.
|
On the remaining inline finding at the option branch: What this PR changes is the unambiguous path for the mistaken-list case: the first argument is always a target, genuinely multi-target lists now refuse before any change, and as of 58f4fb3 a |
…id#4225) Upstream: kunchenguid#4225 State: open Slug: stale-sweep-capacity Upstream PR kunchenguid#4225 (open); supersedes closed kunchenguid#3720. Also sibling kunchenguid#4224. Includes bin/fm-spawn.sh and bin/fm-captain-hold.sh full house delta (capacity + kunchenguid#3712 actor bits + kunchenguid#3458 label bits) and bin/fm-teardown.sh full house delta (capacity release + kunchenguid#3657 retire-secondmate authority), because those files are not cleanly separable at tip. 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).
…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).
Intent
The developer (acting on a captain's order to "push firstmate to close all gaps now") needed two firstmate shell tools fixed so that two leftover records in the main home could finally be closed honestly, because both tools still assumed the pre-Beads markdown world. First, bin/fm-captain-hold.sh's
completepath re-read a scout report's attested legacy hold ids and looked them up by grepping data/backlog.md, so on a Beads-backend home whose holds had been migrated to fm- prefixed ids it failed with an empty-name message ("captain-held task is absent from data/backlog.md") and the scout todo-md-verify-ingest-20260830 could never pass its completion gate; the fix had to resolve ids through the configured backend, accept a migrated row via the exact "migrated from data/backlog.md id " note or the legacy id under the configured prefix, name the unresolved id in any refusal, and keep the markdown path working. Second, bin/fm-teardown.sh refused to tear down task portal-insurance-path-owner because its record predates spawn_gen, so a finished, clean, superseded worktree could never be cleaned; teardown had to accept such a record behind an explicit --legacy-record flag only when the endpoint is dead or agent-less and the worktree passes the ordinary landed test, log the accepted incarnation, and never relax the unlanded-work refusal. The developer also required colocated behavior tests for both (Beads fixture home plus a legacy meta fixture without spawn_gen) that stay CI-portable by self-skipping when only markdown-capable tooling is installed, and required the change to be validated through the no-mistakes pipeline with every gate answered explicitly (never --yes), escalating ask-user findings rather than self-answering them.What Changed
bin/fm-teardown.shnow refuses akind=secondmateteardown unless--retire-secondmate <task-id>names the exact target, refuses the flag on any other kind as a mis-selected target, and does not accept--forceas a substitute; argument parsing was reworked so the first positional argument is always the target (ids that spell an option stay reachable), extra targets are refused before the lock while naming the count and any secondmates among them, andbin/fm-remote-secondmate-control.shpasses the new authority on both its retire paths.bin/fm-fleet-view.shgained--cleanup-candidates, rendering the snapshot as a kind-labeled table of live tasks with a persistent/disposable column; disposable rows carry their runnablefm-teardown.shcommand while a secondmate home carries a pointer to the retirement contract instead, so the report cannot be piped to a shell to retire standing homes.AGENTS.md,CONTRIBUTING.md,docs/architecture.md,docs/remote-secondmates.md,docs/scripts.md, and thesecondmate-provisioningskill.Risk Assessment
✅ Low: The change is a well-bounded, fail-closed CLI hardening: the authority check reads the target's own recorded kind before any destructive step, every unrecognized-argument path refuses rather than proceeding, the sole production caller (bin/fm-remote-secondmate-control.sh) and every in-repo test call site on a kind=secondmate record were updated, and the pipeline fix round made the minimal report change the ruling asked for without weakening the guard.
Testing
Completed 1 recorded test check.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 3 issues found → auto-fixed ✅
bin/fm-fleet-view.sh:47- The--retire-secondmate <id>token carries no information beyond the target id it must equal, and the report designated as the sanctioned source of cleanup targets prints the complete pre-authorized retirement command for every persistent home (bin/fm-teardown.sh <id> --retire-secondmate <id>). Concrete path: an operator or agent runsbin/fm-fleet-view.sh --cleanup-candidates, takes theTeardown commandcolumn, and pipes it to a shell — every standing secondmate is retired, one invocation each, with the one-target rule satisfied and no refusal fired. That weakens the invariant asserted at AGENTS.md:391 ("a selection list can never retire a standing second mate as a side effect") and .agents/skills/secondmate-provisioning/SKILL.md:243 ("a cleanup list a caller assembled cannot retire standing homes as a side effect"). The guard does genuinely block the failure it was built for — an unlabeled path-globbed or pane-swept list, since a path suffix yields no--retire-secondmatetoken — so this is not a defect in the code as written; it is a question about whether the claimed invariant should be narrowed to that case, or whether the report should stop emitting the authority token for persistent rows (e.g. print the kind and a pointer to the retirement contract instead of a runnable command). Flagging the remedy, not the defect: either narrowing the documented claim or changing what the report emits is a product-behavior decision belonging to the author, not a mechanical fix.tests/fm-teardown.test.sh:3577-! grep -q 'unknown teardown option' "$case_dir/stderr"asserts against a stringbin/fm-teardown.shnever emits. The parser's only failure messages areerror: invalid teardown request(bin/fm-teardown.sh:270,277) and the multi-target refusal (bin/fm-teardown.sh:293), so this guard cannot fail no matter how the parser regresses. The regression it is meant to catch — a dash-leading id being consumed as an option — is already covered by the surroundingexpect_code 0andassert_absent .../state/$dash_id.metaassertions in the same loop, which are genuinely behavioral. Either drop the dead grep or point it at the message the code would actually produce if--forcewere parsed as a flag rather than a target (invalid teardown request).bin/fm-teardown.sh:267- The catch-all now reclassifies any unrecognized option as an extra target, so a typo'd flag produces a misdirecting diagnostic:bin/fm-teardown.sh task-x1 --dry-runexits 2 with "teardown acts on exactly one task, but 2 targets were given: task-x1 --dry-run" and advises listing candidates with--cleanup-candidates, instead of naming the unknown flag as the previous parser did. This still fails closed (no invocation can silently succeed with a swallowed flag, because the first argument is already consumed as the target, so any extra token forces the multi-target refusal), and the author documented the tradeoff inline:fm_task_id_path_safe(bin/fm-pr-lib.sh:97) permits dash-leading ids, so an id spelling an option name must remain reachable. Noting the diagnostic cost of that deliberate choice; no action needed.🔧 Fix: stop printing runnable retirement command in cleanup report
✅ Re-checked - no issues remain.
bin/fm-test-run.sh --changed --exclude-family real-herdr-gated✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.