Skip to content

feat(fm-capacity): add opt-in max_fleet_agents machine-wide ceiling - #55

Merged
adibirzu merged 2 commits into
mainfrom
fm/fm-capacity-max-agents-knob
Sep 13, 2026
Merged

adibirzu merged 2 commits into
mainfrom
fm/fm-capacity-max-agents-knob

Conversation

@adibirzu

@adibirzu adibirzu commented Sep 13, 2026 •

Copy link
Copy Markdown
Owner

Add max_fleet_agents to config/spawn-capacity

What and why

The machine-capacity guard (bin/fm-capacity-lib.sh) weighs the fleet by memory
footprint, so a fleet of many small agents can sit well under the fleet-memory
limit. There is no knob for a machine-wide headcount ceiling, even though a home
may have a standing rule of that shape.

This adds one opt-in setting, max_fleet_agents. It is default OFF: absent or
off means no agent-count ceiling, exactly as today. A positive integer makes
the guard refuse a spawn when the machine-wide agent count is at or above it.
The counted figure is the same across N agents measurement the fleet-memory
signal already prints, so the knob and the printed row can never disagree about
what an "agent" is. The setting is generic and per-home; no host-specific value
is baked in.

Because the counted total comes from the same probe, an unreadable count follows
the existing on_unknown policy rather than silently passing.

Changes

  • bin/fm-capacity-lib.sh - new max_fleet_agents key (parse, default,
    evaluation row), documented in the header that owns the config format.
  • docs/configuration.md - operator-facing table row under "Machine capacity
    (config/spawn-capacity)".
  • tests/fm-spawn-capacity.test.sh - colocated coverage for the new gauge.

No existing gauge is disabled, loosened, or reordered.

Verification

Actions minutes are exhausted on this fork, so these local runs are the CI
evidence for this change.

tests/fm-spawn-capacity.test.sh

$ bash tests/fm-spawn-capacity.test.sh
ok - a crewmate spawn is declined when the machine has no headroom
ok - a scout spawn is declined when the machine has no headroom
ok - a secondmate spawn is declined when the machine has no headroom
ok - a spawn proceeds normally when the machine has headroom
ok - a refusal states every measured value against the value it wanted
ok - a refusal never stops, reaps, or edits work that is already running
ok - free memory, swap, kernel pressure, and fleet memory each decline a spawn on their own
ok - a high load average is reported as context and never refuses on its own
ok - an operator who wants a CPU-side ceiling can make load average a limit
ok - the fleet limit is on memory held, not on how many agents are running
ok - an absent agent ceiling leaves the machine-wide count uncapped
ok - an explicit off agent ceiling leaves the machine-wide count uncapped
ok - the agent ceiling refuses at or above the configured count with both numbers
ok - an agent count below the ceiling is admitted
ok - an unreadable agent count follows the configured unknown policy
ok - a non-positive agent ceiling is refused as malformed rather than silently accepted
ok - an unreadable signal is reported as unknown and declines rather than silently passing
ok - the operator can opt into proceeding when a signal cannot be measured
ok - a machine with no swap configured reads as a real answer, not an unreadable signal
ok - raising the limits in config/spawn-capacity admits work the defaults declined
ok - the operator can switch capacity checking off entirely
ok - malformed capacity settings refuse loudly instead of reverting to defaults
ok - the fleet probe counts every verified crewmate-only adapter
ok - the fleet probe counts interpreter-launched adapters and spaced paths, and not lookalikes
ok - a process table that cannot be read is an explicit unknown, never a fabricated zero
ok - the capacity report shows live numbers, and check exits non-zero without headroom
exit=0

Manual bin/fm-capacity.sh with the key set both ways

Measurements injected so the reading is deterministic. Same fleet count (4) in
both runs; only max_fleet_agents changes.

