Skip to content

fix(test-run): bound every fixture and the whole run, and sweep escaped fixture processes - #17

Merged
babbarc merged 1 commit into
mainfrom
fm/firstmate-suite-fixture-timeout
Oct 12, 2026
Merged

babbarc merged 1 commit into
mainfrom
fm/firstmate-suite-fixture-timeout

Conversation

@babbarc

@babbarc babbarc commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Why

The fork's Actions are off, so the local bin/fm-test-run.sh run is the only gate for our own tooling.
On 2026-09-19 a changed-file run wedged for about four days and left 21 fixture processes holding their /tmp fixture directories, with nothing failing or reporting.

What was actually missing (established by reading and by experiment)

  • A per-script bound existed, but by default it only applied under --changed, and only when --jobs was not given; every other mode ran each fixture unbounded.
  • No live whole-run bound: --max-wall-ms is judged after the run finishes, so it cannot stop a hang, and nothing bounded selection or finalization.
  • fm_run_timed does signal the fixture's process group, and that does kill in-group children. But a descendant in a session or group of its own - a private tmux server and its pane, a setsid helper - survives it and keeps holding the fixture directory (shown below).

Change

  • --per-script-timeout-secs now defaults to 1500s in every mode; 0 still opts out. The default keeps its measured rationale (slowest loaded script about 1075s, so about 1.4x headroom, and under the 30-minute CI tier).
  • New --run-timeout-secs (default 21600s, 0 opts out). The runner re-runs itself under the existing fm_exec_timed, so selection, scheduling, every fixture, and finalization all fall under one bound. When it trips, the run exits 124 and names the fixtures or phase in flight. --max-wall-ms keeps its existing post-run result contract (its tests assert that a run past it still reports its complete summary), so the live bound gets its own flag instead of changing that one. The default is about 2x the measured complete serial suite (hint tables sum to about 167 min, plus about 20 min for unhinted scripts at the default weight).
  • Fixture process sweep: each fixture runs with a marker unique to the run and fixture appended to FM_TEST_RUN_FIXTURE_MARKS. Descendants inherit it whatever session or group they move to. When a bound trips, every process still carrying the marker gets TERM and then KILL (via /proc/*/environ, or ps -E where there is no /proc). Only a tripped bound sweeps; a fixture that exits on its own still owns its cleanup.
  • A tripped bound is named in the stream, again on stderr after the summary (per-script), or in the final stderr line (whole-run), and it always reaches the exit status (1 for per-script, 124 for whole-run).
  • Unrelated pre-existing bug fixed along the way: --check-coverage and its test ran comm under the host locale on C-sorted inputs, so the coverage guard failed on this en_US.UTF-8 host. It now runs comm under LC_ALL=C.

No second runner or timeout mechanism was added: the bounds use fm_run_timed and fm_exec_timed from bin/fm-timeout-lib.sh. Fixture assertions are unchanged. Test fixture setups that copied the runner with an empty, stubbed, or deleted timeout library now copy the real one, since the runner now always needs it.

Proof

Reproduction fixture (tests/fm-spawn-wedge.test.sh in a throwaway copy of the runner): it starts a private tmux server running a fake agent, a setsid helper, and an in-group child, all with their cwd in a /tmp fixture directory, then waits forever for readiness.

Hazard, before (base 72ada6f8)

No flags (script-list mode, so no bound), killed from outside after 45s:

$ timeout -s KILL 45 bin/fm-test-run.sh tests/fm-healthy.test.sh tests/fm-spawn-wedge.test.sh
FM_TEST_BEGIN ... tests/fm-spawn-wedge.test.sh ...
ok - fake agent launched in /tmp/fm-spawn-wedge.EgYNhz
outer-timeout rc=137 elapsed=45s   (still running, no failure, no message)
    PID    PPID    PGID     SID  ELAPSED COMMAND
1518722       1 1518722 1518722  00:44 tmux -L fmwedge1518717 new-session -d -s agent -c /tmp/fm-spawn-wedge.EgYNhz exec sleep 100001
1518723 1518722 1518723 1518723  00:44 sleep 100001
1518725       1 1518725 1518725  00:44 sleep 100002

With the old --per-script-timeout-secs 5, the run did fail at 5s, but the tmux server, its pane, and the setsid helper all survived:

not ok - tests/fm-spawn-wedge.test.sh exceeded the per-script bound of 5s and was terminated
rc=1 elapsed=5s
1521209       1 1521209 1521209  00:07 tmux -L fmwedge1521204 new-session -d -s agent -c /tmp/fm-spawn-wedge.N2OnPC exec sleep 100001
1521210 1521209 1521210 1521210  00:07 sleep 100001
1521212       1 1521212 1521212  00:07 sleep 100002

After (this branch)

Per-script bound:

$ bin/fm-test-run.sh --per-script-timeout-secs 5 tests/fm-healthy.test.sh tests/fm-spawn-wedge.test.sh
not ok - tests/fm-spawn-wedge.test.sh exceeded the per-script bound of 5s (--per-script-timeout-secs) and was terminated; swept 3 leftover process(es) outside its process group
FM_TEST_END ... tests/fm-spawn-wedge.test.sh exit=124 duration_ms=6048 gate_skip=false
FM_TEST_SUMMARY total=2 failed=1 skipped_gate=0 duration_ms=6177
fm-test-run: FAIL: per-script bound tripped: tests/fm-spawn-wedge.test.sh exceeded --per-script-timeout-secs 5s and was terminated
exit=1 elapsed=6s
$ ps (fixture processes):
    PID    PPID    PGID     SID     ELAPSED COMMAND

Whole-run bound, with the per-script bound disabled:

$ bin/fm-test-run.sh --per-script-timeout-secs 0 --run-timeout-secs 8 tests/fm-healthy.test.sh tests/fm-spawn-wedge.test.sh
fm-test-run: FAIL: whole-run bound tripped: this run exceeded --run-timeout-secs 8s while running tests/fm-spawn-wedge.test.sh and was terminated; swept 3 leftover fixture process(es)
exit=124 elapsed=9s
$ ps (fixture processes):
    PID    PPID    PGID     SID     ELAPSED COMMAND

I also checked both bounds with fm_run_timed forced onto its perl mechanism (timeout hidden from PATH) and its bash mechanism (FM_TIMEOUT_MECHANISM_OVERRIDE=bash), with the same result: the run fails and no fixture process is left. A --changed run whose git hangs fails with this run exceeded --run-timeout-secs 4s during the selection phase, exit 124.

The fixture's /tmp directory itself is not removed, because the wedged fixture never reached its own cleanup. Nothing holds it any more.

New regressions in tests/fm-test-run.test.sh: the default bound in every mode, the sweep of a setsid descendant on a per-script trip, and the whole-run bound in a fixture and in selection.

Commands and outcomes

  • bin/fm-lint.sh: exit 0.
  • bin/fm-doc-audience-check.sh: ok surfaces=118 local_links=739.
  • bin/fm-test-run.sh tests/fm-test-run.test.sh tests/fm-test-fixtures.test.sh tests/fm-test-isolation-proof.test.sh tests/fm-timeout-lib.test.sh tests/fm-ci-workflow.test.sh (ruby on PATH from nixpkgs): FM_TEST_SUMMARY total=5 failed=0 skipped_gate=0, exit 0.
  • bin/fm-test-run.sh --changed --base origin/main (46 scripts, run through the new runner): FM_TEST_SUMMARY total=46 failed=1 skipped_gate=2, 523s. The one failure is tests/fm-lint.test.sh (the fallback attempts lost per-root RSS reporting: unavailable). It fails the same way on the unchanged base because this host has no /usr/bin/time, so it is not caused by this change. The two gate skips are host capability (tsc, Pi package).
  • Not caused by this change either: tests/fm-live-gate.test.sh fails the claude spawn must stage its launch command the same way on the unchanged base. tests/fm-test-run.test.sh needs ruby, which this host lacks, so I supplied it from nixpkgs for these runs.

Not covered

  • The macOS ps -E sweep path has not been run on macOS.
  • A descendant that scrubs its own environment (env -i) escapes the sweep.
  • The sweep only runs when a bound trips. Leaks from fixtures that pass are left alone: killing them could reach shared infrastructure a fixture started by mistake.
  • External interruption (the caller killing the runner) stays outside the runner's guarantee, as before.

…ed fixture processes

A wedged fixture could hang a local run forever: only --changed got a
per-script bound by default, --max-wall-ms is judged after the run, and a
tripped bound signalled only the fixture's process group, so a private tmux
server or setsid helper outlived it holding its /tmp directory.

- Apply the 1500s per-script bound in every mode (0 still opts out).
- Add --run-timeout-secs (default 21600s), which re-runs the invocation
  under fm_exec_timed so selection, scheduling, fixtures, and finalization
  are all bounded, and exits 124 naming the fixtures or phase in flight.
- Mark each fixture's environment and, when a bound trips, TERM then KILL
  every process still carrying that mark, which reaches descendants that
  left the process group.
- Run comm under LC_ALL=C in the coverage guard and its test, matching the
  C-sorted inputs, so --check-coverage passes on UTF-8 hosts.
@babbarc
babbarc merged commit 118109c into main Oct 12, 2026
babbarc added a commit that referenced this pull request Nov 3, 2026
…ed fixture processes (#17)

A wedged fixture could hang a local run forever: only --changed got a
per-script bound by default, --max-wall-ms is judged after the run, and a
tripped bound signalled only the fixture's process group, so a private tmux
server or setsid helper outlived it holding its /tmp directory.

- Apply the 1500s per-script bound in every mode (0 still opts out).
- Add --run-timeout-secs (default 21600s), which re-runs the invocation
  under fm_exec_timed so selection, scheduling, fixtures, and finalization
  are all bounded, and exits 124 naming the fixtures or phase in flight.
- Mark each fixture's environment and, when a bound trips, TERM then KILL
  every process still carrying that mark, which reaches descendants that
  left the process group.
- Run comm under LC_ALL=C in the coverage guard and its test, matching the
  C-sorted inputs, so --check-coverage passes on UTF-8 hosts.
babbarc pushed a commit that referenced this pull request Nov 22, 2026
…ed (offer #8, final)

Refreshed local patch carrying the final reviewed version of upstream offer #8
(kunchenguid#7382), squashed onto current upstream main.

It replaces the two local variants this stack carried - 783c0ecc (the older
home-resolution variant) and b9ece53e (explicit fm_home_correct calls in five
entry points) - with the single mechanism upstream reviewed:

- bin/fm-home-lib.sh corrects an inherited FM_HOME/FM_ROOT_OVERRIDE/FM_ROOT at
  source time when the checkout is a seeded second mate root, and 26 directly
  invoked bin entry points source it before deriving any home-scoped path, so a
  restored pane's own tool shell can no longer read or write the launcher's
  main home (backlog, state, checks).
- bin/fm-supervision-lib.sh gains fm_supervision_home_verdict; bootstrap and the
  watcher tick re-judge alive second mate homes, report "alive but unsupervised"
  once via a check wake, and teardown clears the marker.
- Test and tooling hardening the offer carries: the home-leak regression case,
  fixture list updates, lint source-directive count, and host-determinism fixes.

Content is identical to the offer's final head 0190e10, minus the
coverage-guard collation slice that offer #17 carries instead.

Refreshed onto upstream bb3e690: the correction now also covers the entry
points and the Pi read-repetition extension added upstream since the offer,
and the cross-home verdict reads the session lock through the shared
fm_session_pid_valid predicate, so a tagged win:<pid> holder is usable.
babbarc added a commit that referenced this pull request Nov 22, 2026
…ed fixture processes (#17)

A wedged fixture could hang a local run forever: only --changed got a
per-script bound by default, --max-wall-ms is judged after the run, and a
tripped bound signalled only the fixture's process group, so a private tmux
server or setsid helper outlived it holding its /tmp directory.

- Apply the 1500s per-script bound in every mode (0 still opts out).
- Add --run-timeout-secs (default 21600s), which re-runs the invocation
  under fm_exec_timed so selection, scheduling, fixtures, and finalization
  are all bounded, and exits 124 naming the fixtures or phase in flight.
- Mark each fixture's environment and, when a bound trips, TERM then KILL
  every process still carrying that mark, which reaches descendants that
  left the process group.
- Run comm under LC_ALL=C in the coverage guard and its test, matching the
  C-sorted inputs, so --check-coverage passes on UTF-8 hosts.

Co-authored-by: yeti <yeti@alps>
@babbarc
babbarc deleted the fm/firstmate-suite-fixture-timeout branch November 22, 2026 17:14
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