Skip to content

feat: permit gate lifecycle calls against disposable lab homes - #5635

Merged
kunchenguid merged 6 commits into
mainfrom
fm/fm-gate-lab-refusal-min-r1
Sep 25, 2026
Merged

kunchenguid merged 6 commits into
mainfrom
fm/fm-gate-lab-refusal-min-r1

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

holy shit how did 5615 become 1700+ lines of changes?

ok do A

Context: #5615 (1,714 added / 203 removed lines across 31 files) implemented two authorized fixes that let the no-mistakes pipeline live-validate Firstmate changes: fix 1, a test-only harness seam plus a per-harness lab primary recipe; fix 2, scoping the gate refusal so a gate agent may drive lifecycle only against a disposable lab home. It will not be merged. Option A, as described when chosen, splits it:

  1. A new small PR with fix 1 only (the FM_TEST_SEAM/FM_TEST_HARNESS test seam in fm-afk-launch.sh, the FM_TEST_SEAM export in tests/lib.sh, the per-harness lab primary recipe in .no-mistakes.yaml reworded to NOT depend on bin/fm-lab-home.sh - e.g. a plain mktemp lab dir), plus the two genuine flaky-test fixes (fm-wake-queue watcher-fixture leg cleanup, fm-remote-secondmate-lifecycle lock-acquisition wait). Target well under 100 lines. Keep the existing gate refusal and its FM_GATE_REFUSE_BYPASS behavior unchanged in this PR.
  2. Fix 2 reworked from scratch as its own PR, minimal: the goal stays 'a gate agent can drive lifecycle only against a disposable lab home, not the real fleet', but find the smallest mechanism that does it (e.g. one marker only the lab helper writes, checked by the refusal, plus a few behavioral tests). Deliberate forgery by a hostile gate agent is out of scope; the threat is a confused agent touching the real fleet. Size budget: a couple hundred lines including tests; if it genuinely cannot fit, stop and report why before building more. Do not carry over the symlink/binding/descendant-home/herdr-session machinery from fix: enable isolated live validation in no-mistakes gates #5615 unless a concrete confused-agent case needs it.

What Changed

  • Add fm-lab-home.sh to mint marked, disposable Firstmate homes; gate lifecycle calls remain refused unless they use a marked home without FM_*_OVERRIDE relocations.
  • Fix teardown’s slot-ownership check for homes reached through symlinks while preserving refusal for a second task record linked to the same file.
  • Document the lab-home boundary and add behavioral coverage for admission, refusal, and teardown.

Risk Assessment

✅ Low: The lab-home exception is bounded by a fresh-home marker and stock-layout check, and the changed teardown identity check preserves distinct task-record claims; no material source-backed issue was found.

Testing

The two targeted test scripts passed. Live CLI checks showed that a marked home reaches task lookup, an unmarked or override-relocated home is refused, and populated or previously marked directories cannot be minted again. The CLI transcript was saved as evidence; transient worktree data was removed. Real Treehouse pool teardown was not driven live.

  • Live validation: ✅ go - 3 of 5 scenarios driven live against the product
Scenario Result Live Evidence
A gate agent targets a marked disposable home and reaches ordinary task lookup ✅ pass live Live gate and lab-home CLI transcript: send and teardown report missing task records rather than gate refusal.
A gate agent targets an unmarked home or relocates a marked home's state and is refused ✅ pass live Live gate and lab-home CLI transcript: both send attempts exit 3.
An operator tries to mint a populated, newline-entry, or previously marked home and creation refuses ✅ pass live Live gate and lab-home CLI transcript: each create attempt fails; refused unmarked homes remain unmarked.
Teardown finds a distinct hardlinked task record claiming the same pool slot and preserves the slot ⏸️ untested no No provisioned disposable real Treehouse pool and live task endpoint were available for a destructive live teardown; provide those in an isolated lab to drive this case live.
Teardown reaches its own record through an alternate home spelling without a false collision ⏸️ untested no No provisioned disposable real Treehouse pool and live task endpoint were available; provide those in an isolated lab to drive this case live.
Evidence: Live gate and lab-home CLI transcript

Source: Live gate and lab-home CLI transcript

