Skip to content

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

Closed
Moshik21 wants to merge 8 commits into
kunchenguid:mainfrom
Moshik21:fm/fm-upstream-6984-rebase
Closed

Moshik21 wants to merge 8 commits into
kunchenguid:mainfrom
Moshik21:fm/fm-upstream-6984-rebase

Conversation

@Moshik21

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 against the optional config/lane-capacity target plus host headroom. --json prints the fm-lane-capacity.v1 document and --publish writes it to state/lane-capacity.json. bin/fm-watch.sh now publishes that file detached, only when config/lane-capacity exists and the file is at least 30s old.
  • Added bin/fm-place.sh, an advisory lane-placement command. It reads each candidate home's published lane facts (local, secondmate, or remote), ranks eligible homes, and treats missing, stale, or unreachable facts as unknown. It has outcome and review subcommands for the decision log. It is opt-in through config/lane-placement.json and never spawns or routes anything.
  • Documented the new scripts and the "Lane capacity" / "Lane placement" config contracts (docs/configuration.md, docs/scripts.md, docs/examples/lane-placement.json, AGENTS.md, the operational-home-layout skill, docs/documentation-audiences.json). Added tests/fm-capacity.test.sh and tests/fm-place.test.sh and registered them in bin/fm-test-run.sh.

Risk Assessment

✅ Low: The rebase kept every carried commit's changed lines identical to the pre-rebase versions and applied the recorded bin/fm-test-run.sh resolution (fm-place 22000 before the polytoken entries). The shell sources and helper functions the new scripts depend on still exist on the new base, and all touched scripts pass bash -n.

Testing

The fm-place test file passes. Live runs of bin/fm-place.sh against disposable lab homes (with real facts from bin/fm-capacity.sh --publish) showed the expected statuses and guards; the lab homes were deleted afterwards. Two checks failed on this host and are explained in the findings: the host-dependent ioreg case in fm-capacity, and the --check-coverage guard, which fails only inside this gate worktree and passes on clean copies of the same commit. The live runs never produced a ranked "clear" pick: host load was about 120, which made main ineligible, and the second lab home's facts were rejected as foreign. The ranking and scoring paths are covered by the passing fm-place test file only. I could not verify that the carried #6973/#6983 commits are unchanged against upstream, because no remote refs are available in the worktree. The runner diff against upstream main shows only the PR's own additions.

  • Live validation: ✅ go - 5 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Runner test list keeps both sides of the merge, in sorted order, with nothing else changed ✅ pass live git diff 9d76aa8 HEAD -- bin/fm-test-run.sh adds fm-place.test.sh and fm-capacity.test.sh entries, and bin/fm-test-run.sh --list --all lists fm-place, polytoken-harness and polytoken-signals-live-…
fm-place advises placement from published lane facts: on, off, captain override, unknown home, missing facts, outcome and review, private decision log ✅ pass live fm-place-live.txt, fm-place-live2.txt, fm-place-live-invalid-config.txt. Statuses seen were ambiguous, full, captain and off; a missing-facts home was reported unknown. The decision log was mode 600.
fm-place behavior tests pass after the rebase ✅ pass live fm-place.test.log: all fm-place tests passed
fm-capacity tests pass after the rebase ✅ pass live fm-capacity.test.log has 1 failure on this macOS host, caused by the real ioreg on PATH. fm-capacity.noioreg.log passes with /usr/sbin off PATH.
Test-runner coverage guard accepts the rebased tree ✅ pass live Passes on 5/5 clean copies of the HEAD tree (git archive, no-.git copy, linked worktree, .no-mistakes path, long path). Fails 5/5 in the gate worktree itself, cause not found; see the warning finding.…
The carried #6973/#6983 commits are unchanged versus upstream ⏸️ untested no The worktree has no remote refs for PRs #6973/#6983, and I may not read the bare gate repo or fetch from the network. Compare patch-ids against the upstream PR heads, or let the outer executor do it,…
Evidence: fm-place live run transcript (lab home, valid config)

Source: fm-place live run transcript (lab home, valid config)

