Repository navigation
fix: bound ShellCheck to one canonical root per process - #5770
Merged
Merged
Conversation
CI job "Lint 1" died twice at about ten minutes because the two shard workers each packed about 110 canonical roots into one unbounded ShellCheck process, and a byte-weight rebalance moved the analysis-heavy fm-watch.sh into a partition with other heavy roots, so the pair outgrew the 16 GiB runner before anything could name a culprit. Run one canonical root per ShellCheck process under an enforced envelope: a wall deadline plus terminate-then-kill grace via the shared fm-timeout-lib.sh watchdog, and a per-root rlimit spec applied inside the child before exec (default a 4 GiB address-space cap, so two workers stay inside a 16 GiB job with headroom). A root that exceeds the envelope fails by name with a recorded reason - timeout, memory, signal, or limit-unavailable - instead of taking the runner down. The per-root watchdog runs in its own process group so the owner's group sweep cannot orphan the bounded subtree, and fm_exec_timed now starts the same escalation when its parent dies before it can be signalled. FM_LINT_REQUIRE_BOUNDS=1, set in CI, refuses the run outright when a configured bound cannot be enforced on the host rather than lint uncapped. Each root's begin/end, reason, duration, and peak RSS stream to stderr in partition mode and append to a retained <telemetry>.roots.tsv sidecar uploaded beside the partition telemetry. Coverage is unchanged: pinned ShellCheck 0.11.0, --norc, --external-sources full analysis, complete and disjoint partition inventory, workflow lint, and the backend-purity check, with byte-identical diagnostics across jobs=1/2 proven by tests/fm-lint.test.sh.
Required-bounds mode (FM_LINT_REQUIRE_BOUNDS=1, set by CI) now refuses the run with named errors before any root starts: a missing fm-timeout-lib.sh, a watchdog that cannot actually bound a probe command, or a host that rejects the address-space limit all stop the run rather than lint uncapped. The generalized FM_LINT_ROOT_RLIMITS flag:value interface is replaced by a single FM_LINT_ROOT_MEMORY_KIB, and the roots sidecar and telemetry record the run's final exit status after backend-purity and workflow checks instead of the pre-check lint status. The default cap is 6 GiB of address space per root, not 4 GiB: ulimit -v bounds virtual address space rather than resident memory, and ShellCheck's GHC runtime keeps roughly a third of that space as reservation, so 6 GiB yields about a 4 GiB working heap budget. A Linux measurement during this change showed eleven real canonical roots running out of memory under the earlier 4 GiB cap while the largest passing root peaked near 2.8 GiB resident; two 6 GiB roots plus runner overhead still fit the 16 GiB job. Roots that still exceed the cap keep failing by name, and the sidecar's per-root peak RSS keeps roots approaching the budget visible. tests/fm-lint.test.sh now proves the memory primitive where it can be proven: on hosts that accept ulimit -v a perl allocator is refused under a 256 MiB limit and reported by name as a memory death, the pinned ShellCheck lints a small file under the configured cap and is named when a far smaller cap binds it, and a watchdog-less copy refuses under REQUIRE_BOUNDS; the bounded cases skip on macOS, which cannot enforce the address-space limit.
…fm_exec_timed caller
The pipeline's document step rewrote the ROOT_MEMORY_KIB comment and dropped the sizing reasoning the change is required to record: address space vs resident memory, the GHC reservation share, the measured 4 GiB failures and ~2.8 GiB peak, and the two-roots-plus-runner capacity arithmetic. Restore it beside the default while keeping the corrected "not a resident-memory ceiling" framing.
…on: the watchdog now reaps an engine when its host dies. The timeout and supervision-host tests pass locally; the watcher test also passes locally. Lint 1 and 2 remain unresolved: seven canonical roots exceeded the required 6 GiB address-space cap in CI. I did not raise the cap, exempt roots, or reduce source-following coverage to make those failures disappear
…s hit the enforced memory cap. I reduced repeated ShellCheck source-graph expansion while keeping runtime imports and the canonical root inventory intact. Pinned ShellCheck passes for all changed roots; the relevant local tests pass. The 6 GiB Linux CI run remains unverified
kunchenguid
force-pushed
the
fm/fm-lint-bounded-roots-r1
branch
from
September 26, 2026 10:57
6bf3a2e to
86139b1
Compare
…I lint job now runs one root at a time with a 12 GiB address-space cap. Kept the local two-worker default and updated the sizing comment and test expectation. The lint tests and workflow validation pass locally; Linux CI remains to confirm the heavy roots
This was referenced Sep 26, 2026
wpartin
added a commit
to wpartin/firstmate
that referenced
this pull request
Sep 27, 2026
* docs: make configuration settings easier to find and understand (#5589) * docs: make configuration settings easier to find and understand * no-mistakes(review): Restore dropped qualifiers and fix misplaced config doc labels * no-mistakes(review): Restore three dropped qualifiers in configuration reference * fix: limit project memory edits to factual corrections (#5636) * fix: bound worker edits of project AGENTS.md/CLAUDE.md to factual corrections These files are loaded into every agent session of a project, so additions should be a deliberate human choice rather than automated task output. The ship brief's project-memory section and AGENTS.md section 6 previously invited workers to record durable knowledge, which let project AGENTS.md files accrete detail the codebase or README already carries. Workers now edit only to fix factually wrong content - including content their own change made wrong - and fm-ensure-agents-md.sh runs only alongside such a correction. Stow no longer routes project-memory additions through ship tasks, and the generated skeleton no longer invites discovery-driven additions. * no-mistakes(review): Stop running fm-ensure-agents-md.sh on memory-file corrections * no-mistakes(document): Clarify manual project-memory initialization and remove duplicate guidance * feat: permit gate lifecycle calls against disposable lab homes (#5635) * fix(bin): let gate agents drive lifecycle against marked lab homes Part 2 of the #5615 split. A no-mistakes gate agent runs inside a checkout carrying the fleet-captain identity, so fm-gate-refuse-lib refuses fleet mutation on the gate signal. That refusal was absolute, which kept gate validation from ever exercising the real lifecycle. Stamp a disposable lab FM_HOME with a .fm-lab-home marker file that only bin/fm-lab-home.sh writes, and only onto a fresh empty dir, so no call path can mark a populated real home. fm_refuse_if_gate_agent then permit
Intent
Ask firstmate to scope the bounded lint change first.
Context: that was the captain's answer on the review board for the CI reliability scout's report (data/fm-ci-resource-flake-structure-s1/report.md), and the main firstmate then asked for it as a ship: implement the report's first recommendation only - run ShellCheck per canonical root under enforced per-process memory and time limits (at most two per job, same flags) with lint coverage unchanged, so an oversized script fails clearly instead of killing the runner. The other recommendations stay out of scope.
Substance of that first recommendation (R1): the worked example is CI job "Lint 1" killed twice at about 10.5 minutes on PR #5732 - bin/fm-lint.sh packs about 110 roots into each of two shard processes by byte weight, and a small change moved the analysis-heavy bin/fm-watch.sh into the same partition as other heavy roots, so the two unbounded ShellCheck processes outgrew the 16 GiB runner. R1 changes bin/fm-lint.sh itself (no new scheduler or service): one full-source-aware root per ShellCheck process in each existing worker, fixed maximum concurrency two, a hard memory limit, a wall deadline, and a short terminate/kill cleanup bound; keep the exact pin, --norc, full dataflow, source-following policy, complete and disjoint inventory, workflow lint, and purity check. The chosen envelope is a 6 GiB virtual-address-space cap per root (FM_LINT_ROOT_MEMORY_KIB=6291456): ulimit -v caps address space, not resident memory, ShellCheck's GHC runtime reserves roughly a third of it, so 6 GiB is about a 4 GiB usable heap budget; measured on Linux, eleven canonical roots OOM'd under 4 GiB while the largest passing root peaked near 2.8 GiB RSS, and two 6 GiB caps plus runner overhead fit the 16 GiB job. That reasoning must stay documented beside the default and in the PR. Roots that still exceed the cap fail by name - no exemptions; the roots sidecar records peak RSS, and roots peaking above about 3 GiB resident are reduction candidates (fm-pending-reply-lib.sh first). Verify the enforcement primitive actually works with the pinned Linux ShellCheck (an inherited address-space limit, or if that is unsuitable a standard Linux cgroup memory ceiling); if enforcement is unavailable, report it rather than running uncapped. Emit each root's mode, start, completion, exit reason, duration, and RSS incrementally plus a retained sidecar, distinguishing timeout, memory limit, signal, and lint findings. Verification: prove canonical root union/disjointness and diagnostic/exit parity at jobs 1 and 2 with small real fixtures; a tiny controlled allocator under a tiny limit plus a separate blocked child show the parent reports the failing root, reaps owned children, preserves completed evidence, and leaves an unrelated sentinel alive; the real heavy roots are measured only in CI.
What Changed
Risk Assessment
✅ Low: The bounded-root change and recorded repairs have no further source-backed material finding in this review; runtime and CI validation belong to later pipeline phases.
Testing
Live CLI checks confirmed disjoint canonical partitions, identical diagnostics and exits with one or two jobs, correct findings versus filename-based OOM classification, macOS fail-closed behavior, and a successful bounded Linux root. A controlled allocator confirmed the Linux limit binds, and the watchdog reaped a blocked child without killing a sentinel. The targeted watchdog tests passed. The available Linux images lack
/usr/bin/time, so their retained sidecars could not demonstrate numeric peak RSS; no UI surface was changed./usr/bin/time, which this product uses for peak RSS. Provide a Linux test image or CI runner with GNU time and rerun the bounded root.Evidence: Partition inventory
Source: Partition inventory
Evidence: One-versus-two-job diagnostic parity
Source: One-versus-two-job diagnostic parity
Evidence: OOM-text classification and fail-closed CLI output
Source: OOM-text classification and fail-closed CLI output
Evidence: Echoed OOM source excerpt remains findings
Source: Echoed OOM source excerpt remains findings
Evidence: Bounded Linux root and allocator control
Source: Bounded Linux root and allocator control
Evidence: Linux watchdog child and sentinel
Source: Linux watchdog child and sentinel
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed (6) ✅
bin/fm-lint.sh:870- The intent says roots peaking above about 3 GiB RSS are reduction candidates, with fm-pending-reply-lib.sh first, and requires the sizing rationale beside the default. This new comment says only “approaching the budget,” omitting the threshold and first candidate. Add that decision beside ROOT_MEMORY_KIB.🔧 Fix applied.
1 warning still open:
bin/fm-timeout-lib.sh:247- Round 2's owner-startup fix left the GNU timeout fallback behind. When Perl is unavailable, an intended direct caller such as bin/fm-supervision-engine-lib.sh:334 or bin/fm-backlog-transition-lib.sh:340 can die after launching fm_exec_timed; the fallback ignores the captured owner PID, so its child can run until the full deadline. The explicit fallback test at tests/fm-timeout-lib.test.sh:267 confirms this path is supported. The remedy needs a decision: preserving owner-death cleanup here would require changing or removing the deliberate Perl-free fallback.🔧 Fix applied.
✅ Re-checked - no issues remain.
bin/fm-timeout-lib.sh:215- If CI cancellation reaches a lint worker after the Perl watchdog forks a root but before it installs signal handlers at line 221, the worker's trap kills the watchdog at bin/fm-lint.sh:124. Default TERM handling exits immediately, leaving the separately grouped root running without a watchdog or cleanup bound. Install the watchdog's signal handling before the fork, or otherwise protect this startup window.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ No issues found.
bin/fm-spawn.sh:586- The intent requires the source-following policy and lint coverage to remain unchanged. Commit 42699d1 replaces source targets withsource=/dev/null, so ShellCheck no longer analyzes those imports in the importing root's context; linting each imported file as a separate canonical root does not restore that cross-file analysis. The same change occurs at bin/fm-spawn.sh:588, :596, :608; bin/fm-backlog-handoff.sh:95; bin/fm-teardown.sh:351, :357; bin/fm-watch.sh:216; tests/fm-launch-prompt-signals-live-e2e.test.sh:83; tests/fm-pending-reply.test.sh:625, :789; and tests/fm-stat-shadowing.test.sh:130. These new suppression paths exceed the bounded-execution scope. Remove them rather than weakening the required policy to make roots fit the cap.bin/fm-lint.sh:169- A bounded ShellCheck process that prints an out-of-memory error and exits 1 is recorded asfindingsbefore its output is examined at line 186. An OOM-terminated process exiting 137 is likewise recorded assignal:KILLat line 180 before that check. Both paths lose the required distinction between memory-limit failures, lint findings, and signals. Check explicit memory-failure evidence before assigning those generic reasons.🔧 Fix applied.
3 issues (1 error, 2 warnings) still open:
bin/fm-spawn.sh:586- The intent requires the source-following policy and lint coverage to remain unchanged. Commit 42699d1 replaces source targets withsource=/dev/null, so ShellCheck no longer analyzes those imports in the importing root's context; linting each imported file as a separate canonical root does not restore that cross-file analysis. The same change occurs at bin/fm-spawn.sh:588, :596, :608; bin/fm-backlog-handoff.sh:95; bin/fm-teardown.sh:351, :357; bin/fm-watch.sh:216; tests/fm-launch-prompt-signals-live-e2e.test.sh:83; tests/fm-pending-reply.test.sh:625, :789; and tests/fm-stat-shadowing.test.sh:130. These new suppression paths exceed the bounded-execution scope. Remove them rather than weakening the required policy to make roots fit the cap.bin/fm-lint.sh:169- A bounded ShellCheck process that prints an out-of-memory error and exits 1 is recorded asfindingsbefore its output is examined at line 186. An OOM-terminated process exiting 137 is likewise recorded assignal:KILLat line 180 before that check. Both paths lose the required distinction between memory-limit failures, lint findings, and signals. Check explicit memory-failure evidence before assigning those generic reasons.bin/fm-lint.sh:181- Round 7's OOM-classification fix can mistake an echoed source line for a runtime error. A root containing a line such asshellcheck: out of memoryalongside an ordinary ShellCheck finding exits 1, but the echoed line matches this regex and the sidecar reportsmemoryinstead offindings. The unrestricted output match at bin/fm-lint.sh:188 has the same source-text risk for other nonzero exits. Distinguish ShellCheck's diagnostic source excerpts from process errors before assigning the memory reason.🔧 Fix applied.
4 issues (1 error, 3 warnings) still open:
bin/fm-spawn.sh:586- The intent requires the source-following policy and lint coverage to remain unchanged. Commit 42699d1 replaces source targets withsource=/dev/null, so ShellCheck no longer analyzes those imports in the importing root's context; linting each imported file as a separate canonical root does not restore that cross-file analysis. The same change occurs at bin/fm-spawn.sh:588, :596, :608; bin/fm-backlog-handoff.sh:95; bin/fm-teardown.sh:351, :357; bin/fm-watch.sh:216; tests/fm-launch-prompt-signals-live-e2e.test.sh:83; tests/fm-pending-reply.test.sh:625, :789; and tests/fm-stat-shadowing.test.sh:130. These new suppression paths exceed the bounded-execution scope. Remove them rather than weakening the required policy to make roots fit the cap.bin/fm-lint.sh:169- A bounded ShellCheck process that prints an out-of-memory error and exits 1 is recorded asfindingsbefore its output is examined at line 186. An OOM-terminated process exiting 137 is likewise recorded assignal:KILLat line 180 before that check. Both paths lose the required distinction between memory-limit failures, lint findings, and signals. Check explicit memory-failure evidence before assigning those generic reasons.bin/fm-lint.sh:181- Round 7's OOM-classification fix can mistake an echoed source line for a runtime error. A root containing a line such asshellcheck: out of memoryalongside an ordinary ShellCheck finding exits 1, but the echoed line matches this regex and the sidecar reportsmemoryinstead offindings. The unrestricted output match at bin/fm-lint.sh:188 has the same source-text risk for other nonzero exits. Distinguish ShellCheck's diagnostic source excerpts from process errors before assigning the memory reason.bin/fm-lint.sh:181- Round 8's stderr-only fix still matches arbitrary stderr text. Linting a nonexistent explicit path namedout of memory.shmakes ShellCheck include that filename in its file-open error; the substring match recordsreason=memoryalthough no allocation failed. Match runtime memory errors rather than an OOM phrase anywhere in stderr.🔧 Fix applied.
1 error still open:
bin/fm-spawn.sh:586- The intent requires the source-following policy and lint coverage to remain unchanged. Commit 42699d1 replaces source targets withsource=/dev/null, so ShellCheck no longer analyzes those imports in the importing root's context; linting each imported file as a separate canonical root does not restore that cross-file analysis. The same change occurs at bin/fm-spawn.sh:588, :596, :608; bin/fm-backlog-handoff.sh:95; bin/fm-teardown.sh:351, :357; bin/fm-watch.sh:216; tests/fm-launch-prompt-signals-live-e2e.test.sh:83; tests/fm-pending-reply.test.sh:625, :789; and tests/fm-stat-shadowing.test.sh:130. These new suppression paths exceed the bounded-execution scope. Remove them rather than weakening the required policy to make roots fit the cap.✅ No issues found.
ulimit -vrefusal and exit 2 on macOSbash tests/fm-timeout-lib.test.shexercised real child processes and the Perl watchdog; timeout-targeted-tests.txt/usr/bin/time, which this product uses to measure root RSS. Provide a Linux test environment with GNU/usr/bin/timeand rerun the bounded fixture.bash tests/fm-lint.test.shbash tests/fm-timeout-lib.test.shCI=true bin/fm-lint.sh --list-filesand both--partition ... --list-filesselectionsRan clean and defective fixtures throughbin/fm-lint.sh --telemetryon macOS and withFM_LINT_REQUIRE_BOUNDS=1in LinuxRan a controlled allocator with and without a 32 MiB limit, then pinned ShellCheck with a 6 GiB limit, through the Linux product entry pointConfirmed required bounds refuse to lint on this macOS hostLive validation:⚠️ inconclusive - 4 of 5 scenarios driven live against the product
bash tests/fm-timeout-lib.test.sh: real child-process deadline, TERM forwarding, grace, and owner-death checks passedulimit -v; provide a Linux runner with the pinned ShellCheck to exercise the CI address-space limit and GNU time RSS measurement.bash tests/fm-timeout-lib.test.shbash tests/fm-lint.test.shbin/fm-lint.sh --partition 1of2 --list-filesand--partition 2of2 --list-files, compared with the canonical shell inventorybin/fm-lint.sh --telemetry … clean.sh defect.sh, compared with pinnedshellcheck --norc --external-sourcesFM_LINT_REQUIRE_BOUNDS=1 bin/fm-lint.sh --telemetry … clean.shon macOSLive validation:⚠️ inconclusive - 5 of 6 scenarios driven live against the product
/usr/bin/time, which the product uses for per-root RSS. Provide a Linux runner or disposable image with GNU time to verify the numeric record.bash tests/fm-lint.test.shbash tests/fm-timeout-lib.test.shbin/fm-lint.sh --partition {1of2,2of2} --list-fileswith canonical union and overlap comparisonFM_LINT_JOBS={1,2} bin/fm-lint.sh --telemetry ... <clean> <bad>using pinned ShellCheckFM_LINT_REQUIRE_BOUNDS=1 bin/fm-lint.sh <clean>on macOS and in a disposable Linux containerLinux pinned-ShellCheck run under the default and an 8 MiB address-space cap; controlled allocator with and without a 256 MiB capDirectfm_exec_timed 1 1deadline check with an unrelated sentinelLive validation:⚠️ inconclusive - 5 of 7 scenarios driven live against the product
/usr/bin/time, which the product uses for peak-RSS capture. Provide a Linux test image with GNU/usr/bin/timeand rerun the bounded-root scenario.bin/fm-lint.sh --list-filesfor the full inventory and both CI partitionsbin/fm-lint.sh --jobs 2 --telemetry …with real clean, findings, and missing-path fixturesFM_LINT_REQUIRE_BOUNDS=1 bin/fm-lint.sh …on macOS and in a Linux container with pinned ShellCheck 0.11.0Focusedtests/fm-lint.test.shscenarios for deadline cleanup, memory refusal, classification, sidecar status, and the pinned memory envelopeLinux allocator control and 64 MiB address-space-limit checkLive validation:⚠️ inconclusive - 6 of 7 scenarios driven live against the product
/usr/bin/time, which this product uses for peak RSS. Provide a Linux test image or CI runner with GNU time and rerun the bounded root.bin/fm-lint.sh --list-filesfor the full inventory and both partitionsCI=true FM_LINT_JOBS={1,2} bin/fm-lint.sh --telemetry ...on real clean and finding-producing rootsFM_LINT_REQUIRE_BOUNDS=1 bin/fm-lint.shon macOS and in an isolated Linux container with pinned ShellCheck 0.11.0Controlled Python allocation with and without a Linux address-space limitDirectfm_exec_timed 1 1blocked-child and unrelated-sentinel checkbash tests/fm-timeout-lib.test.sh✅ **Document** - passed
✅ No issues found.
✅ No issues found.
✅ No issues found.
✅ No issues found.
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ No issues found.
✅ No issues found.
✅ No issues found.
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
✅ No issues found.
✅ No issues found.
✅ No issues found.
✅ No issues found.
CI lint evidence (run 36238728012)
Final envelope: one root at a time per CI lint job under a 12 GiB virtual-address-space cap (
FM_LINT_ROOT_MEMORY_KIB=12582912; GHC reserves roughly a third of address space, so ~8 GiB usable heap). Sizing was measured, not assumed: x86_64 pinned ShellCheck 0.11.0 runs hungrier than the earlier aarch64 estimate - under a 6 GiB cap seven roots died at the ~4.0 GiB usable-heap wall, and under 8 GiB four roots died at the ~5.33 GiB wall. One serialized root per job keeps worst-case resident use at ~8 GiB plus runner overhead, inside the 16 GiB runner.reason=okunder the cap; zero timeouts, zero memory deaths; runners stayed alive; per-root telemetry + roots sidecars uploaded.bin/fm-teardown.shat 7,171,340 KiB (~6.84 GiB) - a 10 GiB cap would still have caught it, which is why the cap is 12 GiB.Roots peaking above ~3 GiB RSS (reduction candidates, in order;
fm-pending-reply-lib.sh's dedup fix already landed via #5753):Interim finding worth noting: the runner also proved the fail-by-name contract mid-run - under the earlier 6 GiB cap the same jobs named each over-cap root (
reason=memory, rc=251) and the runner survived both times.