Repository navigation
feat(bin): refuse a spawn whose brief's # Needs names a missing resource - #13
Merged
Merged
Conversation
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
force-pushed
the
feature/fm-spawn-preflight-p1
branch
from
October 16, 2026 11:49
72c8629 to
cf7dcfb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
bin/fm-spawn-preflight.sh, which reads a brief's optional# Needssection 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.shnow 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.# Needscontract indocs/configuration.md,docs/scripts.md,AGENTS.mdand thebin/fm-brief.shheader. Addedtests/fm-spawn-preflight.test.shand registered it inbin/fm-test-run.sh.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The change is opt-in: only briefs with a
# Needssection 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=2Evidence: Preflight behavior test output
Source: Preflight behavior test output
~/.no-mistakes/evidence/01M51XQKSGVMGXEN0R2G5N6CN5/sample)Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
ℹ️
bin/fm-spawn-preflight.sh:247-check_docker_networkstreats everydocker network createfailure 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'sdocker compose upcould fail during the probe window. Separately, the INT/TERM/HUP trap can leak one network if the signal lands afterdocker network createsucceeds 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 runsdocker 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: Paperonly checks that the process is running (pgrep -x). I confirmed the bundle executable is namedPaper, 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_networksdiscards stderr fromdocker network createand 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_assignssetsfound=1on any nonempty assignment and never clears it. A file withKEY=abcfollowed later byKEY=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- Thedocker info,docker runanddocker network createprobes have no timeout. They run inside fm-spawn before the spawn starts. If the Docker daemon is wedged or still starting (Docker Desktop can hangdocker 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 writtenManual run on the real host:bin/fm-spawn-preflight.shon 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 lineChecked that the transcript does not contain the env-file secret value (grep -c sk-secretreturned 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.shon a real machine against a satisfied brief (exit 0, silent)Manual:bin/fm-spawn-preflight.shon 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.shon a brief with a typo'd kinddockr-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.