Skip to content

feat(bin): add opt-in advisory lane placement with fm-place.sh - #7595

Open
Moshik21 wants to merge 3 commits into
kunchenguid:mainfrom
Moshik21:fm/router-p1-pr-b-2
Open

Moshik21 wants to merge 3 commits into
kunchenguid:mainfrom
Moshik21:fm/router-p1-pr-b-2

Conversation

@Moshik21

@Moshik21 Moshik21 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Intent

A firstmate with several homes (main plus secondmates, local or remote) has no help deciding which home should take a new lane. Each home already publishes its own capacity facts (open lanes, pressure, disk) through fm-capacity.sh, but the choice among homes is still made by eye, with nothing that weighs a home's pressure, headroom or project clone against the task.

bin/fm-place.sh reads those published facts and advises a home. It is opt-in (config/lane-placement.json with "mode": "advise"), only advises, and never spawns, routes or sends. A home the operator names always wins.

This PR was rebased onto current main now that the capacity-facts change (#6983) has landed, so the diff covers only this placement layer.

What Changed

  • Added bin/fm-place.sh, an opt-in advisory script that ranks candidate homes for a new lane from each home's published state/lane-capacity.json facts. It is enabled by config/lane-placement.json with "mode": "advise", and off otherwise (FM_PLACE=off, absent config, or "mode": "off"). It never spawns, routes, or moves anything. It also has outcome and review subcommands and appends to a private decision log, state/lane-placement.jsonl.
  • Added tests/fm-place.test.sh and registered it in bin/fm-test-run.sh (family list, timing table, and the bin/fm-place.sh changed-path mapping).
  • Documented the feature in docs/configuration.md ("Lane placement") and docs/scripts.md, and added the example docs/examples/lane-placement.json with its operator-example entry in docs/documentation-audiences.json. Updated the routing guidance in AGENTS.md and the home layout in the operational-home-layout skill to cover config/lane-placement.json and the decision log.

Risk Assessment

✅ Low: The change is opt-in, advisory-only lane placement scoped to PR B. The approved wording-only fallback correction is now present in the header, the status table and the emitted note, and it matches docs/configuration.md. The answer logic is untouched.

Testing

The existing fm-place test file passes. I also ran the real script against a throwaway home whose capacity facts came from the real fm-capacity.sh --publish. Where a scenario needed an unpressured or stale home, I edited those facts with jq and the script itself was unchanged. Full, clear, fallback, stale fitting home, captain, error, off, usage errors, outcome and review all behaved as documented, and the fallback note uses the approved wording. The log was 0600 and was the only file the script touched. This change has no UI, so no screenshots were taken.

  • Live validation: ✅ go - 10 of 10 scenarios driven live against the product
Scenario Result Live Evidence
When the real host load is high, every home is refused and the status is full ✅ pass live 01-full-real-host-pressure.txt
With all homes unpressured, the best-scoring fitting home (lanes-b, 83) is advised over lanes-a (53) and main ✅ pass live 02-clear-best-fitting.txt
When both fitting homes are blocked, status is clear with place: main and the note 'no fitting home is eligible or unranked' ✅ pass live 03-fallback.txt
A stale fitting home counts as unknown, and the fallback note uses the approved wording, not 'blocked' ✅ pass live 04-unknown-fitting-fallback-wording.txt
A home facts file that names a different home (foreign facts) makes that home unknown and yields ambiguous ✅ pass live Transcript from the earlier run; not saved as an artifact because the facts were then republished
The captain-named home always wins, and facts are still shown ✅ pass live 05-captain-error-off-usage.txt
A task already running in a candidate yields status error, exit 0 ✅ pass live 05-captain-error-off-usage.txt
FM_PLACE=off prints one stderr-style 'place: off' line and exits 0 ✅ pass live 05-captain-error-off-usage.txt
An unknown home, an unknown flag, and a missing --task each exit 2 ✅ pass live 05-captain-error-off-usage.txt
Outcome records followed or override, review summarises agreement, and the log is mode 0600 and the only file written ✅ pass live 06-outcome-review.txt, 07-files-touched.txt
Evidence: Full: real host load refuses every home

Source: Full: real host load refuses every home

# S1 clear: fitting lanes-a,lanes-b, fallback main (real fm-capacity facts)
place:
  status: full   mode: advise   task: t1   project: proj (no-mistakes)   profile: default 1 GB
  candidate: lanes-a -> not eligible: pressure warn: load 17.14 on 8 cores
  candidate: lanes-b -> not eligible: pressure warn: load 17.14 on 8 cores
  candidate: main (fallback) -> not eligible: pressure warn: load 17.14 on 8 cores
  reason: every in-scope home is full, under pressure or reserved; keep the item queued and re-evaluate at the next teardown or heartbeat
  log: 1793044857-t1
rc=0
Evidence: Clear: best fitting home is chosen

Source: Clear: best fitting home is chosen

# S2 clear: all homes unpressured
place:
  status: clear   mode: advise   task: t2   project: proj (no-mistakes)   profile: default 1 GB
  candidate: lanes-a -> eligible score 53: mem 10/40 cpu 23/25 room 20/20  [lanes 0/8, 5 GB free, runq 0.2/core, facts 7 s]
  candidate: lanes-b -> eligible score 83: mem 40/40 cpu 23/25 room 20/20  [lanes 0/8, 12 GB free, runq 0.2/core, facts 0 s]
  candidate: main (fallback) -> eligible score 68: mem 40/40 cpu 23/25 room 20/20 captain -15  [lanes 0/8, 12 GB free, runq 0.2/core, facts 21 s]
  place: lanes-b
  log: 1793044914-t2
rc=0
Evidence: Fallback to main when no fitting home is eligible

Source: Fallback to main when no fitting home is eligible

# S3 fallback: both fitting homes blocked (real host pressure), main eligible
place:
  status: clear   mode: advise   task: t3   project: proj (no-mistakes)   profile: default 1 GB
  candidate: lanes-a -> not eligible: pressure warn: load 53.32 on 8 cores
  candidate: lanes-b -> not eligible: pressure warn: load 53.32 on 8 cores
  candidate: main (fallback) -> eligible score 68: mem 40/40 cpu 23/25 room 20/20 captain -15  [lanes 0/8, 12 GB free, runq 0.2/core, facts 1 s]
  note: no fitting home is eligible or unranked (lanes-a: pressure warn: load 53.32 on 8 cores; lanes-b: pressure warn: load 53.32 on 8 cores); main is the fallback
  place: main
  log: 1793044916-t3
rc=0
Evidence: Stale fitting home with eligible main: wording check

Source: Stale fitting home with eligible main: wording check

# S4 unknown fitting home (stale facts) + eligible main -> wording from fix
place:
  status: clear   mode: advise   task: t4   project: proj (no-mistakes)   profile: default 1 GB
  candidate: lanes-a -> unknown: facts 3601 s old (home not publishing)
  candidate: main (fallback) -> eligible score 68: mem 40/40 cpu 23/25 room 20/20 captain -15  [lanes 0/8, 12 GB free, runq 0.2/core, facts 2 s]
  note: no fitting home is eligible or unranked (lanes-a: facts 3601 s old (home not publishing)); main is the fallback
  place: main
  log: 1793044919-t4
rc=0
Evidence: Captain, already-running task, off, usage errors, JSON

Source: Captain, already-running task, off, usage errors, JSON

# S5 captain-named home wins, facts shown for the record
place:
  status: captain   mode: advise   task: t5   project: proj (no-mistakes)   profile: default 1 GB
  candidate: lanes-a -> eligible score 83: mem 40/40 cpu 23/25 room 20/20  [lanes 0/8, 12 GB free, runq 0.2/core, facts 0 s]
  candidate: lanes-b -> eligible score 83: mem 40/40 cpu 23/25 room 20/20  [lanes 0/8, 12 GB free, runq 0.2/core, facts 0 s]
  candidate: main (fallback) -> eligible score 68: mem 40/40 cpu 23/25 room 20/20 captain -15  [lanes 0/8, 12 GB free, runq 0.2/core, facts 1 s]
  reason: the captain named this home
  place: lanes-a
  log: 1793044929-t5
rc=0
# S6 task already running in a candidate -> error
place:
  status: error   mode: advise   task: t6   project: proj (no-mistakes)   profile: default 1 GB
  candidate: lanes-a -> error: task t6 already runs here: placement is for new lanes only
  candidate: main (fallback) -> eligible score 68: mem 40/40 cpu 23/25 room 20/20 captain -15  [lanes 0/8, 12 GB free, runq 0.2/core, facts 1 s]
  reason: task t6 already runs here: placement is for new lanes only
  log: 1793044929-t6
rc=0
# S7 FM_PLACE=off
place: off (FM_PLACE=off)
rc=0
# S8 usage errors
fm-place: unknown home 'nosuch': not main and not one registered secondmate in data/secondmates.md
rc=2
fm-place: unknown argument --bogus (see --help)
rc=2
fm-place: --task is required
rc=2
# S9 json
{"v":1,"ts":1793044930,"event":"place.advice","id":"1793044930-t9","mode":"advise","task":"t9","project":"proj","delivery":"no-mistakes","profile":"default","footprint_gb":1.0,"requires":[],"fitting":["lanes-b"],"fallback":[],"captain_named":null,"facts_ms":0,"status":"clear","place":"lanes-b","candidates":[{"home":"lanes-b","group":"fitting","rank":1,"lanes":0,"cap":8,"pending":0,"pressure":"ok","basis":"probe","facts_age_s":1,"avail_gb":12,"runq_per_core":0.2,"captain":"not-configured","class":"eligible","reasons":[],"terms":{"mem":40,"cpu":23,"room":20,"captain":0,"quota":0,"unstable":0},"s
-rw-------@ 1 konnermoshier  staff  11974 Oct 26 13:02 /var/folders/zg/kfkfp61x11v1d1tn83t6r5x40000gn/T//fm-lab.IGh6QH/state/lane-placement.jsonl
Evidence: Outcome and review

Source: Outcome and review

place-outcome: recorded t2 -> lanes-b by firstmate (followed: yes)
rc=0
fm-place: outcome reason (not logged): keep with sibling
place-outcome: recorded t3 -> lanes-a by captain (followed: no)
rc=0
place-review:
  span: 14 d   advice: 11   outcomes: 2
  status: clear 4, full 3, ambiguous 2, captain 1, error 1
  agreement: 1 of 2 followed (50%)
  override: t3 advised main chose lanes-a by captain
  home: lanes-a   advised 1   chosen 1   listed 10   unknown 3 (unreachable 0)   refused: pressure warn 3, its own verdict 1
  home: lanes-b   advised 2   chosen 1   listed 9   unknown 2 (unreachable 0)   refused: pressure warn 3, its own verdict 1
  home: main   advised 2   chosen 0   listed 10   unknown 0 (unreachable 0)   refused: pressure warn 3, its own verdict 2, no proj clone in this home 1
rc=0
Evidence: Files touched in the lab home

Source: Files touched in the lab home

sm-a/.fm-secondmate-home
sm-a/state/lane-capacity.json
sm-b/.fm-secondmate-home
sm-b/state/lane-capacity.json
state/lane-capacity.json
state/lane-placement.jsonl

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

🔧 **Rebase** - 4 issues found → auto-fixed ✅
  • ⚠️ AGENTS.md - merge conflict rebasing onto origin/main
  • ⚠️ bin/fm-capacity.sh - merge conflict rebasing onto origin/main
  • ⚠️ docs/configuration.md - merge conflict rebasing onto origin/main
  • ⚠️ tests/fm-capacity.test.sh - merge conflict rebasing onto origin/main

🔧 Fix applied.
✅ Re-checked - no issues remain.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-place.sh:15 - The approved wording-only correction from review round 2 (commit 3eb32498, 'Align fm-place fallback wording with documented rule') is missing from this replay. Only bbe49d5 and c2a6eac are above the base, and 3eb32498 is not an ancestor of HEAD. The round-3 instruction said to preserve that correction in the final tree. The old wording is still in three places, and it contradicts docs/configuration.md:808 ('fallback homes are considered only when no fitting home is eligible or unranked'). (1) bin/fm-place.sh:15 header says the fallback is used 'when every fitting home is blocked'. (2) bin/fm-place.sh:46 says 'the best fallback when every fitting home is blocked'. (3) bin/fm-place.sh:614 emits the note 'every fitting home is blocked (...)'. Because of (3), a fitting home whose facts are unreachable, stale, or missing is reported as 'blocked' even though it was never judged blocked. Matching test: tests/fm-place.test.sh:188 asserts the old note text and must change with it. Restore the 3eb32498 text: 'no fitting home is eligible or unranked (...)', plus the header note that unreachable, stale, or missing facts count as not eligible. This is wording only, with no change to the answer logic.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 10 of 10 scenarios driven live against the product
Scenario Result Live Evidence
When the real host load is high, every home is refused and the status is full ✅ pass live 01-full-real-host-pressure.txt
With all homes unpressured, the best-scoring fitting home (lanes-b, 83) is advised over lanes-a (53) and main ✅ pass live 02-clear-best-fitting.txt
When both fitting homes are blocked, status is clear with place: main and the note 'no fitting home is eligible or unranked' ✅ pass live 03-fallback.txt
A stale fitting home counts as unknown, and the fallback note uses the approved wording, not 'blocked' ✅ pass live 04-unknown-fitting-fallback-wording.txt
A home facts file that names a different home (foreign facts) makes that home unknown and yields ambiguous ✅ pass live Transcript from the earlier run; not saved as an artifact because the facts were then republished
The captain-named home always wins, and facts are still shown ✅ pass live 05-captain-error-off-usage.txt
A task already running in a candidate yields status error, exit 0 ✅ pass live 05-captain-error-off-usage.txt
FM_PLACE=off prints one stderr-style 'place: off' line and exits 0 ✅ pass live 05-captain-error-off-usage.txt
An unknown home, an unknown flag, and a missing --task each exit 2 ✅ pass live 05-captain-error-off-usage.txt
Outcome records followed or override, review summarises agreement, and the log is mode 0600 and the only file written ✅ pass live 06-outcome-review.txt, 07-files-touched.txt
  • bash tests/fm-place.test.sh (all 7 groups ok)
  • Live lab: disposable FM_HOME with two local secondmate homes, each publishing real facts through bin/fm-capacity.sh --publish
  • bin/fm-place.sh --task ... --fitting ... --fallback main for the full, clear, fallback and unknown-fitting cases
  • --captain, an already-running task, FM_PLACE=off, and three usage errors (unknown home, unknown flag, missing --task)
  • --json output, fm-place.sh outcome (firstmate and captain), fm-place.sh review
  • A file-touch check on the lab home; the lab was removed afterwards
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @Moshik21. Welcome back with the placement layer.

Which PR should stay open, this one or #6984? I compared the diffs. bin/fm-place.sh here is byte-identical to #6984 (head 075b237e), and the file set is the same. The difference is that this branch (fm/router-p1-pr-b-2) sits on #6983's newer head bc1d8f58, and its fm-capacity.sh, its tests and the docs are identical to #6983's. So this looks like the rebased version of #6984 on a new branch, much like #7585 earlier. Your 02:47Z note asked us to keep #6973, #6983 and #6984 open. Could you confirm whether this PR replaces #6984? If it does, please close #6984 (or tell us and I'll close it). I won't close either one on a guess.

  • Stack: feat(bin): add fm-capacity.sh to report open lanes and host headroom #6973 is now merged as f1ef0294. As a result, this branch (and feat(bin): publish lane capacity facts with beat pressure and keyed limits #6983) shows as CONFLICTING with main, because bin/fm-capacity.sh and its test are added on both sides. This layer can land only after feat(bin): publish lane capacity facts with beat pressure and keyed limits #6983, and after a rebase that leaves just PR B in the diff.
  • Head da3fac8b. The attestation matches it, and live validation passed 7 of 8 scenarios (the "clear" case wasn't reachable on a loaded host, and the suite covers it). CI 39553504935 was still running when I checked. Require no-mistakes passed.
  • Contract class (my own read): opt-in. fm-place.sh does nothing without config/lane-placement.json in "mode": "advise", and FM_PLACE=off is a kill switch. It only advises and never spawns, routes or sends. Remote facts come through the existing fm-on.sh/fm-remote-file.sh path, bounded in time and size. Both new AGENTS.md lines apply only when their config file exists. The diff touches no workflow files and adds no secrets.
  • VISION.md: aligns on all seven areas. It's advisory, the captain-named home wins, and the agent decides. The scripts are deterministic, the decision log is 0600 on disk, it stays vendor-neutral, and it stays within scope.

Waiting on you: confirm which PR to keep, then rebase in stack order after #6983 lands. Nothing else is needed from you right now.

@Moshik21

Copy link
Copy Markdown
Contributor Author

#7595 replaces #6984. Pipeline custody for the old branch could not be recovered safely; the replacement also includes the privacy scrub. Keep the replacement open; the old PR is being closed as superseded. With #6973 merged, the remaining landing order is #6983, then #7595. The required rebases are still in progress.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks for confirming, @Moshik21. This PR replaces #6984, which you've closed, so there's nothing left to sort out on duplicates. We'll land #6983 and then this one.

This branch still sits on #6983's old head bc1d8f58, so GitHub shows it as CONFLICTING. Once #6983 lands (its CI re-run is in progress), please rebase this onto main so the diff covers only PR B, and re-raise through no-mistakes. My read is unchanged: opt-in. fm-place.sh stays off without config/lane-placement.json in advise mode, and it only advises. It aligns with VISION.md. With a clean rebase and green CI, it can land.

@Moshik21
Moshik21 force-pushed the fm/router-p1-pr-b-2 branch from da3fac8 to 0a75739 Compare October 26, 2026 20:04
@Moshik21 Moshik21 changed the title feat(bin): add lane capacity reporting and advisory lane placement feat(bin): add opt-in advisory lane placement with fm-place.sh Oct 26, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @Moshik21 for the rebase. #6983 landed (3440dd03), and the diff is now just PR B: bin/fm-place.sh, its suite, the docs, and the one AGENTS.md routing line.

What I checked (head 0a757399): the placement logic matches what I reviewed before. The new commits document FM_LANE_CAPACITY_PUBLISH_INTERVAL and align the fallback wording. GitHub reports MERGEABLE. The no-mistakes attestation binds this head, and live validation is 10 of 10. I found no workflow, network or credential changes.

Contract-class (my own read): still opt-in. fm-place.sh prints place: off and exits when config/lane-placement.json is absent, when "mode" is not advise, or when FM_PLACE=off is set. The new AGENTS.md line applies only when that file exists, and the script only advises: it never spawns, routes or sends. VISION.md: every rule aligns (unchanged).

CI: the failing serial shards ran on the old ubuntu-26.04 image. They're the same failures main itself has, and none are in fm-place. That's on our side, not yours, and you don't need to push anything. Once main is green and this gets a fresh run on the pinned runners, it can land.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants