Skip to content

fix(bin): run one ShellCheck per CI lint partition and split lint into four partitions - #15

Merged
max-metaplanet merged 4 commits into
mainfrom
fm/lint-runner-capacity-2
Sep 26, 2026
Merged

max-metaplanet merged 4 commits into
mainfrom
fm/lint-runner-capacity-2

Conversation

@max-metaplanet

@max-metaplanet max-metaplanet commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Intent

The CI lint job runs at the edge of the GitHub runner's memory and gets killed. On the last green run of main (c48332b), lint partition 1 took 574s with 8.3GB peak memory in one ShellCheck worker and 13.7GB summed across workers; partition 2 took 531s with 12GB peak in one worker and 21GB summed, on a 16GB ubuntu-latest runner. On PR #12, the "Lint 2" job was killed twice with exit 143 at about 7m25s, with no findings printed, no GitHub cancellation, and a 30-minute job limit, while every other check passed; that PR only added two small files, which reshuffled the byte-weight partitioning (19 files moved out of partition 2, 18 in) and made partition 2 about 13% heavier. Any future PR that adds or removes files can tip a partition over the same way. That PR was merged with an explicit one-time waiver of that check. Fix the lint job so it stays well within runner memory, with the same lint rigor.

Scope note for the test step: verify behaviour with the lint unit tests (tests/fm-lint*.test.sh, including the test added by this change) plus at most one sanity run of the fixed code on a single partition. Do not rerun full base-versus-fix partition memory comparisons locally. The before/after memory and wall-time telemetry comes from this pull request's real CI run and belongs in the pull request description.

What Changed

  • bin/fm-lint.sh --partition now accepts any <n>of<total> value, not just 1of2/2of2. It rejects malformed or out-of-range values, and a missing value, with exit 2. The byte-weight packing now spreads roots across total partitions instead of a fixed two. In partition mode the script forces a single ShellCheck worker (JOBS=1), and neither --jobs 2 nor FM_LINT_JOBS=2 can override that. Lint runs outside partition mode still use two workers.
  • The CI lint matrix grows from two partitions to four (Lint 1 through Lint 4). The workflow comment names the matrix as the setting to raise when partitions get slow. CONTRIBUTING.md (required checks list) and docs/fm-test-portable-shards.md are updated to match.
  • New maintainer record docs/verification/lint-runner-memory.md, registered in docs/documentation-audiences.json. It holds the measurements behind the change: ShellCheck grows its memory to fill whatever the machine has, so two workers on one runner collide, and splitting roots per process does not lower the peak. tests/fm-lint.test.sh now checks that the four partitions together cover every canonical root with no overlaps, checks the new refusal cases, and adds a test that every partition run records jobs 1 in telemetry even when --jobs 2 or FM_LINT_JOBS=2 is set.

CI memory and wall time

Measured on this PR's own GitHub Actions run at e939f22a, against main at the merge base 65fc15d9.
Both used the pinned ShellCheck 0.11.0 on ubuntu-latest (16 GB).

Before, each partition ran two ShellCheck workers concurrently, so its summed figure is memory that could be live at the same moment:

Partition Roots Wall Max worker Summed (concurrent)
Lint 1 216 765s 11.57 GiB 16.77 GiB
Lint 2 216 351s 8.33 GiB 14.19 GiB

After, each partition runs a single ShellCheck, so its two shards are sequential and the max worker is the real instantaneous ceiling:

Partition Roots Wall Max worker (instantaneous ceiling) Summed (sequential, not simultaneous)
Lint 1 108 649s 12.55 GiB 16.29 GiB
Lint 2 108 629s 8.81 GiB 12.76 GiB
Lint 3 108 429s 5.75 GiB 10.57 GiB
Lint 4 108 387s 5.67 GiB 10.89 GiB

The summed column is no longer a safety number: with one worker the two shards never coexist, so it adds peaks reached at different times.
The number that matters is the instantaneous ceiling, which falls from about 16.8 GiB of concurrent demand on a 16 GB runner to 12.55 GiB in a single process that has no sibling to collide with.
Longest partition wall time falls from 765s to 649s, against a 30 minute job limit.

