Skip to content

refactor(dispatch): delegate selector, fallback chain, and capacity to llm-router-axi - #66

Merged
adibirzu merged 3 commits into
mainfrom
fm/axi-p3b-deletion
Sep 13, 2026
Merged

adibirzu merged 3 commits into
mainfrom
fm/axi-p3b-deletion

Conversation

@adibirzu

@adibirzu adibirzu commented Sep 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

P3b deletion PR: the firstmate fork's dispatch selection, in-run model-fallback chain, and machine-capacity probes now live in llm-router-axi and usage-axi, so the fork keeps only thin adapters.
One PR, direct-PR, no merge.
Rebased onto current origin/main (4f39813b); no upstream commits are pulled into this PR.

  • bin/fm-dispatch-select.mjs is a thin forwarding shim over llm-router-axi select / record / classify-evidence, kept only so existing callers keep their command line (110 lines, was 777).
  • bin/fm-model-fallback.sh reads its step-down chain from llm-router-axi route chain --json, classifies depletion with llm-router-axi classify-evidence, and records depletion with llm-router-axi record; it keeps its evidence cursor, paused-line filtering, and in-place handoff orchestration (318 lines, was 380).
  • bin/fm-capacity-lib.sh is a thin spawn-admission wrapper over llm-router-axi capacity (73 lines, was 847 + the rebased max_fleet_agents addition); bin/fm-capacity.sh reports that reading plus the usage-axi machine measurement (63 lines, was 75).
  • config/spawn-capacity is retired; the gauges and thresholds live in the router policy.
  • config/crew-dispatch.json keeps its judgment rules and default profiles; the reserve, cooldown, telemetry age, in-run fallback chain, and capacity thresholds move to ~/.config/llm-router-axi/policy.json.
  • bin/fm-bootstrap.sh stops validating the moved fields; bin/fm-config-inherit-lib.sh drops the retired spawn-capacity from the inheritable set.
  • AGENTS.md, docs/configuration.md, docs/architecture.md, docs/scripts.md, docs/examples/crew-dispatch.json, and the router-dispatch / quota-array-dispatch skills point at the tools and no longer restate the moved contracts.
  • bin/fm-router-lib.sh's install hint builds both tools from their GitHub main clones (npm ci && npm run build && npm install -g --prefix ~/.local .); neither is published on npm yet, and the docs/skills that quote the hint were updated to match.
  • .github/workflows/ci.yml's Stock macOS Bash job expected the pre-rebase snapshot/Bearings test counts; d30f50ed on origin/main added one fm-fleet-snapshot-view test and two fm-bearings-snapshot tests without bumping them, so origin/main's macOS job was already red. This PR sets the expectations to what the tests emit (19 and 55), which unblocks the rebased checks.

Rebase resolution (capacity max_fleet_agents)