=== create fresh disposable home ===
./.gate-live.Clop7W/lab
status=0
=== gate send against marked home (missing task, reaches task lookup) ===
fm-gate-refuse: gate agent lifecycle permitted only against lab home ./.gate-live.Clop7W/lab
error: target 'missing-task' is not resolvable (tried meta=./.gate-live.Clop7W/lab/state/missing-task.meta; metadata window/terminal lookup; backend=none). Use fm-missing-task for a recorded task/lane, or pass a well-formed explicit backend target such as session:window.
status=1
=== gate teardown against marked home (missing task, reaches task lookup) ===
fm-gate-refuse: gate agent lifecycle permitted only against lab home ./.gate-live.Clop7W/lab
error: teardown refused: task record is not a regular file at ./.gate-live.Clop7W/lab/state/missing-task.meta
status=1
=== gate send against unmarked home ===
error: no-mistakes gate agent must not drive the fleet (NO_MISTAKES_GATE set)
status=3
=== gate send against marked home with relocated state ===
error: no-mistakes gate agent must not drive the fleet (NO_MISTAKES_GATE set)
status=3
=== try marking populated home (must leave marker absent) ===
fm-lab-home: refusing './.gate-live.Clop7W/real': a lab marker is only ever stamped on a fresh empty dir
status=1
marker_absent=0
=== try marking newline-named entry (must leave marker absent) ===
fm-lab-home: refusing './.gate-live.Clop7W/newline': a lab marker is only ever stamped on a fresh empty dir
status=1
marker_absent=0
=== try remint existing lab (must refuse) ===
fm-lab-home: refusing './.gate-live.Clop7W/lab': a lab marker is only ever stamped on a fresh empty dir
status=1

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
A gate agent targets a marked disposable home and reaches ordinary task lookup ✅ pass live Live gate and lab-home CLI transcript: send and teardown report missing task records rather than gate refusal.
A gate agent targets an unmarked home or relocates a marked home's state and is refused ✅ pass live Live gate and lab-home CLI transcript: both send attempts exit 3.
An operator tries to mint a populated, newline-entry, or previously marked home and creation refuses ✅ pass live Live gate and lab-home CLI transcript: each create attempt fails; refused unmarked homes remain unmarked.
Teardown finds a distinct hardlinked task record claiming the same pool slot and preserves the slot ⏸️ untested no No provisioned disposable real Treehouse pool and live task endpoint were available for a destructive live teardown; provide those in an isolated lab to drive this case live.
Teardown reaches its own record through an alternate home spelling without a false collision ⏸️ untested no No provisioned disposable real Treehouse pool and live task endpoint were available; provide those in an isolated lab to drive this case live.
  • tests/fm-gate-refuse.test.sh
  • tests/fm-teardown-endpoint-safety.test.sh
  • Manually ran bin/fm-lab-home.sh create, bin/fm-send.sh, and bin/fm-teardown.sh with isolated homes and NO_MISTAKES_GATE=1.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Part 2 of the #5615 split. A no-mistakes gate agent runs inside a
checkout carrying the fleet-captain identity, so fm-gate-refuse-lib
refuses fleet mutation on the gate signal. That refusal was absolute,
which kept gate validation from ever exercising the real lifecycle.

Stamp a disposable lab FM_HOME with a .fm-lab-home marker file that
only bin/fm-lab-home.sh writes, and only onto a fresh empty dir, so
no call path can mark a populated real home. fm_refuse_if_gate_agent
then permits lifecycle only when FM_HOME carries the marker and is
driven through its stock layout - any FM_*_OVERRIDE relocation stays
refused so part of the "lab" cannot be split back onto the real fleet.
The threat model is a confused agent touching the real fleet, not
deliberate forgery, so the marker is a plain token file rather than a
bound record. FM_GATE_REFUSE_BYPASS is unchanged: it still serves the
test harness, which cannot mark hundreds of temp homes.

Teardown's slot-ownership scan compared state-dir paths textually
while fm_firstmate_root_home canonicalizes, so a lab home under a
symlinked TMPDIR scanned its own record twice and self-collided;
compare file identity (-ef) instead.
@kunchenguid
kunchenguid merged commit ca8c293 into main Sep 25, 2026
19 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-gate-lab-refusal-min-r1 branch September 25, 2026 06:05
mituso89 pushed a commit to mituso89/firstmate that referenced this pull request Sep 26, 2026
…enguid#5635)

* fix(bin): let gate agents drive lifecycle against marked lab homes

Part 2 of the kunchenguid#5615 split. A no-mistakes gate agent runs inside a
checkout carrying the fleet-captain identity, so fm-gate-refuse-lib
refuses fleet mutation on the gate signal. That refusal was absolute,
which kept gate validation from ever exercising the real lifecycle.