All four partitions passed, including the job that was previously killed with exit 143.

One caveat worth stating plainly: 12.55 GiB is 78% of the runner, which is consumption rather than requirement.
ShellCheck expands into whatever memory is free, and the same heaviest root completes cleanly at exactly 5.00 GiB when capped at 5 GiB.
With one process per runner there is no second process sizing itself to the whole machine, which is what produced the kills.

Why not a heap cap instead

A per-process GHC heap cap would bound memory without changing concurrency, and would have been the smaller change.
The pinned ShellCheck refuses it.
GHCRTS does reach the binary, since GHCRTS=--info prints the RTS table (GHC 9.8.2, vanilla non-threaded RTS), but both GHCRTS=-M6g and shellcheck --norc +RTS -M6g -RTS fail with:

shellcheck: Most RTS options are disabled. Link with -rtsopts to enable them.

That is why partition count carries the wall-time cost instead.
docs/verification/lint-runner-memory.md records the measurement and says to re-test after a ShellCheck upgrade, since a build linked with -rtsopts would make the cap the better fix.

Coverage

Coverage and rules are unchanged.
The same 432 canonical roots are linted, now 108 per partition across four partitions instead of 216 across two.
Severity, extended analysis, --external-sources and the ShellCheck version pin are all untouched, and no check is disabled or excluded.

Risk Assessment

✅ Low: The change is small and well-tested: each CI partition now runs one ShellCheck, partition parsing is generalized with correct validation and greedy balancing, and the CI matrix uses the existing job-total contract with the same roots and analysis settings; the only defect found is a stale error message.

Testing

I ran both lint unit test files, including the new single-worker partition test, and both passed. From the command line I checked that the four partitions cover the 432 canonical roots exactly once (108 roots each), and that malformed or weakened partition options are refused with exit 2. I then ran partition 2of4 once with real ShellCheck 0.11.0 while explicitly asking for 2 workers through both --jobs 2 and FM_LINT_JOBS=2. Telemetry showed jobs=1, full analysis, and exit 0. The run took 268s wall time, and the single worker peaked at about 3.9GB RSS on this macOS host. That number is only a local sanity figure because ShellCheck sizes its heap to the memory it can see. The before/after memory and wall-time comparison against the 16GB runner has to come from this PR's real CI run, as the intent specifies, so I did not repeat it locally. No transient files were left in the worktree.

  • Live validation: ✅ go - 4 of 6 scenarios driven live against the product
Scenario Result Live Evidence
A CI lint partition runs exactly one ShellCheck at a time even when a caller asks for 2 workers via --jobs 2 or FM_LINT_JOBS=2 ✅ pass live partition-2of4-telemetry.tsv shows jobs=1 for CI=true FM_LINT_JOBS=2 bin/fm-lint.sh --partition 2of4 --jobs 2; new unit test test_partition_runs_one_shellcheck_at_a_time passes
A real single-partition lint (2of4) completes with full source-aware analysis and exits 0 ✅ pass live partition-2of4-real-run.txt: 'full ShellCheck extended analysis enabled', workflows valid, exit=0, 277s wall time; telemetry analysis_mode=full
The four partitions together cover every canonical root exactly once, so lint rigor is unchanged ✅ pass live partition-cli-transcript.txt: 4 x 108 roots = 432 canonical total, 0 duplicated roots; test_canonical_partitions_preserve_full_lint passes
Adversarial: malformed or weakened partition requests (0of4, 5of4, of4, 1of, xof4, 1of4x, --fast, explicit path) are refused ✅ pass live partition-cli-transcript.txt: each option exits 2 with a clear error; unit test covers 2of1, 3of2, explicit subset
Non-partitioned canonical lint keeps its two bounded workers ⏸️ untested no The earlier payload checked this only with a unit test that uses a stub ShellCheck (test_partition_runs_one_shellcheck_at_a_time asserts jobs=2 for CI=true bin/fm-lint.sh). It recorded no live run.…
On a 16GB ubuntu-latest GitHub runner, every lint partition stays well within memory and is not killed with exit 143 ⏸️ untested no Needs this PR's real GitHub Actions run on ubuntu-latest. The only local evidence is a macOS sanity run, where one worker peaked at about 3.9GB RSS with workers run sequentially. ShellCheck sizes its…
Evidence: Partition CLI transcript (coverage, disjointness, refusals)