\### 1. both fitting, advice
place:
  status: full   mode: advise   task: t1   project: demo (local-only)   profile: default 0.5 GB
  candidate: main -> not eligible: no demo clone in this home; pressure warn: load 112.89 on 8 cores
  candidate: docs-lanes -> not eligible: local-only work stays in the main home
  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: 1792524019-t1
exit=0
\### 2. requires macos -> docs-lanes not eligible
place:
  status: full   mode: advise   task: t2   project: demo (local-only)   profile: macos-app 0.5 GB
  candidate: main -> not eligible: no demo clone in this home; pressure warn: load 112.89 on 8 cores
  candidate: docs-lanes -> not eligible: local-only work stays in the main home
  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: 1792524021-t2
exit=0
\### 3. captain override
place:
  status: captain   mode: advise   task: t3   project: demo (local-only)   profile: default 0.5 GB
  candidate: main -> not eligible: no demo clone in this home; pressure warn: load 112.89 on 8 cores
  candidate: docs-lanes (captain) -> not eligible: local-only work stays in the main home
  reason: the captain named this home
  note: facts for the captain's choice, for the record only: local-only work stays in the main home
  place: docs-lanes
  log: 1792524023-t3
exit=0
\### 4. unknown home
fm-place: unknown home 'nope': not main and not one registered secondmate in data/secondmates.md
exit=2
\### 5. missing facts -> unknown
place:
  status: full   mode: advise   task: t5   project: demo (local-only)   profile: default 0.5 GB
  candidate: main -> not eligible: no demo clone in this home; pressure warn: load 112.89 on 8 cores
  candidate: docs-lanes -> not eligible: local-only work stays in the main home
  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: 1792524025-t5
exit=0
\### 6. outcome + review
place-outcome: recorded t1 -> main by firstmate (followed: no advice)
exit=0
{"since_days":14,"advice":4,"outcomes":1,"status":{"full":3,"captain":1},"agreement":{"judged":0,"followed":0},"overrides":[],"homes":[{"home":"docs-lanes","advised":1,"chosen":0,"listed":4,"unknown":0,"unreachable":0,"refused":{"local-only work stays in the main home":4}},{"home":"main","advised":0,"chosen":1,"listed":4,"unknown":0,"unreachable":0,"refused":{"no demo clone in this home":4,"pressure warn":4}}]}

\### 7. log
600
       5
Evidence: fm-place live run: direct-PR, missing-facts and foreign-facts cases

Source: fm-place live run: direct-PR, missing-facts and foreign-facts cases

\### A both fitting, direct-PR
place:
  status: ambiguous   mode: advise   task: a1   project: demo (direct-PR)   profile: default 0.5 GB
  candidate: main -> not eligible: pressure warn: load 121.85 on 8 cores
  candidate: docs-lanes -> unknown: facts name home main, not docs-lanes
  reason: no home is rankable on known facts (docs-lanes: facts name home main, not docs-lanes); every other home is refused; decide as today
  log: 1792524045-a1
exit=0
\### B requires macos
place:
  status: ambiguous   mode: advise   task: a2   project: demo (direct-PR)   profile: default 0.5 GB
  candidate: main -> not eligible: pressure warn: load 121.85 on 8 cores
  candidate: docs-lanes -> unknown: facts name home main, not docs-lanes
  reason: no home is rankable on known facts (docs-lanes: facts name home main, not docs-lanes); every other home is refused; decide as today
  log: 1792524046-a2
exit=0
\### C docs-lanes facts missing -> unknown, main still ranked
place:
  status: ambiguous   mode: advise   task: a3   project: demo (direct-PR)   profile: default 0.5 GB
  candidate: main -> not eligible: pressure warn: load 121.85 on 8 cores
  candidate: docs-lanes -> unknown: no published facts
  reason: no home is rankable on known facts (docs-lanes: no published facts); every other home is refused; decide as today
  log: 1792524047-a3
