# Design-review verdict: remote-lane stop (the two closers of one lane's TERMINAL)

Verdict: **PASS with conditions.** The stop node may be built against this model under
the conditions at the end.

Reviewed against the committed TLC output in this directory, bound by `SUMMARY.txt`
(the sha256 of `RemoteLaneStop.tla`, of each cfg and of each `results/*.out`).
CI runs no TLC (no java there), so the evidence is the recorded run, regenerated by
`python3 tests/formal/remote_lane_stop_tlc.py` on a lab host (placed by the lab runner on
h101, TLC2 2.19, tla2tools.jar sha256 `936a262061c914694dfd669a543be24573c45d5aa0ff20a8b96b23d01e050e88`).

| Config | Expected | Result |
| --- | --- | --- |
| Model.cfg | all nine invariants and EveryStopAnswered hold | PASS |
| mut_no_single_closer.cfg | the ledger takes every TERMINAL | AtMostOneTerminal violated |
| mut_no_wait_for_exit.cfg | the TERMINAL follows the signal | TerminalAfterExit violated |
| mut_early_kill.cfg | the forceful signal skips the polite wait | KillAfterWait violated |
| mut_signal_first.cfg | the signal is sent before the ledger read | NoSignalWhenAlreadyEnded violated |
| mut_no_give_up.cfg | no bound on the forceful wait | EveryStopAnswered violated |

Each mutation flips one constant of Model.cfg and keeps every invariant enabled. Six
witness configs (`wit_*`) each violate an invariant that says a state is unreachable,
which shows the state is reachable: a stop that wins, a stop that loses the single-closer
race and reports already_ended, a stop that needed the forceful signal, a refusal that
names a survivor, a stop that read an ended lane and sent nothing, and a runner that
closed the lane after a stopper had signalled it.

Interleavings tried against the model, each in the state space of Model.cfg
(two stop commands, a runner that may be alive or dead, an engine that may ignore the
polite signal and may not die of the forceful one, and a lane that may already have ended
with or without its TERMINAL):

1. The runner closes the lane between a stopper's read and its signal: the stopper
   signals a dead tree, waits, writes, and the ledger refuses it; it reports
   already_ended and wrote nothing (LoserWritesNothing).
2. Two stop commands both read an open lane, both signal, both wait, both write: one
   row is accepted, the other stopper is a no-op (AtMostOneTerminal, StoppedIsOwnWrite).
3. The engine ignores the polite signal and dies of the forceful one: the forceful
   signal is sent only after the polite wait (KillAfterWait).
4. The engine survives both signals: the stopper refuses after the bounded wait, names
   the survivor and writes no row (RefusedWritesNothing, EveryStopAnswered).
5. The engine ended on its own and its runner is dead, so no TERMINAL exists: the
   stopper closes the lane (a stale lane is stoppable).
6. The runner is alive and sees the engine end from the stopper's own signal: either
   closer may win; the loser is a no-op (AtMostOneTerminal, EndedHasTerminal).
7. A stopper that wrote its row before the process was gone (mutation) and one that
   signalled before reading (mutation) are caught by their own invariants.

Conditions the code must keep, each outside what the model can say:

- The signal reaches only the lane's own tree: the node reads the pid and group from
  the lane's context directory and refuses to signal once the run's exit-code file
  exists (a recycled pid is not the lane).
- An ssh failure or an unreadable host is a refusal with no row, never a stopped lane.
- A refusal leaves the CLAIM open, and the runner's own closeout or the host reaper
  closes it later; the node never writes a row on a refusal.
- The ledger's refusal of a second TERMINAL for one CLAIM is the single closer: the node
  does not keep a lock of its own, and a writer failure is re-read from the ledger
  before it is reported (already_ended when a TERMINAL now closes the CLAIM).
- Time is abstract in the model; the waits are bounded polls whose lengths come from
  the request.
