Skip to content

feat(bin): refuse a spawn whose brief's # Needs names a missing resource - #13

Merged
demy00 merged 1 commit into
mainfrom
feature/fm-spawn-preflight-p1
Oct 16, 2026
Merged

demy00 merged 1 commit into
mainfrom
feature/fm-spawn-preflight-p1

Conversation

@demy00

@demy00 demy00 commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Intent

The captain asked for a review of skill usage across recent worker PRs; its report is ~/Developer/agentic-dev/firstmate/data/pr-skill-usage-retro-r2/report.md. Firstmate then proposed building the firstmate-side recommendations from section 7 (recs 1, 6 and 9: refuse to start a worker whose instructions name no skills, check Docker disk, tools and credentials before starting a worker, and script the weekly skill table). The captain's answer, 2026-10-16: "build the firstmate improvements."

This task is recommendation 6: a spawn preflight for shared resources.

Substance of recommendation 6 from that report: before spawning a task that needs a stack, check Docker free disk and network room, the toolchain, Paper running for design tasks, and the named credentials, and refuse with one clear blocker line instead of a worker discovering it an hour in; where: bin/fm-spawn.sh or a per-project preflight script. Its evidence (report section 5, items 3 and 4): the Docker disk had 10.7 GB free against 12+ needed and the Docker network pool was full (37 networks), which blocked three fix workers; and workers found missing tools and credentials only mid-task - a Rust toolchain, an OpenRouter key, a demo login password, a mailbox password, and Paper Desktop closed or off screen for two design workers.

What Changed

  • Added bin/fm-spawn-preflight.sh, which reads a brief's optional # Needs section and checks each declared need: tools on PATH, environment variables (set directly or in an env file, value never printed), credential files, running apps (pgrep -x), free Docker disk (measured in a throwaway busybox container), and room for new Docker networks (it creates labelled probe networks and removes them). If anything is missing, it prints one stderr blocker line and exits 1. A malformed line exits 2 without running any check.
  • bin/fm-spawn.sh now runs the preflight on every fresh ship or scout spawn before any lock, worktree, or record exists, and refuses if it exits non-zero. Relaunches are exempt, and a brief without the section gets no checks.
  • Documented the # Needs contract in docs/configuration.md, docs/scripts.md, AGENTS.md and the bin/fm-brief.sh header. Added tests/fm-spawn-preflight.test.sh and registered it in bin/fm-test-run.sh.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change is opt-in: only briefs with a # Needs section are checked, only on fresh ship and scout spawns, and before any lock or record exists. Behavior tests cover it, and the remaining issues are minor diagnostic edge cases.

Testing

I ran the focused preflight test suite and all of it passed. It uses fake docker, pgrep and tmux to cover every need kind, the network-probe cleanup, Docker being down, and fm-spawn refusing before it creates anything. I also ran the real CLI on this machine against satisfied, missing and malformed sample briefs. The results were exit 0 (silent), exit 1 (one blocker line, no secret leaked) and exit 2 (line named). The sandbox blocked live Docker probes (they create real networks and containers), so Docker behavior is shown only through the faked-engine tests. This is a CLI change with no UI, so there are no screenshots.

Evidence: Real-machine preflight CLI transcript (ok / missing / malformed briefs)

Source: Real-machine preflight CLI transcript (ok / missing / malformed briefs)

$ bin/fm-spawn-preflight.sh sample/brief-ok.md exit=0 $ bin/fm-spawn-preflight.sh sample/brief-missing.md error: spawn preflight refused sample/brief-missing.md: tool cargo-fm-absent is not on PATH; environment variable FM_PREFLIGHT_UNSET_VAR is not set; DEMO_LOGIN_PASSWORD is not set in sample/demo.env; file ~/fm-absent-mailbox-password.txt is missing or empty; app FmAbsentPaperApp is not running exit=1 $ bin/fm-spawn-preflight.sh sample/brief-typo.md error: sample/brief-typo.md # Needs line '- dockr-disk: 12G' is not a valid need (kinds: tool, env, file, app, docker-disk, docker-networks; see bin/fm-spawn-preflight.sh --help) exit=2

$ bin/fm-spawn-preflight.sh sample/brief-ok.md
exit=0

$ bin/fm-spawn-preflight.sh sample/brief-missing.md
error: spawn preflight refused sample/brief-missing.md: tool cargo-fm-absent is not on PATH; environment variable FM_PREFLIGHT_UNSET_VAR is not set; DEMO_LOGIN_PASSWORD is not set in sample/demo.env; file ~/fm-absent-mailbox-password.txt is missing or empty; app FmAbsentPaperApp is not running
exit=1

$ bin/fm-spawn-preflight.sh sample/brief-typo.md
error: sample/brief-typo.md # Needs line '- dockr-disk: 12G' is not a valid need (kinds: tool, env, file, app, docker-disk, docker-networks; see bin/fm-spawn-preflight.sh --help)
exit=2
Evidence: Preflight behavior test output

Source: Preflight behavior test output

