Skip to content

fix(bin): stop no-mistakes status probes from fetching and leaking processes - #91

Merged
max-metaplanet merged 4 commits into
mainfrom
fm/nm-probe-no-lazy-fetch
Oct 17, 2026
Merged

max-metaplanet merged 4 commits into
mainfrom
fm/nm-probe-no-lazy-fetch

Conversation

@max-metaplanet

Copy link
Copy Markdown
Owner

Problem

Firstmate's read-only no-mistakes probes - the axi status path and
fm_nm_run_checked in bin/fm-crew-state.sh, the custody check in
bin/fm-dod-lib.sh, and the pre-teardown run lookup in bin/fm-teardown.sh -
run inside core worktrees, which are partial clones. When no-mistakes resolved a
run commit the copy did not hold, the promisor fetched it: about 10 seconds and
about 500 MB per call (upload-pack: not our ref ...), paid on every
supervision pass.

bin/fm-nm-run-lib.sh also carried its own copy of the timeout-mechanism
selection that bin/fm-timeout-lib.sh already owns, and that copy's GNU
timeout arm passed no -k: it sent TERM to the process group and never
escalated or reaped. A probe that ignored TERM survived its deadline reparented
to init and kept working, so another copy accumulated every pass.

Change

  • fm_nm_run_bounded exports GIT_NO_LAZY_FETCH=1 for the probe's own
    subshell. A missing object now answers "absent" immediately, which is what
    this library's attribution rules already expect. It is exported rather than
    passed through env, so the supervision hot path gains no PATH dependency.
    Every no-mistakes call made through this library is a read-only probe plus
    teardown's own axi abort; none of them may fetch, and the header says so.
  • fm_nm_resolve_commit does the same for firstmate's own lookup. Its contract
    already claimed it never fetches; in a partial clone that was not true, and it
    is the second source of the same promisor fetch on the same hot path.
  • fm_nm_bounded now routes through fm_run_timed, deleting the duplicated
    mechanism selection. The single owner runs the command in its own process
    group and escalates TERM to KILL on every mechanism it selects.
  • bin/fm-timeout-lib.sh passes the caller's stdin through its asynchronous
    launches (<&0). Both the external-timeout and bash mechanisms start the
    bounded command in the background, where bash substitutes /dev/null; without
    this, bin/fm-pipeline-spend.sh, which feeds python3 - a heredoc through
    fm_nm_bounded, would have lost its program.
  • A comment in bin/fm-crew-state.sh describing the removed "no timeout tool
    returns 1" path was made wrong by the change and is corrected.

Tests

tests/fm-nm-run-lib.test.sh is new and runs each case against every bound
mechanism available on the host. All four cases were confirmed to fail against
the pre-change code:

  • a probe carries GIT_NO_LAZY_FETCH=1, runs in the worktree it was given, and
    does not leak the variable into its caller;
  • a bounded command receives its caller's stdin;
  • a probe that outruns its bound leaves no descendant: both halves of the stub
    ignore TERM, so only an escalation to KILL across the whole group ends them,
    and the test asserts the descendant has stopped working afterwards rather than
    only that its pid is gone;
  • fm_nm_resolve_commit answers absent for a commit only the promisor holds,
    with a non-vacuity check that the same lookup without the guard does fetch it.

The orphan was reproduced directly against a faithful GNU timeout stand-in:
with the previous library the probe and its descendant both survived the bound
with ppid 1 and kept running; with this change both are gone.

Targeted suites run locally, all green: fm-nm-run-lib, fm-timeout-lib,
fm-crew-state, fm-dod-lib, fm-pipeline-spend, fm-teardown,
fm-test-run, fm-gotmp. bin/fm-lint.sh and bin/fm-doc-audience-check.sh
are clean.

Follow-up, out of scope here

How no-mistakes itself resolves a run commit is an upstream no-mistakes matter.
Disabling lazy fetching stops firstmate paying for it; the upstream CLI could
avoid touching the object store for that answer at all.

…ocesses

Firstmate's read-only no-mistakes probes run in core worktrees, which are
partial clones. no-mistakes resolving a run commit the copy does not hold
made the promisor fetch it, measured at about 10 seconds and about 500 MB
per call, on every supervision pass. Export GIT_NO_LAZY_FETCH=1 for the
probe child so a missing object answers "absent" immediately, which is what
the attribution rules already expect, and do the same for this library's own
fm_nm_resolve_commit, whose contract already claimed it never fetches.

The probes' timeout wrapper also duplicated the mechanism selection that
bin/fm-timeout-lib.sh owns, and its GNU timeout arm sent TERM to the group
with no KILL escalation and no reap. A probe that ignored TERM survived the
bound reparented to init and kept working, piling up another copy every
pass. Route the wrapper through fm_run_timed, the single owner, which runs
the command in its own process group and escalates TERM to KILL on every
mechanism it selects.
… exporting it

ShellCheck reads the exported PATH and mechanism override in one subshell as
possibly lost in the next (SC2030/SC2031). Set them as command prefixes, the
shape tests/fm-timeout-lib.test.sh already uses, so lint passes without a
suppression.
@max-metaplanet max-metaplanet added the fm-ci-validated Deliberately validated by this repository CI instead of the local no-mistakes pipeline label Oct 17, 2026
…g the environment

CI's source-following ShellCheck ties the shell-variable read back to the
export inside fm_nm_run_bounded's subshell and reports SC2031. What must not
leak is what a later child would inherit, so read the exported environment
instead; nothing here exports the variable, and the assertion still fails
when it is present.
@max-metaplanet
max-metaplanet merged commit 7e81a6f into main Oct 17, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fm-ci-validated Deliberately validated by this repository CI instead of the local no-mistakes pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant