Skip to content

feat(bin): advise lane placement from published lane facts - #6984

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

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

Conversation

@Moshik21

@Moshik21 Moshik21 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Our own open upstream pull request #6984 (feat(bin): advise lane placement from published lane facts, branch fm/router-p1-pr-b) currently shows mergeable=false (conflicts) against upstream main. Get it rebased and passing its checks again. Upstream consent for updating this exact PR branch is recorded for this task. The PR adds bin/fm-place.sh, an advisory lane-placement command that reads published lane capacity facts, and is stacked on the open PRs #6983 and #6973, whose commits it carries and must keep unchanged.

What Changed

  • Added bin/fm-capacity.sh, which reports open lanes and host headroom against an optional config/lane-capacity target. Its --publish mode writes the state/lane-capacity.json facts document, and --admit returns this home's admission verdict as an exit status. bin/fm-watch.sh publishes the document from a detached job only while config/lane-capacity exists.
  • Added bin/fm-place.sh, an advisory placement command that is opt-in through config/lane-placement.json. It ranks candidate homes from their published lane facts and prints a status and score breakdown. It appends each decision to state/lane-placement.jsonl, and it also provides outcome and review subcommands. It never spawns or routes anything.
  • Documented the new config, state files and scripts in docs/configuration.md, docs/scripts.md, the operational-home-layout skill, AGENTS.md, and a new docs/examples/lane-placement.json listed in docs/documentation-audiences.json. Added tests/fm-capacity.test.sh and tests/fm-place.test.sh, and registered both with bin/fm-test-run.sh.

Risk Assessment

✅ Low: The rebase kept the carried #6973/#6983 commits and the fm-test-run.sh resolution as the user decided, and I found no concrete defect in the new advisory, opt-in, exit-0 placement script or the capacity publisher.

Testing

I ran tests/fm-place.test.sh and tests/fm-capacity.test.sh in full; both pass, including the captain/quota case that failed last round. A dry merge of HEAD into current origin/main is clean, with 9 commits ahead of it. I then ran the real bin/fm-capacity.sh --publish and bin/fm-place.sh against two disposable lab homes (a main home and a local secondmate "scholar"), covering the config guards, scoring, outcome and review recording, and the stale and foreign-facts guards. All 13 live scenarios passed (see the scenario list). The lab homes were removed afterwards. tests/fm-test-run.test.sh has one failure, "packing exactly at the budget": the coverage guard reports that portable serial shards share scripts. It fails identically on the base commit 9d76aa8, so I report it as unrelated. I did not test the remote-secondmate read path through fm-on.sh live because it needs an ssh host; the unit suite covers it.

  • Live validation: ✅ go - 13 of 13 scenarios driven live against the product
Scenario Result Live Evidence
Rebased branch merges cleanly into current origin/main and carries the fm-place entries in bin/fm-test-run.sh ✅ pass live git merge-tree --write-tree origin/main HEAD exits 0; the fm-test-run.sh diff shows tests/fm-place.test.sh 22000 listed before tests/fm-polytoken-harness.test.sh and tests/fm-polytoken-signals-live-e2…
fm-place.test.sh passes ✅ pass live bash tests/fm-place.test.sh prints '# all fm-place tests passed'
Carried fm-capacity suite passes on this host, including the captain-presence test that failed last round ✅ pass live bash tests/fm-capacity.test.sh prints '# all fm-capacity tests passed'
A zero value for min_uptime_s is rejected: fm-place exits 2 and names the problem ✅ pass live place-live-1.txt
A fact file naming another home is treated as unknown and the status falls to ambiguous ✅ pass live place-live-1.txt shows 'facts name home main, not scholar'; place-live-3.txt S12 shows a tampered home field rejected
A host under real load pressure is refused with its reason: main (fallback) is 'not eligible: pressure warn: load 18.37 on 8 cores' ✅ pass live place-live-1.txt
With both homes healthy, scholar is advised with scores matching the documented formula (mem 27, cpu 23, room 20 = 70; main 51 after the -15 captain term) ✅ pass live place-live-2.txt S2
A captain-named home is the answer and the other candidate's facts are shown for the record ✅ pass live place-live-2.txt S3
Local-only work is refused on non-main homes; unknown home and unknown delivery exit 2; --json emits a place.advice object; FM_PLACE=off prints one stderr line and nothing on stdout ✅ pass live place-live-2.txt S4-S7
outcome records followed, override and no-advice; reason text is not written to the log; recent outcomes count as pending lanes and make the home 'full' (0+4 pending of 2 lanes); the log is mode 0600 ✅ pass live place-live-3.txt S8-S9 and log mode listing
review reports status counts, agreement (1 of 2 followed), the captain override, and per-home refusal reasons ✅ pass live place-live-3.txt S10
Facts 10 minutes old are treated as unknown ('home not publishing'), giving ambiguous (decide as today) ✅ pass live place-live-3.txt S11
mode: enforce in config is a configuration error (exit 2) ✅ pass live place-live-3.txt S13
Evidence: Live fm-place run: config guard, foreign-facts guard, host under real pressure

