Skip to content

sminos: bench_scale.py stops what it started on SIGTERM or SIGINT (#152) - #423

Merged
SSFSKIM merged 3 commits into
mainfrom
sminos-bench-signals
Oct 28, 2026
Merged

SSFSKIM merged 3 commits into
mainfrom
sminos-bench-signals

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 28, 2026

Copy link
Copy Markdown
Owner

What

sminos/tests/bench_scale.py now stops every process it started when it gets SIGTERM or SIGINT, in every mode: the sleep sessions, daemon run (its uplink ends with it), the hub or endpoint stand-in, and every waited-for child (a tick, the probe, daemon status, the verbs). It removes the synthetic machine unless --keep and exits 128 + the signal. B2's step 2 (bench_scale.py run --rl10 on the mini) can now be timed out or interrupted without leaving load behind on a shared Mac.

How

  • The handler raises Stopped, a BaseException that is neither SystemExit nor KeyboardInterrupt. tick and profile run the daemon's tick_all in the bench's own process, and tick_all catches (Exception, SystemExit) per project, so a SystemExit there was swallowed as one project's failure.
  • Every child goes through spawn (or run_child, for one it waits for). If a signal lands while spawn is starting a child, it is only noted, and raised once the child is in STARTED.
  • main's end is shielded: from its first statement a signal is only noted. It kills whatever in STARTED an unwind left running, then removes the machine. A second signal does nothing; the cleanup already under way finishes.
  • The sessions' stdio goes to /dev/null, so they no longer hold the caller's pipe open.

Tests

test_scale.py's BenchStops (runs in the sminos gate):

  • SIGTERM mid-warm-up on DX2 and on --rl10, and SIGINT on --rl10. Each test records the bench's descendants before signalling, then checks that none is left after the exit, that the exit status is 128 + the signal, and that the synthetic machine is gone. Against the old script these tests found the sessions, daemon run, its uplink and the stand-in still running.
  • SIGTERM mid-tick in process. This one fails against a SystemExit-based stop.
  • A signal injected while spawn or run_child starts a child: the child is registered, and the sweep ends it.

Normal runs of run (DX2 and --rl10), tick and verbs were checked by hand at small scale: same output and exit status, nothing left behind.

Review

doperpowers:reviewer-medium ran three rounds.

  • Round 1 found three problems: tick_all swallowed the stop; a signal at a child's start left that child unregistered; a first signal during the ordinary end cut the end short. All three are fixed by the design above.
  • Round 2 found the subprocess.run children unregistered. Fixed with run_child. It also reported a window at the very entry of main's finally, before the shield is set. That window exists only under a tracer: CPython runs no signal handler between entering a finally and its first store. Dismissed.
  • Round 3 found nothing on the ordinary path. Residue below.

Residue (not fixed)

  • bench_open.uptime(), which opens calls for its summaries, starts uptime through a plain subprocess.run. A signal landing inside that call's Popen could leave one uptime unregistered, but uptime exits on its own within milliseconds, so nothing is orphaned.
  • daemon run still gets up to 60 s to stop after a signal (its tick in hand, then its uplink's grace), as on the ordinary path. A harness that SIGKILLs sooner can still leave it behind.

sminos 1.27.1.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)

A SIGTERM (a timeout, a harness stopping it) killed bench_scale.py at once,
skipping the finally that ends its processes, so its `sleep` sessions, its
`daemon run` (and that daemon's uplink) and its stand-in kept running. A
handler for SIGTERM and SIGINT now raises SystemExit(128 + the signal) into
the existing finally blocks; a later signal is ignored so the cleanup it
started is never cut short again. Each two-step cleanup is nested, so one
interrupted step never skips the next, and the build itself ends the
sessions it started when it is cut short. The sessions no longer hold the
caller's stdout open.

test_scale.py's BenchStops starts a small `run` in each mode, signals it
mid-warm-up, and finds none of its descendants left and the synthetic
machine removed (SIGTERM on DX2 and RL10, SIGINT on RL10).

sminos 1.27.1.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
… its own end

Review of the first cut found three windows. `tick` and `profile` run the
daemon's tick_all in the bench's process, which takes a SystemExit as one
project's failure, so the stop was swallowed there; a signal between a
child's start and its registration left that child unknown; and a first
signal during the ordinary end cut that end short.

The stop is now `Stopped`, a BaseException that is neither SystemExit nor
KeyboardInterrupt. Every child goes through `spawn`, which notes a signal
that lands while it starts the child and raises it only once the child is
in STARTED. Main's end runs shielded (a signal is only noted there) and
kills whatever of STARTED an unwind left running before it removes the
synthetic machine, then exits 128 + the signal. The nested cleanups of the
first cut are gone: the end's sweep covers what they guarded.

test_scale.py adds a SIGTERM mid-tick in process (it fails with a
SystemExit-based stop) and a signal inside spawn, and every stop test now
checks the exit status is 128 + the signal.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
The re-review found the `subprocess.run` children (a tick, the probe,
`daemon status`, the verbs, `ps`) outside the registry: a signal between
such a child's start and run's own handler left it unknown to the end's
sweep. They now go through `run_child`, which starts the child with
`spawn` and kills it if this process is stopped while it waits. The
spawn test covers both ways in.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-28T09:09:30.142967Z 6f3faab PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@SSFSKIM
SSFSKIM merged commit 4038244 into main Oct 28, 2026
9 checks passed
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