Stamp a disposable lab FM_HOME with a .fm-lab-home marker file that
only bin/fm-lab-home.sh writes, and only onto a fresh empty dir, so
no call path can mark a populated real home. fm_refuse_if_gate_agent
then permits lifecycle only when FM_HOME carries the marker and is
driven through its stock layout - any FM_*_OVERRIDE relocation stays
refused so part of the "lab" cannot be split back onto the real fleet.
The threat model is a confused agent touching the real fleet, not
deliberate forgery, so the marker is a plain token file rather than a
bound record. FM_GATE_REFUSE_BYPASS is unchanged: it still serves the
test harness, which cannot mark hundreds of temp homes.

Teardown's slot-ownership scan compared state-dir paths textually
while fm_firstmate_root_home canonicalizes, so a lab home under a
symlinked TMPDIR scanned its own record twice and self-collided;
compare file identity (-ef) instead.

* no-mistakes(review): Refuse unlistable lab homes and hardlinked slot records

* no-mistakes(review): Mint lab markers only on verified-empty fresh dirs

* no-mistakes(document): Clarify lab-home gate documentation and comment contracts

* no-mistakes(document): Clarify lab-home gate documentation and remove stale claims

* no-mistakes(document): Clarify gate lab-home documentation and boundary wording
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 26, 2026
…enguid#5635)

* fix(bin): let gate agents drive lifecycle against marked lab homes

Part 2 of the kunchenguid#5615 split. A no-mistakes gate agent runs inside a
checkout carrying the fleet-captain identity, so fm-gate-refuse-lib
refuses fleet mutation on the gate signal. That refusal was absolute,
which kept gate validation from ever exercising the real lifecycle.

Stamp a disposable lab FM_HOME with a .fm-lab-home marker file that
only bin/fm-lab-home.sh writes, and only onto a fresh empty dir, so
no call path can mark a populated real home. fm_refuse_if_gate_agent
then permits lifecycle only when FM_HOME carries the marker and is
driven through its stock layout - any FM_*_OVERRIDE relocation stays
refused so part of the "lab" cannot be split back onto the real fleet.
The threat model is a confused agent touching the real fleet, not
deliberate forgery, so the marker is a plain token file rather than a
bound record. FM_GATE_REFUSE_BYPASS is unchanged: it still serves the
test harness, which cannot mark hundreds of temp homes.

Teardown's slot-ownership scan compared state-dir paths textually
while fm_firstmate_root_home canonicalizes, so a lab home under a
symlinked TMPDIR scanned its own record twice and self-collided;
compare file identity (-ef) instead.

* no-mistakes(review): Refuse unlistable lab homes and hardlinked slot records

* no-mistakes(review): Mint lab markers only on verified-empty fresh dirs

* no-mistakes(document): Clarify lab-home gate documentation and comment contracts

* no-mistakes(document): Clarify lab-home gate documentation and remove stale claims

* no-mistakes(document): Clarify gate lab-home documentation and boundary wording
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 26, 2026
…enguid#5635)

* fix(bin): let gate agents drive lifecycle against marked lab homes

Part 2 of the kunchenguid#5615 split. A no-mistakes gate agent runs inside a
checkout carrying the fleet-captain identity, so fm-gate-refuse-lib
refuses fleet mutation on the gate signal. That refusal was absolute,
which kept gate validation from ever exercising the real lifecycle.

Stamp a disposable lab FM_HOME with a .fm-lab-home marker file that
only bin/fm-lab-home.sh writes, and only onto a fresh empty dir, so
no call path can mark a populated real home. fm_refuse_if_gate_agent
then permits lifecycle only when FM_HOME carries the marker and is
driven through its stock layout - any FM_*_OVERRIDE relocation stays
refused so part of the "lab" cannot be split back onto the real fleet.
The threat model is a confused agent touching the real fleet, not
deliberate forgery, so the marker is a plain token file rather than a
bound record. FM_GATE_REFUSE_BYPASS is unchanged: it still serves the
test harness, which cannot mark hundreds of temp homes.

Teardown's slot-ownership scan compared state-dir paths textually
while fm_firstmate_root_home canonicalizes, so a lab home under a
symlinked TMPDIR scanned its own record twice and self-collided;
compare file identity (-ef) instead.

* no-mistakes(review): Refuse unlistable lab homes and hardlinked slot records

* no-mistakes(review): Mint lab markers only on verified-empty fresh dirs

* no-mistakes(document): Clarify lab-home gate documentation and comment contracts

* no-mistakes(document): Clarify lab-home gate documentation and remove stale claims

* no-mistakes(document): Clarify gate lab-home documentation and boundary wording
ashkonmousavi added a commit to ashkonmousavi/firstmate that referenced this pull request Sep 26, 2026