Source: Live fm-place run: config guard, foreign-facts guard, host under real pressure

$ fm-place ... --fitting scholar --fallback main   (host really under warn pressure)
place:
  status: ambiguous   mode: advise   task: t1   project: demo (no-mistakes)   profile: default 1 GB
  candidate: scholar -> unknown: facts name home main, not scholar
  candidate: main (fallback) -> not eligible: pressure warn: load 18.37 on 8 cores
  reason: no home is rankable on known facts (scholar: facts name home main, not scholar); every other home is refused; decide as today
  log: 1792530491-t1
exit=0
Evidence: Live fm-place run: clear, captain, local-only, usage errors, JSON, kill switch

Source: Live fm-place run: clear, captain, local-only, usage errors, JSON, kill switch

\### S2 clear: both homes healthy, scholar better
place:
  status: clear   mode: advise   task: t2   project: demo (no-mistakes)   profile: default 1 GB
  candidate: scholar -> eligible score 70: mem 27/40 cpu 23/25 room 20/20  [lanes 0/2, 14 GB free, runq 0.2/core, facts 6 s]
  candidate: main (fallback) -> eligible score 51: mem 25/40 cpu 21/25 room 20/20 captain -15  [lanes 0/8, 8 GB free, runq 0.4/core, facts 7 s]
  place: scholar
  log: 1792530516-t2
exit=0

\### S3 captain choice: main named
place:
  status: captain   mode: advise   task: t3   project: demo (no-mistakes)   profile: default 1 GB
  candidate: scholar -> eligible score 70: mem 27/40 cpu 23/25 room 20/20  [lanes 0/2, 14 GB free, runq 0.2/core, facts 7 s]
  candidate: main (captain) -> eligible score 51: mem 25/40 cpu 21/25 room 20/20 captain -15  [lanes 0/8, 8 GB free, runq 0.4/core, facts 8 s]
  reason: the captain named this home
  place: main
  log: 1792530517-t3
exit=0

\### S4 local-only never main? (local-only, fitting main)
place:
  status: clear   mode: advise   task: t4   project: demo (local-only)   profile: default 1 GB
  candidate: main -> eligible score 51: mem 25/40 cpu 21/25 room 20/20 captain -15  [lanes 0/8, 8 GB free, runq 0.4/core, facts 8 s]
  candidate: scholar -> not eligible: local-only work stays in the main home
  place: main
  log: 1792530517-t4
exit=0

\### S5 unknown home / unknown delivery -> exit 2
fm-place: unknown home 'nosuch': not main and not one registered secondmate in data/secondmates.md
exit=2
fm-place: --delivery must be no-mistakes, direct-PR, or local-only
exit=2

\### S6 json
{"event":"place.advice","status":"clear","chosen":"scholar","cands":[{"home":"scholar","class":"eligible","score":70},{"home":"main","class":"eligible","score":51}]}

\### S7 kill switch
place: off (FM_PLACE=off)
exit=0
Evidence: Live fm-place run: outcome, pending, review, stale and foreign facts, enforce refused

Source: Live fm-place run: outcome, pending, review, stale and foreign facts, enforce refused

\### S8 outcome followed / override + pending
place-outcome: recorded t2 -> scholar by firstmate (followed: yes)
exit=0
fm-place: outcome reason (not logged): secret-reason-text
place-outcome: recorded t3 -> scholar by captain (followed: no)
exit=0
\### S9 pending lane holds a place: scholar cap 2, two pending -> full?
place-outcome: recorded t90 -> scholar by firstmate (followed: no advice)
place-outcome: recorded t91 -> scholar by firstmate (followed: no advice)
place:
  status: full   mode: advise   task: t10   project: demo (no-mistakes)   profile: default 1 GB
  candidate: scholar -> not eligible: full: 0+4 pending of 2 lanes
  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: 1792530528-t10
