Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
wip: sequential TLC configs, guard tests without custom expect messages
garrytan239581f7bf4a
diff --git a/scripts/spec/tlc.sh b/scripts/spec/tlc.shindex 570e013eef..de8cf35b07 100755--- a/scripts/spec/tlc.sh+++ b/scripts/spec/tlc.sh@@ -12,7 +12,7 @@# TLC_TIMEOUT TLC did not finish within TLC_TIMEOUT_S (default 600): the state space grew; shrink the config# TLC_ERROR TLC stopped (parse or semantic error, out of memory): the log names the line# Env: TLA2TOOLS (a jar to use; otherwise scripts/spec/tla-jar.sh downloads the pinned one), TLC_OUT (logs; default-# .context/tlc), TLC_WORKERS (default: CPUs / configs run at once), TLC_TIMEOUT_S, TLC_JAVA_OPTS, TLC_NIGHTLY (1 also runs+# .context/tlc), TLC_WORKERS (default: every CPU; configs run one at a time), TLC_TIMEOUT_S, TLC_JAVA_OPTS, TLC_NIGHTLY (1 also runs# the *Nightly.cfg configs, which take too long for every pull request).set -euo pipefailroot="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"@@ -38,7 +38,9 @@ for dir in "${specs[@]}"; dofor cfg in "${cfgs[@]}"; do [ -f "$dir/$cfg" ] || { echo "TLC_ERROR: no config $dir/$cfg" >&2; exit 2; }; jobs+=("$dir|$module|$cfg"); donedonecpus="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)"-workers="${TLC_WORKERS:-$(( cpus / ${#jobs[@]} > 0 ? cpus / ${#jobs[@]} : 1 ))}"+# One config at a time with every CPU: the configs differ in size by 100x, so running them side by side leaves the+# largest on a fraction of the machine.+workers="${TLC_WORKERS:-$cpus}"run() { # dir module cfg -> runs TLC on a private copy, so its states/ directory never lands in the treelocal dir="$1" module="$2" cfg="$3" work="$out/$(basename "$1")-${3%.cfg}" rc=0@@ -47,9 +49,7 @@ run() { # dir module cfg -> runs TLC on a private copy, so its states/ directory-cp "$jar" tlc2.TLC -workers "$workers" -config "$cfg" -metadir "$work/states" "$module.tla") > "$work/tlc.log" 2>&1 || rc=$?echo "$rc" > "$work/rc"}-pids=()-for job in "${jobs[@]}"; do IFS='|' read -r d m c <<< "$job"; run "$d" "$m" "$c" & pids+=($!); done-wait "${pids[@]}"+for job in "${jobs[@]}"; do IFS='|' read -r d m c <<< "$job"; run "$d" "$m" "$c"; donestatus=0for job in "${jobs[@]}"; dodiff --git a/spec/tla/README.md b/spec/tla/README.mdindex 208eb4a75c..fdd248ca41 100644--- a/spec/tla/README.md+++ b/spec/tla/README.md@@ -43,7 +43,7 @@ copy of the tree there. A failed or interrupted run leaves only partial logs in| `MUTANT_STALE` | A mutant's `before` text is not found exactly once. | The spec or code moved: update the mutant's text in `mutants.json` to the new line that implements the same guard. || `MUTANT_SURVIVED` | No property caught a model mutant, or the named test passed with the guard removed from the code. | A property or a test stopped pinning the guard. Restore it; never delete the mutant to go green. || `MUTANT_WRONG_PROPERTY` | A different property caught it, or a survivor became load-bearing. | Read the trace; update `expect`, and give a new load-bearing guard a code edit and a test. |-| `MUTANT_INCOMPLETE` | TLC did not finish or did not start; a named test failed without the edit or matched no test; or with the edit the test did not end in a clean assertion failure (a signal, a timeout, a load error, an error between tests). | Read the log the message names. Fix the test or filter first; a run that did not fail on the test's own assertion proves nothing. An interrupted run may be rerun once with the printed command. |+| `MUTANT_INCOMPLETE` | TLC did not finish or did not start; a named test failed without the edit or matched no test; or with the edit the test did not end in a clean assertion failure (a signal, a timeout, a load error, an error between tests). | Read the log the message names. Fix the test or filter first; a run that did not fail on the test's own assertion proves nothing. A named test asserts with plain `expect()`: a custom message makes Bun report the failure as an `Error`, not an `AssertionError`. An interrupted run may be rerun once with the printed command. || `MUTANT_NOTHING_CHECKED` | Every check the selection asked for was skipped (a Postgres test without `DATABASE_URL`). | Point `DATABASE_URL` at a test database (`GBRAIN_TEST_ALLOW_DATABASE_URL=1`). |## drain-lease: the managed-sync drain lease@@ -59,7 +59,7 @@ lock with the token stamped on its request: a folded stamp's proof (`provenStamp| `DrainLease.cfg` | Two drainers, one fenced transaction at a time, the code's timing at 10 s ticks: every property. || `DrainLeaseSafety.cfg` | Every adverse assumption on (live holders stolen by a lying pid probe or `--force-break-lock`, fenced transactions longer than the renewal timeout, no renewal priority, a cancelled renewal settling late), 20 s ticks: the safety properties, which must hold anyway. || `DrainLeaseStamp.cfg` | The same, plus the pass stamp's fence: a coordinator transaction that holds the row `FOR SHARE` by any issued token, overlaps the holder's and survives its crash. |-| `DrainLeaseLanesNightly.cfg` | The safety config with two overlapping fenced transactions per holder, at a shorter clock bound. About 5 minutes, so `tlc.sh` runs it only with `TLC_NIGHTLY=1` (the schedule and dispatch). |+| `DrainLeaseLanesNightly.cfg` | The safety config with two overlapping fenced transactions per holder, at a shorter clock bound. About 2 minutes on 4 CPUs, so `tlc.sh` runs it only with `TLC_NIGHTLY=1` (the schedule and dispatch). |`test/spec-drain-lease-constants.test.ts` keeps every config's timing equal to the code's constants and checks theordering the liveness property needs.diff --git a/spec/tla/drain-lease/DrainLeaseLanesNightly.cfg b/spec/tla/drain-lease/DrainLeaseLanesNightly.cfgindex de77ea35ce..983e5a708c 100644--- a/spec/tla/drain-lease/DrainLeaseLanesNightly.cfg+++ b/spec/tla/drain-lease/DrainLeaseLanesNightly.cfg@@ -1,4 +1,4 @@-\* Nightly only (tlc.sh runs it with TLC_NIGHTLY=1; about 5 minutes on 3 workers): DrainLeaseSafety.cfg with two+\* Nightly only (tlc.sh runs it with TLC_NIGHTLY=1; about 2 minutes on 4 CPUs): DrainLeaseSafety.cfg with two\* overlapping fenced transactions per holder (sync lanes), at a shorter clock bound and one cursor step.SPECIFICATION SpecCHECK_DEADLOCK TRUEdiff --git a/test/drain-lease-guards.test.ts b/test/drain-lease-guards.test.tsindex b3d506b1c8..073cd980d8 100644--- a/test/drain-lease-guards.test.ts+++ b/test/drain-lease-guards.test.ts@@ -49,35 +49,38 @@ async function succeed(engine: BrainEngine, id: string) {return row(engine, id);}-describe('drain lease lock-row guards', () => {- test('a live holder whose row has not expired is never taken over (takeover-ignores-ttl)', async () => {- for (const { backend, engine } of engines) {+// One describe per engine, and no custom expect() messages: the mutant runner counts a failure as a caught guard only+// when Bun reports it as an AssertionError, and a custom message turns it into a plain Error.+for (const backend of testBackends()) {+ const engineFor = () => engines.find(e => e.backend === backend)!.engine;++ describe(`drain lease lock-row guards (${backend})`, () => {+ test('a live holder whose row has not expired is never taken over (takeover-ignores-ttl)', async () => {+ const engine = engineFor();const holder = await tryAcquireDbLock(engine, 'test-guard-live', DRAIN_LEASE_TTL_MINUTES);- expect(holder, backend).not.toBeNull();+ expect(holder).not.toBeNull();const before = await row(engine, 'test-guard-live');- expect(await tryAcquireDbLock(engine, 'test-guard-live', DRAIN_LEASE_TTL_MINUTES), backend).toBeNull();- expect(await row(engine, 'test-guard-live'), backend).toEqual(before);+ expect(await tryAcquireDbLock(engine, 'test-guard-live', DRAIN_LEASE_TTL_MINUTES)).toBeNull();+ expect(await row(engine, 'test-guard-live')).toEqual(before);await holder!.release();- }- });+ });- test("a former holder's refresh leaves its successor's row as it was (renewal-ignores-token)", async () => {- for (const { backend, engine } of engines) {+ test("a former holder's refresh leaves its successor's row as it was (renewal-ignores-token)", async () => {+ const engine = engineFor();const former = await tryAcquireDbLock(engine, 'test-guard-refresh', DRAIN_LEASE_TTL_MINUTES);- expect(former, backend).not.toBeNull();+ expect(former).not.toBeNull();const successor = await succeed(engine, 'test-guard-refresh');- expect(await former!.refresh(), backend).toBe(false);- expect(await row(engine, 'test-guard-refresh'), backend).toEqual(successor);- }- });+ expect(await former!.refresh()).toBe(false);+ expect(await row(engine, 'test-guard-refresh')).toEqual(successor);+ });- test("a former holder's release leaves its successor's row in place (release-ignores-token)", async () => {- for (const { backend, engine } of engines) {+ test("a former holder's release leaves its successor's row in place (release-ignores-token)", async () => {+ const engine = engineFor();const former = await tryAcquireDbLock(engine, 'test-guard-release', DRAIN_LEASE_TTL_MINUTES);- expect(former, backend).not.toBeNull();+ expect(former).not.toBeNull();const successor = await succeed(engine, 'test-guard-release');await former!.release();- expect(await row(engine, 'test-guard-release'), backend).toEqual(successor);- }+ expect(await row(engine, 'test-guard-release')).toEqual(successor);+ });});-});+}