Source: Partition CLI transcript (coverage, disjointness, refusals)

partition 1of4:      108 roots
partition 2of4:      108 roots
partition 3of4:      108 roots
partition 4of4:      108 roots
canonical total:      432
duplicated roots: 0
--partition 0of4 -> exit 2 : fm-lint.sh: --partition must be <n>of<total> with 1 <= n <= total, got 0of4.
--partition 5of4 -> exit 2 : fm-lint.sh: --partition must be <n>of<total> with 1 <= n <= total, got 5of4.
--partition of4 -> exit 2 : fm-lint.sh: --partition must be <n>of<total> with 1 <= n <= total, got of4.
--partition 1of -> exit 2 : fm-lint.sh: --partition must be <n>of<total> with 1 <= n <= total, got 1of.
--partition xof4 -> exit 2 : fm-lint.sh: --partition must be <n>of<total> with 1 <= n <= total, got xof4.
--partition 1of4x -> exit 2 : fm-lint.sh: --partition must be <n>of<total> with 1 <= n <= total, got 1of4x.
fm-lint.sh: --partition requires full canonical lint; omit --fast and explicit paths.
--partition 1of4 --fast -> exit 2
Evidence: Real partition 2of4 lint run with /usr/bin/time -l

Source: Real partition 2of4 lint run with /usr/bin/time -l

$ CI=true FM_LINT_JOBS=2 /usr/bin/time -l bin/fm-lint.sh --partition 2of4 --jobs 2 --telemetry telemetry.tsv
fm-lint.sh: ShellCheck 0.11.0 (pinned 0.11.0)
fm-lint.sh: full ShellCheck extended analysis enabled
fm-lint-workflows.sh: actionlint 1.7.12 (pinned 1.7.12)
fm-lint-workflows.sh: 3 workflow files valid
      276.76 real       238.85 user        25.70 sys
          4023271424  maximum resident set size
                   0  average shared memory size
                   0  average unshared data size
                   0  average unshared stack size
             9534162  page reclaims
                2863  page faults
                   0  swaps
                   0  block input operations
                   0  block output operations
                   0  messages sent
                   0  messages received
                 193  signals received
               11068  voluntary context switches
              430922  involuntary context switches
          1202512460  instructions retired
           693886622  cycles elapsed
             3490272  peak memory footprint
exit=0
Evidence: Partition 2of4 telemetry (jobs 1 despite --jobs 2 / FM_LINT_JOBS=2)

Source: Partition 2of4 telemetry (jobs 1 despite --jobs 2 / FM_LINT_JOBS=2)

partition 2of4 jobs 1 analysis_mode full root_count 108 wall_seconds 268 max_worker_rss_kib 3928976 result_exit 0

format	fm-lint-telemetry-v1
git_head	ec11a2c04a488e98c7c8c46957eaaa88c063942a
content_cksum	3750214232-5248
shellcheck_version	0.11.0
analysis_mode	full
partition	2of4
jobs	1
root_count	108
direct_lines	74185
direct_bytes	3691670
source_directives	206
source_boundary_directives	31
source_followed_directives	175
source_target_count	55
shard_1_weight_bytes	1846225
shard_2_weight_bytes	1845445
wall_seconds	268
worker_wall_sum_seconds	267.43
max_worker_wall_seconds	176.78
user_seconds	235.58
system_seconds	22.63
max_worker_rss_kib	3928976
worker_rss_sum_kib	7108944
shellcheck_processes_start	0
shellcheck_processes_end	0
load_average_start	6.27/5.99/5.95
load_average_end	8.73/7.12/6.41
aggregate_cpu_percent_start	311.10
aggregate_cpu_percent_end	452.40
result_exit	0
Evidence: fm-lint unit test log

