Skip to content

fix(bin): fit ShellCheck extended analysis under the 4 GB lint cap - #3786

Open
ikehoff wants to merge 1 commit into
kunchenguid:mainfrom
ikehoff:fm/fm-lint-blowup-f3
Open

ikehoff wants to merge 1 commit into
kunchenguid:mainfrom
ikehoff:fm/fm-lint-blowup-f3

Conversation

@ikehoff

@ikehoff ikehoff commented Sep 5, 2026

Copy link
Copy Markdown

Intent

The captain suffered three machine-wide OOM crashes on 2026-09-04 caused by firstmate's lint suite (the captain calls it "spellcheck") running ShellCheck unbounded, and said: "ok we just suffered through three OOM crashes due to spellcheck being unbounded." A memory cap was added (#3685, ulimit -v around shellcheck in bin/fm-lint.sh, default 4 GB via FM_LINT_SHELLCHECK_MAX_MB), but the cap only turns the crash into a failed lint step: on unchanged main, ShellCheck's extended analysis of three scripts cannot complete under 4 GB.

Evidence from the previous task (a per-file bisect with shellcheck 0.11.0, --norc --external-sources, extended analysis on, one file per process):

  • bin/fm-spawn.sh: out of memory at 4 GB (completes at 8 GB)
  • bin/fm-teardown.sh: out of memory at 4 GB and at 8 GB (observed ~15 GB)
  • bin/fm-watch.sh: out of memory at 4 GB (completes at 8 GB)
  • every other file in that bisect finished in 1-3 s.
    GitHub CI runs the same full lint and passes, so the analysis does complete on runners with more memory. bin/fm-lint.sh --fast (extended analysis off) is clean.

The captain wants the full lint to be safe to run on a 24 GB machine: find what construct in those three scripts makes ShellCheck's extended analysis explode and restructure the scripts so the full lint completes under the 4 GB cap, without changing their behavior.

What Changed

Final changed paths and statuses:

M	.agents/skills/firstmate-coding-guidelines/SKILL.md
M	bin/backends/herdr.sh
M	bin/fm-afk-return.sh
M	bin/fm-bootstrap.sh
M	bin/fm-home-summary-refresh.sh
M	bin/fm-merge-outcome-lib.sh
M	bin/fm-pending-reply-lib.sh
M	bin/fm-public-followup-lib.sh
M	bin/fm-spawn.sh
M	bin/fm-teardown.sh
M	bin/fm-wake-lib.sh
M	bin/fm-watch.sh
M	tests/fm-pending-reply.test.sh

Risk Assessment

✅ Low: The only executable change is folding six identical lock wrappers into one shared wrapper whose dynamic-scope binding and positional-parameter pass-through I traced as equivalent to the inlined originals (fm-wake-lib and fm-parent-channel-lib use no top-level positional parameters or local/declare -g), everything else is ShellCheck directives and comments, and I confirmed the three named roots now lint clean under a 4 GB address-space limit.

Testing