exit=0
\### S10 review
place-review:
  span: 1 d   advice: 6   outcomes: 4
  status: clear 3, ambiguous 1, captain 1, full 1
  agreement: 1 of 2 followed (50%)
  override: t3 advised main chose scholar by captain
  home: main   advised 2   chosen 0   listed 5   unknown 0 (unreachable 0)   refused: pressure warn 1
  home: scholar   advised 2   chosen 4   listed 6   unknown 1 (unreachable 0)   refused: full 1, local-only work stays in the main home 1
\### log mode / reason not logged
-rw-------@ 1 konnermoshier  staff  5642 Oct 20 14:08 /var/folders/zg/kfkfp61x11v1d1tn83t6r5x40000gn/T//fm-lab.lyjOeK/state/lane-placement.jsonl
0
\### S11 stale facts: age the clock 10 min
place:
  status: ambiguous   mode: advise   task: t11   project: demo (no-mistakes)   profile: default 1 GB
  candidate: scholar -> unknown: facts 618 s old (home not publishing)
  candidate: main (fallback) -> unknown: facts 619 s old (home not publishing)
  reason: no home is rankable on known facts (scholar: facts 618 s old (home not publishing); main: facts 619 s old (home not publishing)); decide as today
  log: 1792531128-t11
exit=0
\### S12 foreign: tamper facts home field
place:
  status: clear   mode: advise   task: t12   project: demo (no-mistakes)   profile: default 1 GB
  candidate: scholar -> unknown: facts name home evil, not scholar
  candidate: main -> eligible score 51: mem 25/40 cpu 21/25 room 20/20 captain -15  [lanes 0/8, 8 GB free, runq 0.4/core, facts 19 s]
  place: main
  log: 1792530528-t12
