Skip to content

test(formal): serialize TLC runs and check the jar before caching it - #44

Merged
pdevito3 merged 4 commits into
mainfrom
test/formal-tooling-followups
Nov 26, 2026
Merged

pdevito3 merged 4 commits into
mainfrom
test/formal-tooling-followups

Conversation

@pdevito3

Copy link
Copy Markdown
Contributor

Why

Verifiers who ran the two TLA+ models as new users hit runner faults and skill gaps. tlc.sh cached a jar before it checked its hash. Three TLC runs at once (-workers auto, default heap) drove a 10-core, 32 GiB Mac to load 410 and filled the disk. A TLC crash showed only as error:1 MISMATCH. This PR fixes those faults, so the next person can run one check without overloading the machine.

What changed

  • tests/formal/tlc.sh:
    • Hashes the download before it moves it into the cache. A bad cached jar is downloaded again.
    • Lets one TLC run go at a time on the machine. The lock is /tmp/backwave-tlc.lock, a symlink created atomically with ln -s. Its target is the holder's PID plus its ps -o lstart start time in a fixed locale, which catches a dead holder and a reused PID. A second run prints Waiting for the TLC run of PID <pid> to finish and polls every 2 s.
    • Runs TLC as a tracked child, so a signal to tlc.sh stops TLC before the lock is released.
    • Adds TLC_WORKERS (default half the cores, auto for all), TLC_HEAP (default 4g), and TLC_LOG. check.sh uses TLC_LOG for its log, and the wait notice stays on the terminal.
  • Both check.sh: --config <name> runs one config. On an exit code other than 0 or 12, they print the last 20 lines of TLC's output.
  • Skills:
    • Both list Java 11+ or mise, --config, the lock and its settings, and measured times with load.
    • commit-horizon maps EndTxn and ReporterStart to code, and says that TLC never reads the C#.
    • lease-fencing gives the baseline distinct-state counts and shows how to gate a shared guard such as Fence on one adapter.
  • The probe comment now cites OracleJobStore.cs:1473-1484, matching the spec header and the skill.

Tradeoffs

The default is half the cores rather than auto, because the lock already serializes runs and the machine is shared. I chose a symlink lock over mkdir plus a PID file because it creates the lock and writes the PID in one step.

Verification

All runs were on this branch, one at a time, at load averages from 10 to 510.

  • Lock: two concurrent short runs serialize and print the notice through both check.sh. Dead-PID, reused-PID, and mixed-TZ/locale locks behave as described. SIGTERM and SIGINT stop TLC (exit 143) and release the lock.
  • Jar: a wrong hash leaves no cached jar, and a corrupt cached jar is replaced.
  • Failures: a bad TLC_HEAP and a missing Java each print their reason in the tail of both scripts.
  • lease-fencing/check.sh --all: 17 of 17 rows match. oracle 14,110,656, postgres 1,947,808, sqlserver 2,698,212. I reran the three adapters on the final tlc.sh with the same counts.
  • commit-horizon/check.sh --deep: 17 of 17 runs ok, check passed.

tlc.sh hashes the download before it moves it into the cache, takes a
machine-wide lock so one TLC run goes at a time, and caps workers and
heap through TLC_WORKERS and TLC_HEAP. Both check.sh scripts gain
--config to run one config and print the tail of TLC's output when a
run ends with an unexpected exit code.
Quote measured run times and how load affects them, list Java 11+ or
mise, document --config and the TLC lock, map EndTxn and ReporterStart
to code, give baseline distinct-state counts for the adapter configs,
and explain how to model a guard that changes in one adapter only.
… log early tlc.sh failures

ps prints lstart in the caller's TZ and locale, so a run with a different
environment took a live lock as stale. TLC_LOG now opens once the lock is
taken, so a missing Java or a bad download reaches the check.sh tail.
…-config

A SIGTERM to the PID in the wait notice released the lock and left TLC
running. tlc.sh now runs TLC as a child, forwards INT, TERM and HUP, and
keeps the lock until TLC exits.
@pdevito3

Copy link
Copy Markdown
Contributor Author

review-gate: passed 6ed6614