Source: fm-lint unit test log

ok - fm-lint.sh --help reports the complete executable interface
ok - fm-lint.sh --list-files reports the complete shell inventory
ok - canonical lint partitions preserve complete source-aware coverage and reject weakened modes
ok - a CI partition runs one ShellCheck at a time and no caller flag can raise it
ok - fm-lint.sh --fast disables ShellCheck extended analysis
ok - fm-lint.sh keeps full ShellCheck analysis by default in CI
ok - fm-lint.sh rejects explicit --fast mode in CI
ok - fm-lint.sh --fast catches an ordinary shell lint defect
ok - fm-lint.sh pins an explicit ShellCheck version (0.11.0)
ok - ShellCheck installer retries a transient download failure
ok - ShellCheck installer selects the official archive, URL, and checksum per OS/arch
ok - ShellCheck installer rejects a wrong checksum
ok - ShellCheck installer falls back to shasum -a 256 when sha256sum is absent
ok - ShellCheck installer prefers sha256sum when both hashers are present
ok - ShellCheck installer rejects an unsupported OS or architecture
ok - missing ShellCheck fails closed
ok - fm-lint.sh refuses to lint under a non-pinned ShellCheck version
ok - fm-lint.sh catches a real lint defect the old no-op gate passed
ok - fm-lint.sh rejects direct Beads CLI invocations in firstmate core
ok - fm-lint.sh enforces backend purity for explicit core paths
ok - fm-lint.sh ignores ambient ShellCheck options
ok - fm-lint.sh passes a clean fixture
ok - jobs=1 and jobs=2 preserve deterministic diagnostics, failures, cleanup bounds, and quiet telemetry
ok - jobs=1 and jobs=2 stop complete worker trees with and without telemetry
ok - seeded dispatcher, adapter, production-owner, and test-local diagnostics preserve parity
ok - fm-lint.sh changed mode lints only the changed canonical file
ok - fm-lint.sh forces a full lint in CI even when the local diff would be empty
ok - fm-lint.sh forces a full lint when HEAD is on main
ok - fm-lint.sh explicit paths bypass changed-file mode selection
ok - fm-lint.sh exits 0 with a note when the local branch has no changed lint targets
ok - fm-lint.sh --list-files reports the would-be changed set in changed mode
ok - fm-lint.sh changed mode drops source following and excludes cross-file codes
ok - fm-lint.sh changed mode invokes ShellCheck once per root
ok - fm-lint.sh CI keeps source following without the local exclusion list
ok - fm-lint.sh on main keeps source following without the local exclusion list
ok - fm-lint.sh without a merge-base keeps source following without the local exclusion list
ok - fm-lint.sh explicit paths keep source following
ok - fm-lint.sh --fast on a local branch keeps source following
ok - fm-lint.sh changed mode excludes cross-file codes that explicit paths still report
ok - local exclusion list covers every no-external-sources ShellCheck code
exit=0
Evidence: fm-lint-workflows unit test log

Source: fm-lint-workflows unit test log

ok - fm-lint-workflows.sh pins an explicit actionlint version (1.7.12)
ok - current .github/workflows YAML files parse
ok - column-0 heredoc workflow fails validation with a clear error
ok - valid fixture workflow passes
ok - empty workflows directory fails closed
ok - explicit malformed workflow path fails validation
ok - non-mapping workflow YAML root fails
ok - missing actionlint fails closed
ok - fm-lint-workflows.sh refuses to lint under a non-pinned actionlint version
ok - actionlint installer retries a transient download failure
ok - actionlint installer selects the official archive, URL, and checksum per OS/arch
ok - actionlint installer rejects a wrong checksum
ok - actionlint installer falls back to shasum -a 256 when sha256sum is absent
ok - actionlint installer prefers sha256sum when both hashers are present
ok - actionlint installer rejects an unsupported OS or architecture
ok - fm-lint.sh default path catches a self-broken ci.yml
exit=0

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • ℹ️ bin/fm-lint.sh:435 - Running --partition with no value still prints the old 'requires 1of2 or 2of2' message. The CI matrix now uses 1of4..4of4, so that message points users at a two-way split. It should match the new wording at line 475: 'requires <n>of<total>, such as 1of4'.
  • ℹ️ docs/verification/lint-runner-memory.md:20 - Evidence for the fix: one ShellCheck on the 16 GB runner peaked at about 11.6 GiB (12,128,056 KiB), which leaves roughly 4 GiB of headroom. The fix makes sure only one ShellCheck runs per runner, and it keeps full rigor: same roots, rules, source following, and extended analysis. How much headroom there really is gets confirmed by this PR's CI telemetry, which the intent assigns to the PR description. No code change needed.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 4 of 6 scenarios driven live against the product