exit=0
\### S13 enforce mode is config error
fm-place: config/lane-placement.json: mode enforce is not available in this version; use advise or off
exit=2
- Outcome: ⚠️ 1 info across 2 runs (36m17s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

🔧 **Rebase** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-test-run.sh - merge conflict rebasing onto origin/main

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

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 1 info
Scenario Result Live Evidence
Rebased branch merges cleanly with origin/main, test-list order is place, polytoken-harness, polytoken-signals-live-e2e, pr-check-security ⏸️ untested no The prior payload only inspected git and files (merge-tree, diff of bin/fm-test-run.sh); it did not drive a running product, so it did not establish a live result for this scenario.
Equal scores resolve to the lower configured rank (sm-a over sm-b) with a tie note ✅ pass live fm-place-live.txt scenario A: status clear, tie at 75, place: sm-a
A home with fewer free lane places loses on the room score (sm-b over sm-a at 3/4 lanes) ✅ pass live fm-place-live.txt scenario B: sm-a 62 vs sm-b 77, place: sm-b
When every fitting home is full, the fallback home (main) is advised; when all are full the answer is 'full' and keeps the item queued ✅ pass live fm-place-live.txt scenarios C and D
A task already running in a candidate yields status error, 'decide as today', exit 0 ✅ pass live fm-place-live.txt scenario E
Stale, future-dated, and missing published facts make a home unknown for the decision, not guessed ✅ pass live fm-place-live.txt scenarios F, G, H
A captain-named home is always the answer even when another scores equal or better; nothing is spawned or moved ✅ pass live fm-place-live.txt scenario I (status captain, place: sm-b) and P (lab state holds only the capacity facts and the decision log)
A pressure-warn home is refused and the healthy one is advised ✅ pass live fm-place-live.txt scenario J
Outcome and review record choices, the log is mode 0600, and --reason text never reaches the log ✅ pass live fm-place-live.txt scenarios K, L, M (mode 600, 14 lines, secret-text count 0)
Off paths (mode off, absent config, FM_PLACE=off) print one stderr line and exit 0; mode enforce and non-positive numeric config exit 2; an undeclared home exits 2 ✅ pass live fm-place-live.txt scenarios N, O, 4, 6; fm-place-live-bad-config.txt
Carried fm-capacity suite passes on this host ❌ fail live bash tests/fm-capacity.test.sh: 'unreadable presence and quota must read unknown (expected unknown|unknown, got idle|unknown)'
  • git merge-tree --write-tree origin/main HEAD (clean merge, HEAD sits directly on origin/main)
  • git diff origin/main -- bin/fm-test-run.sh: tests/fm-place.test.sh 22000 sits before tests/fm-polytoken-harness.test.sh 21090, tests/fm-polytoken-signals-live-e2e.test.sh 103 and tests/fm-pr-check-security.test.sh
  • bash tests/fm-place.test.sh (all pass)
  • bash tests/fm-capacity.test.sh (one host-dependent failure in the unchanged #6983 code)
  • Disposable lab home from bin/fm-lab-home.sh create, with real bin/fm-capacity.sh --publish documents for main, sm-a and sm-b, then bin/fm-place.sh run against it: clear/tie-break, room scoring, fallback, full, error, stale/future/missing facts, captain, pressure refusal, outcome, review, log mode 0600, enforce/off/absent config, bad numeric config
  • Lab torn down with rm -rf

🔧 Fix applied.
1 info still open:

  • ℹ️ tests/fm-test-run.test.sh, test_portable_serial_packing_budget_boundary ('packing exactly at the budget must be accepted'), fails on this macOS host. The coverage guard reports 'portable serial shards share scripts'. The same test fails against the base commit 9d76aa8, so it is not caused by this change. Remote Linux CI is the arbiter.
  • Live validation: ✅ go - 13 of 13 scenarios driven live against the product
Scenario Result Live Evidence
Rebased branch merges cleanly into current origin/main and carries the fm-place entries in bin/fm-test-run.sh ✅ pass live git merge-tree --write-tree origin/main HEAD exits 0; the fm-test-run.sh diff shows tests/fm-place.test.sh 22000 listed before tests/fm-polytoken-harness.test.sh and tests/fm-polytoken-signals-live-e2…
fm-place.test.sh passes ✅ pass live bash tests/fm-place.test.sh prints '# all fm-place tests passed'
Carried fm-capacity suite passes on this host, including the captain-presence test that failed last round ✅ pass live bash tests/fm-capacity.test.sh prints '# all fm-capacity tests passed'
A zero value for min_uptime_s is rejected: fm-place exits 2 and names the problem ✅ pass live place-live-1.txt
A fact file naming another home is treated as unknown and the status falls to ambiguous ✅ pass live place-live-1.txt shows 'facts name home main, not scholar'; place-live-3.txt S12 shows a tampered home field rejected
A host under real load pressure is refused with its reason: main (fallback) is 'not eligible: pressure warn: load 18.37 on 8 cores' ✅ pass live place-live-1.txt
With both homes healthy, scholar is advised with scores matching the documented formula (mem 27, cpu 23, room 20 = 70; main 51 after the -15 captain term) ✅ pass live place-live-2.txt S2
A captain-named home is the answer and the other candidate's facts are shown for the record ✅ pass live place-live-2.txt S3
Local-only work is refused on non-main homes; unknown home and unknown delivery exit 2; --json emits a place.advice object; FM_PLACE=off prints one stderr line and nothing on stdout ✅ pass live place-live-2.txt S4-S7
outcome records followed, override and no-advice; reason text is not written to the log; recent outcomes count as pending lanes and make the home 'full' (0+4 pending of 2 lanes); the log is mode 0600 ✅ pass live place-live-3.txt S8-S9 and log mode listing
review reports status counts, agreement (1 of 2 followed), the captain override, and per-home refusal reasons ✅ pass live place-live-3.txt S10
Facts 10 minutes old are treated as unknown ('home not publishing'), giving ambiguous (decide as today) ✅ pass live place-live-3.txt S11
mode: enforce in config is a configuration error (exit 2) ✅ pass live place-live-3.txt S13
  • bash tests/fm-place.test.sh (passes)
  • bash tests/fm-capacity.test.sh (passes, including test_captain_and_quota)
  • git merge-tree --write-tree origin/main HEAD (clean, exit 0)
  • bash tests/fm-test-run.test.sh (one failure, test_portable_serial_packing_budget_boundary, also fails on base 9d76aa8e)
  • Live: bin/fm-lab-home.sh create, bin/fm-capacity.sh --publish and bin/fm-place.sh (advice, --captain, --json, outcome, review, FM_PLACE=off) against two lab homes
  • Live adversarial: stale facts via FM_PLACE_NOW, tampered facts home field, invalid config values, mode: enforce, unknown home, unknown delivery
✅ **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. This is a carefully specified piece, and turning the proposal's worked examples into fixtures is great. I read head d4f47a0a against main fb75c1f9. It targets main but carries #5472 and #6983 (PR A) underneath, so it can only land after those, in stack order.

What I checked: bin/fm-place.sh is advisory only. It never spawns, routes, or sends. The fm-watch.sh publish hook runs only when config/lane-capacity exists, and fm-place.sh only when config/lane-placement.json exists. The new AGENTS.md line is conditional on that file. The log is 0600, with ids, numbers and fixed codes, and ssh error text stays on stderr. There are no workflow, secret, or new network surfaces; remote reads use the existing fm-on.sh path. I approved your first-time fork runs 38017601851 (CI) and 38017601824/38017688715 (Require no-mistakes).

Contract-class: opt-in (my own read). Unconfigured, this costs one file test per beat plus one conditional contract line.
VISION: One captain: aligns (advice, escalate only on a real choice). Authority: aligns (captain-named home always wins, advise mode only). Scripts/agents: aligns (scoring in a script, final choice stays with the agent). Restart: aligns (durable log/facts). Delegation: aligns. Vendor: aligns. Scope: cannot tell yet. It's about 2.6k lines of placement machinery, so whether it earns its way in over existing primitives is Kun's call.

Waiting on you, gently:

  1. The PR body has no no-mistakes attestation marker for this head, so Require no-mistakes can't bind it. Could you re-raise via git push no-mistakes (≥1.46) so the attestation lands?
  2. The Testing section shows a hand-run against a fixture home. When you can, a live run would help a lot: real main plus at least one real secondmate publishing state/lane-capacity.json, with the advice and outcome you saw.

Once both are in and the base PRs land, it'll go to Kun.

Add bin/fm-capacity.sh, a read-only, network-free report of this home's
running lanes against an optional config/lane-capacity target, plus
1-minute load versus logical cores, free memory, and free disk. The first
output line is machine-readable (free_lanes=N reason=...), followed by a
human summary. Probes degrade to unknown when unavailable on a platform.

Document config/lane-capacity in docs/configuration.md and point the
backlog re-evaluation rule in AGENTS.md at the new report.
…imits

Extend bin/fm-capacity.sh with --json, --publish, and --admit, optional
config/lane-capacity lines (min-avail-gb, min-disk-gb, pressure-file,
reserve-flag, captain-idle, quota-provider, max-load1), lookout.beat
pressure reading with probe fallback, and an opt-in watcher publish of
state/lane-capacity.json.
bin/fm-place.sh reads each candidate home's state/lane-capacity.json
(local, or through fm-on.sh and fm-remote-file.sh for a remote home),
filters and scores the fitting homes, prints one TOON answer with every
home's reasons, and appends one line to state/lane-placement.jsonl. It
never spawns, routes, or moves anything. Modes are off and advise, opted
in by config/lane-placement.json; outcome records firstmate's choice and
review summarizes the advice period. Facts failing fail open; a malformed
config exits 2.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @Moshik21 for getting this rebased.

Which PR should stay open? #7585 has the same title and diff, and its body says its goal is to update this PR. This branch (fm/router-p1-pr-b, head 075b237e) was force-pushed at 21:35 UTC. It now has everything #7585 has, plus the ioreg stub fix in tests/fm-capacity.test.sh. I compared the two diffs, and that is the only difference. So this PR looks like the one to keep, and #7585 looks like a duplicate from your rebase run. Could you confirm, and close #7585 (or tell me which one you'd rather keep)? I won't close either one until you say.

What I checked on 075b237e against main 9d76aa8e: the merge is clean. fm-place.sh only gives advice. It never spawns, routes, or sends. The fm-watch.sh publish only runs when config/lane-capacity exists, and placement only runs when config/lane-placement.json exists. There are no workflow, secret, or new network changes. Remote reads use the existing fm-on.sh path. CI is green except Behavior portable serial 2, which was cancelled at the 30-minute ceiling (the known #7255 issue, not caused by this PR). I re-ran it once (run 39501592594). No-mistakes passed.

Contract-class: opt-in (my own read; unchanged from the earlier pass). Without any config, the only costs are one file test per beat and the contract lines. One note: the carried AGENTS.md line "bin/fm-capacity.sh reports open lanes and host headroom for that re-evaluation" is not gated on any config. Please keep it purely informational, so that an unconfigured home never treats its output as a dispatch hold.

VISION: One captain: aligns (advice only; it escalates only when there is a real choice). Authority: aligns (a home the captain names always wins; it never dispatches). Scripts/agents: aligns (the script scores, the agent decides). Restart: aligns (durable log and facts files). Delegation: aligns (live evidence 13/13 in the body). Vendor: aligns (no harness coupling). Scope: aligns (command layer only).

Stack order is still a blocker: this branch carries #6973 and #6983, and both are still open. As before, at most one layer lands at a time, starting with #6973. Then this branch needs a rebase so its diff covers only PR B. That part is on the stack order, not on you right now. The one thing I need from you is the #6984/#7585 answer.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @Moshik21. You confirmed #7585 was opened in error and closed it, so this is the PR we'll keep. You don't need to do anything right now. What's left is the serial 2 re-run (39501592594) and the stack order: #6973, then #6983, and then this branch rebased so its diff covers only PR B.

@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.

@Moshik21 Moshik21 closed this Oct 21, 2026
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