ok - a task that declares no needs gets no checks
ok - tool needs refuse only for a command missing from PATH
ok - env needs refuse for an unset or empty variable
ok - env-file needs check the named key is assigned without printing its value
ok - file needs refuse for a missing or empty file
ok - app needs refuse for a process that is not running
ok - docker-disk needs compare free space inside Docker with the declared size
ok - docker-networks needs prove the networks can be created and leave none behind
ok - Docker needs refuse when the engine is unreachable
ok - every missing need is named on one blocker line
ok - a malformed declaration exits 2 naming the line, before any check runs
ok - fm-spawn refuses a missing or malformed need before any endpoint exists
# all fm-spawn-preflight tests passed
  • Evidence: Sample briefs and env file used for manual run (local file: ~/.no-mistakes/evidence/01M51XQKSGVMGXEN0R2G5N6CN5/sample)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 3 infos
  • ℹ️ bin/fm-spawn-preflight.sh:247 - check_docker_networks treats every docker network create failure as an exhausted address pool and prints "address pool full". A daemon permission error, a name conflict or a plugin error would get the same wrong diagnosis in the blocker line. Fix: capture stderr and only say "address pool full" when the daemon says the pools are fully subnetted. Otherwise include the daemon's first error line.

  • ℹ️ bin/fm-spawn-preflight.sh:243 - The docker-networks probe briefly takes real slots from the shared Docker address pool before releasing them. The probe matters most when the pool is nearly full (the report saw 37 networks), and that is exactly when a running worker's docker compose up could fail during the probe window. Separately, the INT/TERM/HUP trap can leak one network if the signal lands after docker network create succeeds but before the name is added to PROBE_NETWORKS. The fm.preflight=1 label makes manual cleanup possible. This tradeoff is inherent to the documented design, since Docker does not expose pool capacity.

  • ℹ️ bin/fm-spawn-preflight.sh:221 - The docker-disk probe runs docker run busybox:1.36. If that image is not cached locally, the first spawn pulls it, which needs registry access and some disk. When Docker disk is nearly full (the exact case this check targets), the pull or container create can fail. The result is then the vaguer "could not be measured" instead of the free-space figure. The spawn still refuses, so this fails safe, but the blocker line is less useful.

  • ℹ️ bin/fm-spawn-preflight.sh:33 - The report's evidence includes Paper Desktop being "closed or off screen" for two design workers. app: Paper only checks that the process is running (pgrep -x). I confirmed the bundle executable is named Paper, so the check does match the app. Off-screen or no-open-file states are not covered. This is a reasonable scope limit, but the captain may expect it to be covered.

  • ℹ️ bin/fm-spawn-preflight.sh:263 - Still unaddressed from round 1. check_docker_networks discards stderr from docker network create and reports every failure as "address pool full". A permission error, name conflict or plugin error therefore gets the wrong diagnosis in the blocker line. Fix: capture stderr, say "address pool full" only when the daemon reports the pools are fully subnetted, and otherwise include the daemon's first error line.

  • ℹ️ bin/fm-spawn-preflight.sh:132 - env_file_assigns sets found=1 on any nonempty assignment and never clears it. A file with KEY=abc followed later by KEY= passes the check, but sourcing that file leaves KEY empty (the last assignment wins). Fix: track the last assignment, setting found to 1 for a nonempty value and 0 for an empty one.

  • ℹ️ bin/fm-spawn-preflight.sh:225 - The docker info, docker run and docker network create probes have no timeout. They run inside fm-spawn before the spawn starts. If the Docker daemon is wedged or still starting (Docker Desktop can hang docker info), the spawn hangs instead of refusing with a blocker line. This only affects briefs that declare docker needs.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-spawn-preflight.test.sh - all 12 cases pass, covering the tool, env, env-file, file, app, docker-disk and docker-networks checks (probe networks cleaned up), Docker unreachable, all missing needs on one line, malformed lines exiting 2, and fm-spawn ship and scout refusing before tmux is called or metadata is written
  • Manual run on the real host: bin/fm-spawn-preflight.sh on four briefs, against the real PATH, process table and Docker, where Docker was down and Paper closed. No-needs brief: exit 0. Brief with all needs met (cargo, OPENROUTER_API_KEY from an env file, a file): exit 0. Brief naming a missing tool, an empty DEMO_PASSWORD in the env file, an unset MAILBOX_PASSWORD, app Paper, docker-disk 12G and docker-networks 2: exit 1 with one line naming all five gaps. Typo - tol: cargo: exit 2 naming the line
  • Checked that the transcript does not contain the env-file secret value (grep -c sk-secret returned 0)

✅ No issues found.

  • bash tests/fm-spawn-preflight.test.sh (all 12 cases: no-needs, tool, env, env-file, file, app, docker-disk, docker-networks with cleanup, Docker unreachable, combined single blocker line, malformed exit 2, fm-spawn refusal before endpoint)
  • Manual: bin/fm-spawn-preflight.sh on a real machine against a satisfied brief (exit 0, silent)
  • Manual: bin/fm-spawn-preflight.sh on a brief with a missing tool, an unset env var, an empty env-file key, a missing credential file and an app that is not running (exit 1, one line naming all five, env-file secret value not printed)
  • Manual: bin/fm-spawn-preflight.sh on a brief with a typo'd kind dockr-disk (exit 2, names the bad line)
✅ **Document** - passed

✅ No issues found.

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

✅ No issues found.

A brief may declare the shared machine resources its task needs in a
top-level # Needs section: tools on PATH, environment variables,
credentials in an env file, credential files, running apps, free Docker
disk, and room for new Docker networks. bin/fm-spawn-preflight.sh owns
the section and its checks; fm-spawn.sh runs it on every fresh ship or
scout spawn before any lock, endpoint, worktree, or record exists, and
refuses with one blocker line naming every missing need. A brief that
declares nothing gets no checks.
@demy00
demy00 force-pushed the feature/fm-spawn-preflight-p1 branch from 72c8629 to cf7dcfb Compare October 16, 2026 11:49
@demy00
demy00 merged commit ff6f7f1 into main Oct 16, 2026
19 of 20 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.

1 participant