Completed 1 recorded test check.

  • Outcome: ⚠️ 1 error across 1 run (32m2s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 issues (1 warning, 1 info)
  • ⚠️ bin/fm-spawn.sh:263 - The intent asks to "find what construct in those three scripts makes ShellCheck's extended analysis explode and restructure the scripts so the full lint completes under the 4 GB cap". The diagnosed cause is followed-source fan-out (each # shellcheck source= target inlined at every source site), and the only genuine restructuring is the pending-reply wrapper dedup. The rest of the reduction, including all of the savings in fm-spawn.sh, fm-teardown.sh, and fm-watch.sh, comes from converting followed sources to # shellcheck source=/dev/null analysis boundaries (spawn +5, teardown +6, watch +1, plus wake-lib, herdr, bootstrap, afk-return, merge-outcome, public-followup, home-summary-refresh). That is a lint-coverage tradeoff, not a script change: from those roots ShellCheck no longer sees the boundaried libraries' function and variable definitions, so cross-file checks (e.g. a misspelled fm_lock_* call or a lowercase variable read from fm-pr-lib/fm-busy-lib/fm-pending-reply-lib) are no longer caught at the root, and the new SKILL.md rule (line 122) institutionalizes boundaries as the standing remedy. Each library is still linted as its own root, and the same pattern already existed in 13 places on base, so this is a reasonable engineering choice, but it substitutes directives for the restructuring the intent describes and the author/captain should confirm the reduced cross-file analysis is acceptable. Verified independently: with --norc --external-sources and extended analysis on, fm-spawn.sh, fm-teardown.sh, fm-watch.sh, and fm-pending-reply-lib.sh now each complete in ~4-5 s under ulimit -v 4194304 with peak RSS of 1.67 GB, 1.04 GB, 1.17 GB, and 0.69 GB respectively.
  • ℹ️ .agents/skills/firstmate-coding-guidelines/SKILL.md:122 - The 4 GB ShellCheck cap this change targets (PR fix(bin): bound shellcheck memory per lint shard #3685, ulimit -v / FM_LINT_SHELLCHECK_MAX_MB in bin/fm-lint.sh) is still an open, unmerged PR; neither the base commit nor origin/main contains any ulimit in fm-lint.sh. Nothing in this branch enforces the budget the new SKILL.md rule and the source comments refer to, so the guideline currently describes a cap that only exists in a pending PR and in the captain's local checkout. This does not affect correctness of the change, but merge ordering matters: the guideline text and the "under the cap" claim become enforceable only once fix(bin): bound shellcheck memory per lint shard #3685 lands.
⚠️ **Test** - 1 error
  • 🚨 tests failed with exit code 1
  • bin/fm-test-run.sh --changed --exclude-family real-herdr-gated
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Sep 5, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge because no concrete changed-code defect remains after checking the wrapper equivalence and source-boundary changes.

The shared wrapper preserves all positional arguments, lock lifecycle, dynamic wake-library bindings, and body return codes, while the other script changes affect ShellCheck analysis directives rather than runtime sourcing.

Reviews (1): Last reviewed commit: "fix(bin): fit ShellCheck extended analys..." | Re-trigger Greptile

@ikehoff ikehoff changed the title chore: update pull request fix(bin): fit ShellCheck extended analysis under the 4 GB lint cap Sep 18, 2026
ShellCheck inlines every followed source at every source site and its
extended analysis keeps a full variables-in-scope map per control-flow
node, so memory grows with inlined lines times variables in scope. Six
production roots (spawn, teardown, watch, send, backlog-handoff,
procevent-remote-reply) exceeded the 4 GB cap on main, and three more sat
within 10 percent of it; the pending-reply library alone cost 2.0 GB
because six lock wrappers each re-sourced the wake library inside the
function body.

- fm-pending-reply-lib: fold the six identical per-correlation lock
  wrappers into one shared wrapper and load the wake and parent-channel
  libraries through two loader functions (same dynamic-scope binding and
  positional parameters as the inline sources); both loads are analysis
  boundaries.
- fm-wake-lib: the lazy classify and timeout loads are analysis
  boundaries, so consumers stop inlining the classifier graph.
- teardown, herdr backend, public-followup, merge-outcome, bootstrap,
  afk-return, home-summary-refresh: lazy or duplicate in-function wake
  library sources become analysis boundaries.
- spawn, teardown, watch: the largest already-canonical libraries they
  source stay analysis boundaries at the root.
- Two SC2034 suppressions where a variable is now consumed only behind a
  boundary; two SC2329 suppressions for test stubs reached through the
  shared wrapper's dynamic dispatch.
- firstmate-coding-guidelines: one source-graph budget rule.

All 167 production roots now complete under the cap (largest 1.8 GB);
the full lint passes with FM_LINT_JOBS=1. No runtime behavior changes.

Claude-Session: https://claude.ai/code/session_014f2aYxnXHTw4r9oeq3xxRP
@ikehoff
ikehoff force-pushed the fm/fm-lint-blowup-f3 branch from 5204d87 to 519ae5e Compare September 18, 2026 23:02
@ikehoff

ikehoff commented Sep 18, 2026

Copy link
Copy Markdown
Author

Rebased onto current main (daaffdb); conflicts resolved in .agents/skills/firstmate-coding-guidelines/SKILL.md, bin/fm-afk-return.sh, and bin/fm-spawn.sh (upstream had moved the config-inherit source and the in-function classify-lib load; the PR's analysis-boundary directives were reapplied at their new locations). One new SC2034 suppression in bin/fm-wake-lib.sh for the branch-owner sentinel read that upstream added on 2026-09-08, which the classify-lib boundary now exposes. No behavior change; bin/fm-lint.sh and the tests for the touched scripts pass.

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