Two thermo-nuclear-review passes on opus: the first at 3c16fb8, the second at 6ed6614. No high findings.

Fixed:

  • Pass 1 M1: lstart depended on TZ and locale. Fixed in 6ed6614.
  • Pass 1 M2: an early tlc.sh failure left no log. Fixed in 6ed6614.
  • Pass 2 M1: a SIGTERM to the holder orphaned TLC. Fixed in 141d3e3, after the last review, together with two lows: an empty --config and a note that the seconds include the lock wait.

Open, all low:

  • Two waiters on a stale lock can both start, in a window of microseconds. The cost is one extra concurrent run.
  • A stale lock owned by another Unix user fails rm under the sticky /tmp. The Mac has one user.
  • A non-symlink at the lock path makes the loop spin or acquire falsely. Nothing writes there.
  • A failed ps, such as a fork failure, makes a live holder look stale. The cost is one extra concurrent run.
  • oracle-skip-locked-probe.sh hand-copies the ExpireLeases SQL with only a line citation as its link. The comment review flagged it, and it is out of scope here.

@pdevito3

Copy link
Copy Markdown
Contributor Author

verify: PASS+NOTES 141d3e3

Base 280ecbc, patch-id b3da67351c8570b86b612654607eb02b02c0f651 (matches). Independent verifier, not the author. One TLC process at a time, small configs only, load average 10 to 45.

  1. Skills read cold, single-config option: PASS. commit-horizon/check.sh --config MutantNoHorizon.cfg (cold cache, jar downloaded and hashed) and --config MutantPAfterProbes.cfg (both checks ran) passed. lease-fencing/check.sh --config mutants/claim-no-lock-postgres.cfg and --config postgres.cfg passed. postgres.cfg gave 1947808 distinct states, as the new table says. Unknown names, --config "", and a path outside the folder exit 2.
  2. Lock: PASS. A second run printed Waiting for the TLC run of PID ... and its TLC started after the first ended. SIGTERM, SIGHUP, and SIGINT with default disposition (to the PID and to the process group, as Ctrl-C sends) mid-run: exit 143 within 1s, the java child gone in ps, the lock gone, the -metadir dir gone. Stale locks removed and the run proceeded, for a dead PID and for a live PID with the wrong start time. A waiter killed with SIGTERM left the holder's lock as it was, and the holder finished with exit 0.
  3. Jar hash: PASS, in a scratch copy. A corrupt cached jar was downloaded again and the hash matched. With a wrong pin the run exits 1 with the mismatch message, and .cache stays empty with no .tmp. The real cache was not touched.
  4. Env vars: PASS. TLC_WORKERS=2 TLC_HEAP=1g gives -Xmx1g -workers 2 in ps (TLC: 2 workers, 910MB heap). The default is -workers 5 -Xmx4g on 10 cores, and auto gives 10 workers. With TLC_LOG the wait notice goes to the terminal, and all output after the lock goes to the file.
  5. Citations: PASS. OracleJobStore.cs:1473-1484 is the ExpireLeases command and SQL, in the same range the spec uses. EndTxn/Commit/Rollback, ReporterStart, Fence, Has("OwnerOnlyFence"), Adapter, and the Mutants ASSUME all exist. No em dash and no ADR or issue numbers in the added lines or commit messages.

Notes (none block the merge):

  • SIGTERM to check.sh itself, not to tlc.sh, orphans tlc.sh and java. They run the config to the end and hold the lock, so later runs wait. Ctrl-C in a terminal is not affected. The orphan also happens at base, but base had no lock to hold.
  • postgres.cfg took 72s at load 43. The lease skill says every config other than a passing Oracle one takes under a minute.
  • SIGINT sent to a tlc.sh that a non-interactive shell started in the background is ignored, because bash inherits SIG_IGN, so the run finishes. Scripts should stop it with SIGTERM.

After the checks: git status clean, no lock, no TLC process, scratch dirs removed.

@pdevito3
pdevito3 merged commit 6333c56 into main Nov 26, 2026
2 checks passed
@pdevito3
pdevito3 deleted the test/formal-tooling-followups branch November 26, 2026 12:18
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