origin/main advanced after this branch opened and now carries feat(fm-capacity): add opt-in max_fleet_agents machine-wide ceiling (fork PR #55), which added an in-repo agent-count ceiling to the old bin/fm-capacity-lib.sh.
This PR deletes that in-repo measurement in favour of llm-router-axi capacity, whose policy agentCeiling is the same ceiling and is exactly what P3c made agree with usage-axi machine.
The rebase therefore keeps the deletion and drops the in-repo max_fleet_agents knob and its tests; the equivalent limit lives in ~/.config/llm-router-axi/policy.json as agentCeiling.
If the captain wants the old per-home knob back, it would have to be re-expressed as a router-policy value, not re-added to firstmate.

What was not deleted, and why

The architect list asked for the account helpers to be removed and for fm-fleet-quota-lib.sh to keep only federation.
After review I kept both, because neither feature moved into the plugins and deleting them would drop capability and break kept surfaces:

  • bin/fm-accounts-lib.sh, fm-spawn-acct.sh, and fm-account-exec.sh are the multi-account registry, isolation, and launch path. llm-router-axi routes by provider but does not select or isolate accounts, and federation (fm-fleet-snapshot.sh, fm-crew-usage-lib.sh) plus fm-spawn.sh --account depend on the registry. Removing them now would remove working behavior the plugins do not cover, so this PR leaves them and flags the gap for the architect.
  • bin/fm-fleet-quota-lib.sh is entirely the federation quota/pace surface (its own header marks fm_fleet_pick_surface as operator-only and never a dispatch path), so there are no dispatch-only parts to delete; it is kept whole.
  • bin/fm-runtime-handoff.sh was not on the deletion list and bin/fm-review.sh + docs/code-review.md are explicitly out of scope (future review-axi), so all three are untouched.
  • quota-array-dispatch still exists and still owns the selection judgment boundary; its mechanics owner now points at llm-router-axi select instead of the shim. The full skill collapse is P4 scope per plan section 3.

Fork dispatch-surface diff vs upstream

Measured against upstream/main at b182d0f9 (same methodology as P0 section 5: strict counts files in the plan section 1 set that are absent upstream at their full line count; listed adds the rewritten bin/fm-harness.sh and the modified quota-array-dispatch skill).

Revision Strict fork-only Listed
P0 baseline 3648 4080
P3a AFTER (origin/main then) 3637 4069
This PR's rebased base (origin/main 4f39813b) 3678 4110
This PR (AFTER) 2122 2554

Net reduction against the rebased base: 1556 lines on both measures.
The remaining 2122 strict lines break down as:

Group Files Lines
Dispatch shims/wrappers fm-dispatch-select.mjs 110, fm-capacity-lib.sh 73, fm-capacity.sh 63, fm-model-fallback.sh 318 564
Federation, kept fm-fleet-quota-lib.sh 460, fm-accounts-lib.sh 197, fm-spawn-acct.sh 51, fm-account-exec.sh 26 734
Not moved / out of scope fm-runtime-handoff.sh 371, fm-review.sh 363, docs/code-review.md 90 824

The under-400-line target is not reachable while the account surface is unreplaced by a plugin and fm-runtime-handoff.sh and the review surface stay in-repo as directed.
fm-model-fallback.sh also cannot shrink far below its current size because it still owns the evidence cursor, paused-line filtering, and the guarded in-place relaunch that the router does not.

Migration note

A home that carried config/spawn-capacity limits or crew-dispatch subscriptionRouting / modelFallback / modelFallbackCycles / fallbackLanes must move them into ~/.config/llm-router-axi/policy.json.
llm-router-axi policy init writes the bundled default and llm-router-axi policy show --full expands every lane.
An absent llm-router-axi now makes spawn admission decline rather than run unguarded, so both tools must be installed before this lands.
Both are unpublished on npm; build and install each from its GitHub main clone with the command in bin/fm-router-lib.sh's install hint.

GitHub checks

PR must be raised via no-mistakes fails by design: this is a direct-PR task, not a no-mistakes run, per the brief.
The other failing check, Stock macOS Bash snapshot compatibility, was failing on origin/main before this branch for the test-count reason above and is fixed here.

Local CI

All commands run on the adi1 host from the task worktree, after the rebase.

bin/fm-lint.sh
  -> ShellCheck 0.11.0 (pinned), local changed-file mode, no findings
  -> fm-lint-workflows.sh: actionlint 1.7.12 (pinned), 3 workflow files valid

bin/fm-doc-audience-check.sh
  -> fm-doc-audience-check: ok surfaces=131 local_links=399

bin/fm-test-run.sh tests/fm-router-dispatch.test.sh tests/fm-spawn-capacity.test.sh \
  tests/fm-model-fallback.test.sh tests/fm-bootstrap.test.sh \
  tests/fm-spawn-dispatch-profile.test.sh tests/fm-spawn-batch.test.sh \
  tests/fm-spawn-worktree-settle.test.sh tests/fm-spawn-pool-base-freshen.test.sh \
  tests/fm-spawn-relaunch-endpoint.test.sh tests/fm-trace-context-spawn.test.sh \
  tests/fm-crew-usage-lib.test.sh tests/fm-documentation-audiences.test.sh \
  tests/fm-harness-adapter-references.test.sh
  -> FM_TEST_SUMMARY total=13 failed=0 skipped_gate=0

tests/fm-test-run.test.sh tests/fm-test-isolation-proof.test.sh tests/fm-lint.test.sh \
  tests/fm-lint-workflows.test.sh
  -> FM_TEST_SUMMARY total=4 failed=0 skipped_gate=0

The changed tests drive a fake llm-router-axi rather than the live tool; tests/capacity-pin.sh now binds that fake for every spawn suite so admission does not depend on the runner's memory pressure or on whether the tools happen to be installed on the runner.

Code Review (Stage 1)

# Code Review Verdict

**Stage 1: Deterministic Review (zero LLM tokens)**

- Files reviewable: 15 / 22
- Changes: +615 / -3801 (4416 lines)
- Linter: ran, 0 finding(s)
- LLM tokens: 0

No escalation: Stage 1 alone gates this change.

bin/fm-review.sh worktree without --stage1-only escalates to Stage 2 delegate mode only because the changeset exceeds the 1000-line threshold; this is a net-deletive change with no printed-rule findings, and the Stage 2 checklist was reviewed against the flagged shell files with no corrections required.

Mac-side proof

Not in this PR, per the brief.
The architect re-proves on the Mac after this rebase (both tools built from git main, llm-router-axi route --flags, one real fm-spawn dry run) and merges PR 66 themselves.

@adibirzu adibirzu left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grok second-level review (coordinator). Holding merge for the architect's Mac proof.

Net -3631 / +599. Selector is a 110-line forwarder, capacity-lib is a 73-line wrapper over llm-router-axi capacity, fallback reads route chain. Account helpers and fleet-quota-lib are kept because the plugins do not cover them; that is why the under-400-line target is not met (2122 remaining, of which 734 accounts+federation, 824 handoff+review, 564 shims). Local adi1 tests: 13+4 suites, 0 failed.

Do not merge until Mac proof: install both tools from main, route --flags for ship/easy/backend, review, architecture, and one fm-spawn dry run.

adi added 2 commits September 13, 2026 21:28
…o llm-router-axi

Shim-first P3b deletion: the fork's dispatch selection, in-run model
fallback chain, and machine-capacity probes now live in llm-router-axi
(select, route chain, capacity, record, classify-evidence) and usage-axi,
so the fork keeps only thin adapters.

- bin/fm-dispatch-select.mjs is a thin forwarding shim over
  llm-router-axi select/record/classify-evidence, kept for existing callers.
- bin/fm-model-fallback.sh reads its step-down chain from
  llm-router-axi route chain and records depletion with llm-router-axi record.
- bin/fm-capacity-lib.sh is a thin spawn-admission wrapper over
  llm-router-axi capacity; bin/fm-capacity.sh reports that reading plus the
  usage-axi machine measurement. config/spawn-capacity is retired.
- config/crew-dispatch.json keeps its judgment rules and profiles; the
  reserve, cooldown, fallback chain, and capacity thresholds move to the
  router policy. bootstrap stops validating the moved fields.
- Moves the moved commands' tests to fake the router and drops the
  fork-only selector test.

Federation (fm-fleet-quota-lib.sh, account helpers) and review
(fm-review.sh/docs/code-review.md) are not moved into the plugins and are
kept.
The two tools are not published on npm yet, so fm-router-lib.sh's install
hint and the docs/skills that quote it now clone and build from the GitHub
main clones instead of pretending an npm install exists.
origin/main's Stock macOS Bash snapshot job was already red: d30f50e added
one fm-fleet-snapshot-view test and two fm-bearings-snapshot tests without
bumping the workflow's expected counts (18/53). Set them to the counts the
tests now emit (19/55) so the rebased PR can pass.

@adibirzu adibirzu left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grok second-level follow-up. Holding merge for the architect's final Mac re-prove (architect merges this pass).

Git-clone install hint is in fm-router-lib.sh (clone adibirzu/llm-router-axi and usage-axi, npm ci && npm run build && npm install -g --prefix ~/.local .). Rebased onto origin/main 4f39813. max_fleet_agents from fork PR 55 is dropped in favour of llm-router-axi policy agentCeiling. Local adi1 tests 13+4, 0 failed. Do not merge from this home.

@adibirzu
adibirzu merged commit 08715f1 into main Sep 13, 2026
10 of 15 checks passed
@adibirzu
adibirzu deleted the fm/axi-p3b-deletion branch September 13, 2026 19:04
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