Scenario Result Live Evidence
A CI lint partition runs exactly one ShellCheck at a time even when a caller asks for 2 workers via --jobs 2 or FM_LINT_JOBS=2 ✅ pass live partition-2of4-telemetry.tsv shows jobs=1 for CI=true FM_LINT_JOBS=2 bin/fm-lint.sh --partition 2of4 --jobs 2; new unit test test_partition_runs_one_shellcheck_at_a_time passes
A real single-partition lint (2of4) completes with full source-aware analysis and exits 0 ✅ pass live partition-2of4-real-run.txt: 'full ShellCheck extended analysis enabled', workflows valid, exit=0, 277s wall time; telemetry analysis_mode=full
The four partitions together cover every canonical root exactly once, so lint rigor is unchanged ✅ pass live partition-cli-transcript.txt: 4 x 108 roots = 432 canonical total, 0 duplicated roots; test_canonical_partitions_preserve_full_lint passes
Adversarial: malformed or weakened partition requests (0of4, 5of4, of4, 1of, xof4, 1of4x, --fast, explicit path) are refused ✅ pass live partition-cli-transcript.txt: each option exits 2 with a clear error; unit test covers 2of1, 3of2, explicit subset
Non-partitioned canonical lint keeps its two bounded workers ⏸️ untested no The earlier payload checked this only with a unit test that uses a stub ShellCheck (test_partition_runs_one_shellcheck_at_a_time asserts jobs=2 for CI=true bin/fm-lint.sh). It recorded no live run.…
On a 16GB ubuntu-latest GitHub runner, every lint partition stays well within memory and is not killed with exit 143 ⏸️ untested no Needs this PR's real GitHub Actions run on ubuntu-latest. The only local evidence is a macOS sanity run, where one worker peaked at about 3.9GB RSS with workers run sequentially. ShellCheck sizes its…
  • bash tests/fm-lint.test.sh (includes the new test_partition_runs_one_shellcheck_at_a_time and the updated test_canonical_partitions_preserve_full_lint) - exit 0
  • bash tests/fm-lint-workflows.test.sh - exit 0
  • bin/fm-lint.sh --partition {1..4}of4 --list-files compared against CI=true bin/fm-lint.sh --list-files for completeness and no duplicates
  • bin/fm-lint.sh --partition &lt;0of4|5of4|of4|1of|xof4|1of4x&gt; --list-files and --partition 1of4 --fast checked for refusal with exit 2
  • CI=true FM_LINT_JOBS=2 /usr/bin/time -l bin/fm-lint.sh --partition 2of4 --jobs 2 --telemetry ... - one real sanity run on a single partition with pinned ShellCheck 0.11.0
🔧 **Document** - 2 issues found → auto-fixed ✅
  • ⚠️ CONTRIBUTING.md:43 - The CI matrix now emits Lint 1 through Lint 4, and CONTRIBUTING.md now lists those as required contexts, but the GitHub main ruleset itself is repository configuration, not a committed file. A maintainer has to add Lint 3 and Lint 4 as required checks once this lands green, following the CONTRIBUTING.md procedure. Until then, those two partitions can fail without blocking a merge.
  • ℹ️ bin/fm-lint.sh:435 - When --partition is given with no value, the error still says 'requires 1of2 or 2of2', which no longer matches the &lt;n&gt;of&lt;total&gt; format (line 475 uses 'such as 1of4'). This is an executable message, so the document phase left it alone. It needs a one-line code fix.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…rocess