exit=0
\### D task already running in candidate -> error
{"v":1,"ts":1792524049,"event":"place.advice","id":"1792524049-a3","mode":"advise","task":"a3","project":"demo","delivery":"direct-PR","profile":"default","footprint_gb":0.5,"requires":[],"fitting":["main"],"fallback":[],"captain_named":null,"facts_ms":0,"status":"full","reason":"every in-scope home
Evidence: fm-place live run: invalid config rejected

Source: fm-place live run: invalid config rejected

\### 1. both fitting, advice
fm-place: config/lane-placement.json: facts_max_age_s, facts_budget_s, min_uptime_s, unstable_window_s, and pending_ttl_s must be positive integers
exit=2
\### 2. requires macos -> docs-lanes not eligible
fm-place: config/lane-placement.json: facts_max_age_s, facts_budget_s, min_uptime_s, unstable_window_s, and pending_ttl_s must be positive integers
exit=2
\### 3. captain override
fm-place: config/lane-placement.json: facts_max_age_s, facts_budget_s, min_uptime_s, unstable_window_s, and pending_ttl_s must be positive integers
exit=2
\### 4. unknown home (adversarial)
fm-place: config/lane-placement.json: facts_max_age_s, facts_budget_s, min_uptime_s, unstable_window_s, and pending_ttl_s must be positive integers
exit=2
\### 5. stale/missing facts -> unknown
fm-place: config/lane-placement.json: facts_max_age_s, facts_budget_s, min_uptime_s, unstable_window_s, and pending_ttl_s must be positive integers
exit=2
\### 6. off via FM_PLACE=off
place: off (FM_PLACE=off)
exit=0
\### 7. outcome + review
place-outcome: recorded t1 -> main by firstmate (followed: no advice)
exit=0
{"since_days":14,"advice":0,"outcomes":1,"status":{},"agreement":{"judged":0,"followed":0},"overrides":[],"homes":[{"home":"main","advised":0,"chosen":1,"listed":0,"unknown":0,"unreachable":0,"refused":{}}]}

\### 8. log perms
600
       1 /var/folders/zg/kfkfp61x11v1d1tn83t6r5x40000gn/T//fm-lab.vF6ZBn/state/lane-placement.jsonl
Evidence: fm-place test log

Source: fm-place test log

ok - the Proposal's worked examples recompute to the same placements
ok - off, FM_PLACE=off, and an absent config print one stderr line and read nothing
ok - usage and configuration errors exit 2 and are never selected around
ok - every filter refuses, discloses, or ranks with its plain reason
fm-place: outcome reason (not logged): the captain wants it on scholar
ok - outcomes record the choice, and recent ones hold pending lanes
ok - unreachable and stalled homes are unknown, and the log is private, rotated, and optional
fm-place: outcome reason (not logged): kept with its sibling lane
ok - review reports agreement, overrides, and per-home refusals over its span
# all fm-place tests passed
Evidence: fm-capacity test log (fails on macOS ioreg case)

Source: fm-capacity test log (fails on macOS ioreg case)

ok - absent config/lane-capacity reports counts and no target
ok - a target yields open lanes, full, and never a negative count
ok - cpu, memory, and disk pressure close every lane and are named
ok - unavailable probes print unknown and do not constrain
ok - a malformed target is reported, not guessed
ok - keyed config lines parse, and unknown, repeated, or malformed lines are refused
ok - a fresh beat replaces probes, and its warn level closes lanes with its reason
ok - late beats count, and stale, missing, malformed, or foreign beats fall back to probes
ok - several pressure files: worst level wins, first supplies memory, every disk counts
ok - a beat with missing fields keeps its fields aligned and limits fall back to probes
ok - the lane footprint memory rule applies only with min-avail-gb
ok - limits close lanes with named reasons, and --admit exits 0, 75, or 1
ok - publish is opt-in, private, throttled, records boots, and publishes an invalid config as invalid
not ok - unreadable presence and quota must read unknown (expected 'unknown|unknown', got 'idle|unknown')
Evidence: fm-capacity test log with /usr/sbin off PATH (passes)

Source: fm-capacity test log with /usr/sbin off PATH (passes)

ok - absent config/lane-capacity reports counts and no target
ok - a target yields open lanes, full, and never a negative count
ok - cpu, memory, and disk pressure close every lane and are named
ok - unavailable probes print unknown and do not constrain
ok - a malformed target is reported, not guessed
ok - keyed config lines parse, and unknown, repeated, or malformed lines are refused
ok - a fresh beat replaces probes, and its warn level closes lanes with its reason
ok - late beats count, and stale, missing, malformed, or foreign beats fall back to probes
ok - several pressure files: worst level wins, first supplies memory, every disk counts
ok - a beat with missing fields keeps its fields aligned and limits fall back to probes
ok - the lane footprint memory rule applies only with min-avail-gb
ok - limits close lanes with named reasons, and --admit exits 0, 75, or 1
ok - publish is opt-in, private, throttled, records boots, and publishes an invalid config as invalid
ok - captain presence and quota runway publish derived words only, unknown when unreadable
ok - the watcher publishes lane facts only for an opted-in home
ok - real host probes produce a well-formed report
# all fm-capacity tests passed
Evidence: check-coverage failure output in the gate worktree

Source: check-coverage failure output in the gate worktree

fm-test-run: coverage guard: portable serial shards share scripts:
tests/fm-afk-contract.test.sh
tests/fm-backend-cmux-smoke.test.sh
tests/fm-backend-tmux-smoke.test.sh
tests/fm-backend-zellij-smoke.test.sh
tests/fm-backlog-read-bound.test.sh
tests/fm-bearings-snapshot.test.sh
tests/fm-calm-claude-mod-plugin.test.sh
tests/fm-calm-pi-queue-retention-live-e2e.test.sh
tests/fm-classify-corr-token.test.sh
tests/fm-classify-decision-key.test.sh
tests/fm-commandcode-harness.test.sh
tests/fm-daemon.test.sh
tests/fm-fork-free-helpers.test.sh
tests/fm-harness-adapter-instructions-live-e2e.test.sh
tests/fm-harness-precedence.test.sh
tests/fm-herdr-pi-stale-registration-live-e2e.test.sh
tests/fm-herdr-session-cleanup.test.sh
tests/fm-herdr-version-floor-live-e2e.test.sh
tests/fm-inactive-reconcile.test.sh
tests/fm-lint-workflows.test.sh
tests/fm-muse-harness.test.sh
tests/fm-opencode-primary-live-e2e.test.sh
tests/fm-project-mode.test.sh
tests/fm-quota-choose.test.sh
tests/fm-remote-backlog-handoff.test.sh
tests/fm-remote-herdr-guard.test.sh
tests/fm-remote-job.test.sh
tests/fm-rovo-harness.test.sh
tests/fm-secondmate-restart.test.sh
tests/fm-secondmate-sync.test.sh
tests/fm-session-lock-ancestry.test.sh
tests/fm-sessionstart-nudge.test.sh
tests/fm-shared-captain-inheritance.test.sh
tests/fm-spawn-compact-adviser-disable-remote.test.sh
tests/fm-startup-growth-check.test.sh
tests/fm-startup-network.test.sh
tests/fm-stat-shadowing.test.sh
tests/fm-supervision-host-attended-live-e2e.test.sh
tests/fm-task-inbox.test.sh
tests/fm-tool-update-check.test.sh
tests/fm-vendor-auth-probe.test.sh
tests/fm-voice-relay.test.sh
tests/fm-wake-drain-open-decisions.test.sh
tests/fm-wake-drain-outcome-backstop.test.sh
tests/fm-watch-checkpoint.test.sh
- Outcome: ⚠️ 2 issues (1 warning, 1 info) across 1 run (1h1m22s)

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** - 2 issues (1 warning, 1 info)
  • ⚠️ bin/fm-test-run.sh --check-coverage fails here with 'portable serial shards share scripts'. It failed on all 5 runs in this gate worktree, including under env -i. The same commit passes in 5 other copies, and the base commit 9d76aa8 passes 4/4 in clean copies. The copies were git archives, a no-.git copy, a copy with the .git pointer file, a linked worktree, a copy under a .no-mistakes/worktrees/... path, and a 160-character path. In-process enumeration inside the guard was inconsistent: two portable_serial_assignments calls in one process disagreed (227 lines with tests/fm-x-mode.test.sh vs 226 without). Standalone --list is stable at 226. I could not find the cause, so I am treating it as specific to this worktree and bash 3.2, not a defect in the rebased content. The guard needs to be confirmed in remote CI.
  • ℹ️ tests/fm-capacity.test.sh:471 - tests/fm-capacity.test.sh case 'unreadable presence and quota must read unknown' fails on this macOS host (got idle|unknown) because the real /usr/sbin/ioreg is on PATH after the test removes its fake ioreg. The test belongs to the carried feat(bin): add fm-capacity.sh to report open lanes and host headroom #6973 commits, which must stay unchanged. With /usr/sbin removed from PATH the whole file passes. Linux CI is unaffected.
  • Live validation: ✅ go - 5 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Runner test list keeps both sides of the merge, in sorted order, with nothing else changed ✅ pass live git diff 9d76aa8 HEAD -- bin/fm-test-run.sh adds fm-place.test.sh and fm-capacity.test.sh entries, and bin/fm-test-run.sh --list --all lists fm-place, polytoken-harness and polytoken-signals-live-…
fm-place advises placement from published lane facts: on, off, captain override, unknown home, missing facts, outcome and review, private decision log ✅ pass live fm-place-live.txt, fm-place-live2.txt, fm-place-live-invalid-config.txt. Statuses seen were ambiguous, full, captain and off; a missing-facts home was reported unknown. The decision log was mode 600.
fm-place behavior tests pass after the rebase ✅ pass live fm-place.test.log: all fm-place tests passed
fm-capacity tests pass after the rebase ✅ pass live fm-capacity.test.log has 1 failure on this macOS host, caused by the real ioreg on PATH. fm-capacity.noioreg.log passes with /usr/sbin off PATH.
Test-runner coverage guard accepts the rebased tree ✅ pass live Passes on 5/5 clean copies of the HEAD tree (git archive, no-.git copy, linked worktree, .no-mistakes path, long path). Fails 5/5 in the gate worktree itself, cause not found; see the warning finding.…
The carried #6973/#6983 commits are unchanged versus upstream ⏸️ untested no The worktree has no remote refs for PRs #6973/#6983, and I may not read the bare gate repo or fetch from the network. Compare patch-ids against the upstream PR heads, or let the outer executor do it,…
  • bash tests/fm-place.test.sh (exit 0, all tests passed)
  • bash tests/fm-capacity.test.sh (fails 1 host-dependent case on macOS; passes with /usr/sbin removed from PATH)
  • git diff 9d76aa8 HEAD -- bin/fm-test-run.sh to confirm the sorted list: tests/fm-place.test.sh 22000, then upstream's polytoken-harness 21090 and polytoken-signals-live-e2e 103, then tests/fm-pr-check-security.test.sh
  • bin/fm-test-run.sh --list --all | grep -E 'fm-place|polytoken' (all three scripts are scheduled)
  • bin/fm-test-run.sh --check-coverage in the gate worktree (failed 5/5) and in clean copies of HEAD (passed 5/5), plus the base commit in clean copies (passed 4/4)
  • Live bin/fm-place.sh runs against disposable lab homes (made with bin/fm-lab-home.sh, facts from bin/fm-capacity.sh --publish): invalid config rejected with exit 2, FM_PLACE=off, captain override, unknown home rejected, missing secondmate facts reported as unknown, outcome and review --json, decision log mode 0600
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

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. This PR's body says its goal is to update #6984. #6984 itself was force-pushed at 21:35 UTC (head 075b237e), and it now has this diff plus the ioreg stub fix in tests/fm-capacity.test.sh. That is the only difference between the two. So this PR looks superseded by #6984. Could you confirm and close this one, or tell me if you'd rather keep this one instead? I'm leaving both open until you say. The full review is on #6984 (#6984 (comment)).

Contract-class: opt-in (same diff as #6984). CI: same as #6984; serial 2 was cancelled at the 30-minute ceiling (#7255).

@Moshik21

Copy link
Copy Markdown
Contributor Author

Opened in error by our tooling; superseded by #6984, which carries the update.

@Moshik21 Moshik21 closed this Oct 20, 2026
@Moshik21
Moshik21 deleted the fm/fm-upstream-6984-rebase branch October 20, 2026 22:16
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks for confirming and closing this, @Moshik21. Really appreciate the quick answer. Review continues on #6984, which supersedes this one.

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