$ cat cap-on/spawn-capacity
max_fleet_agents = 4
$ bin/fm-capacity.sh check          # FM_CONFIG_OVERRIDE=cap-on
machine capacity: the machine has no headroom left on agents
  free memory      measured 8.0 GB of 16.0 GB installed (50%) | wanted at least 1.0 GB free  [ok]
  swap in use      measured 0.0 GB of 8.0 GB swap (0%), 0 swapouts since boot | wanted at most 50% of swap used  [ok]
  memory pressure  measured normal | wanted normal or better  [ok]
  fleet memory     measured 0.5 GB resident across 4 agents and their 8 processes (3% of installed memory) | wanted at most 40% of installed memory  [ok]
  fleet agents     measured 4 agents machine-wide | wanted fewer than 4 agents  [OVER]
  load per core    measured 0.12 per core (1m load 1.0 over 8 cores) | wanted context only - load also rises when memory is paging  [context]
  A spawn attempted now would be declined. Nothing already running is affected.
  Raise the limits or set mode = off in /tmp/opencode/cap-on/spawn-capacity to proceed anyway.
check exit=1

$ cat cap-off/spawn-capacity
max_fleet_agents = off
$ bin/fm-capacity.sh check          # FM_CONFIG_OVERRIDE=cap-off
machine capacity: headroom available
  free memory      measured 8.0 GB of 16.0 GB installed (50%) | wanted at least 1.0 GB free  [ok]
  swap in use      measured 0.0 GB of 8.0 GB swap (0%), 0 swapouts since boot | wanted at most 50% of swap used  [ok]
  memory pressure  measured normal | wanted normal or better  [ok]
  fleet memory     measured 0.5 GB resident across 4 agents and their 8 processes (3% of installed memory) | wanted at most 40% of installed memory  [ok]
  fleet agents     measured not checked | wanted not checked  [skipped]
  load per core    measured 0.12 per core (1m load 1.0 over 8 cores) | wanted context only - load also rises when memory is paging  [context]
check exit=0

bin/fm-lint.sh on the changed shell files

$ bin/fm-lint.sh bin/fm-capacity-lib.sh tests/fm-spawn-capacity.test.sh
fm-lint.sh: ShellCheck 0.11.0 (pinned 0.11.0)
fm-lint.sh: full ShellCheck extended analysis enabled
exit=0

Code Review (Stage 1)

$ bin/fm-review.sh worktree
# Code Review Verdict

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

- Files reviewable: 2 / 3
- Changes: +158 / -1 (159 lines)
- Linter: ran, 0 finding(s)
- LLM tokens: 0

No escalation: Stage 1 alone gates this change.

Code Review (Stage 2 - independent second-level review)

Independent second-level review by an OpenCode Go reviewer on a different model than the implementing worker (muse-spark reviewing deepseek), on branch commit 4b12144 against origin/main.

Verdict: PASS - correct, safe, minimal, well-tested, lint-clean; no defects; no changes requested.

Evidence: all 26 tests/fm-spawn-capacity.test.sh tests pass (including the 6 new agent-ceiling tests and every pre-existing test, no regressions); bin/fm-lint.sh exits 0 with pinned ShellCheck 0.11.0 and actionlint 1.7.12. The reviewer independently confirmed: the new gauge reuses the single fleet-agent measurement (no second definition of "agent"); the at-or-above boundary is correct; absent/off is identical to today; an unreadable count follows the existing on_unknown policy; no existing gauge is touched or reordered; the refusal leaves running work untouched; no host-specific value is baked in; the contract lives only in the bin/fm-capacity-lib.sh header and the single docs/configuration.md row. Full report: data/fm-pr55-second-level-review/report.md.

Code Review (Stage 2 - independent second-level review)

Independent second-level review by an OpenCode Go reviewer on a different model than the implementing worker (muse-spark reviewing deepseek), on the PR head against origin/main. Verdict: PASS - reviewed, no defects; full report: data/fm-pr55-second-level-review/report.md.

Add a max_fleet_agents setting to config/spawn-capacity, default off, that
refuses a spawn when the machine-wide agent count is at or above it. The
count is the same "across N agents" figure the fleet-memory signal
reports, so the knob and the printed row agree on what an agent is. An
unreadable count follows the existing on_unknown policy.

Covered by colocated tests for absent/off, at-or-above refusal with the
measured and wanted numbers, below-the-ceiling admission, unknown-policy
behavior, and malformed values.
@adibirzu adibirzu closed this Sep 13, 2026
@adibirzu adibirzu reopened this Sep 13, 2026
@adibirzu
adibirzu merged commit e11bb32 into main Sep 13, 2026
14 of 16 checks passed
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