The lint partitions ran at the edge of the GitHub runner's memory and a
partition was killed outright when a two-file PR reshuffled the byte-weight
packing. In source-following mode a worker handed its whole shard to one
ShellCheck process, and that process keeps the heap its heaviest root needed
for as long as it runs, so each of the two concurrent workers held a worst-root
high-water mark for the length of the job.

Peak memory tracks the sourced-library fan-out rather than file size, so the
byte-weight packing that balances the shards cannot bound it, and any file
added or removed can regroup the roots and tip a partition over.

Analyze every root in its own process instead, which is what the
no-source-following path already did. A worker's peak is then one root's
analysis, measured across the canonical set at 4.07 GiB at most, and that bound
no longer depends on how roots are grouped. Coverage, rules, source following
and extended analysis are unchanged: ShellCheck reports findings only for the
root it was given, so the per-root and batched diagnostics are identical.
A lint partition was killed by the runner's OOM killer (exit 143, no findings
printed) whenever the byte-weight packing gave it two expensive shards.

ShellCheck sizes its heap to the memory it can see rather than to a fixed
per-root cost. The same root on Linux x86_64 is OOM-killed under a 3 GiB cap,
completes at exactly 5.00 GiB under a 5 GiB cap, uses 5.72 GiB under 7 GiB, and
reaches about 11.6 GiB on a 16 GB runner. Two workers sharing a runner both
expand toward the whole machine, which is the collision; one worker expands into
that same runner safely.

Because the heap follows available memory, no regrouping of roots can bound it:
giving every root its own process moved the runner's reported peak by 0.009%.
A per-process GHC heap cap would bound it without touching concurrency, but the
pinned binary rejects both GHCRTS=-M and +RTS with "Most RTS options are
disabled", so that lever is unavailable until ShellCheck ships -rtsopts.

Run a single ShellCheck per partition, and generalize --partition from the
hardcoded 1of2/2of2 to <n>of<total> so partition count is the dial that bounds
wall time. The CI matrix moves to four partitions to absorb the lost intra-job
concurrency. Coverage, rules, source following and extended analysis are
unchanged; --jobs and FM_LINT_JOBS can no longer raise a partition above one
worker.
@max-metaplanet max-metaplanet changed the title fix(bin): bound CI lint memory by analyzing one root per ShellCheck process fix(bin): run one ShellCheck per CI lint partition and split lint into four partitions Sep 25, 2026
@max-metaplanet
max-metaplanet merged commit 8105600 into main Sep 26, 2026
23 checks passed
max-metaplanet added a commit that referenced this pull request Oct 6, 2026
…o four partitions

Carried from fork commit 8105600 (#15).

The plan's step 9 said to prefer upstream here if upstream's work covers this
partitioning. It does not: upstream fixed the same memory problem from the other
side, by bounding each root's deadline and address space and retrying a root that
hits the ceiling without source following, but its `--partition` remains fixed at
`1of2|2of2` and its CI matrix remains two partitions.
This commit generalizes the partition count to `<n>of<total>` and runs one
ShellCheck per partition, which upstream does not do, so both land: upstream's
per-root envelope keeps a single root from running uncapped, and this commit's
one-worker-per-partition rule keeps two workers on one runner from each sizing a
heap to the whole machine and colliding with its OOM killer.

The script header states both: upstream's bounded workers and one-root-per-process
default, then this commit's generalized partition count and the reason a partition
runs one ShellCheck at a time.

docs/fm-test-portable-shards.md keeps upstream's per-root bounds sentence, its
per-root lifecycle sidecar, and its newer statement that the watch-triage floor
alone already exceeds the fifteen-minute objective, with this commit's
partition-count wiring, its pointer to the new memory verification record, and the
corrected sixteen-job layout.

`bin/fm-doc-audience-check.sh` passes, and the new verification record is
classified in the inventory.
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