A cable says when it was pulled, and both doors say the same thing (#1385) #1386

Merged
jaylouisw merged 1 commit from feat/link-instant into main 2026-11-10 21:12:05 +00:00
Owner

A cable says when it was pulled, and both doors say the same thing. Fixes #1385.

setLinkState() read Number(o.atMs) || 0, so a change with no instant named was stamped t=0 — always. Typed
into a console standing at t=60000:

R1#link down l1
Link l1 (...) is now down.
Network converges again at 30000 ms.        <- half a minute before the moment it was asked about

The same board asked the same question through the API with atMs: 60000 answered 90000. The two doors
disagreed, and one of them was nonsense.

markTopologyChange() — two methods up, written for exactly this reason in #1331 — already had the right rule: the
operator's instant, else 0. setLinkState() now uses it.

The rule, at both doors

  • an instant that is named is the one used;
  • an instant that is not named is the instant the question is being asked at (a settled board has none, and 0 is
    where a board's clock starts — unchanged behaviour there);
  • an atMs that is not a time at or after 0 is refused as E_BAD_INSTANT instead of quietly becoming zero.

That last one mattered: atMs: "abc" used to move the cable and stamp it at 0. The server's
Number(body.atMs) || 0 coerced it before the engine could see it, and mapped every failure to 404 no such link.
The server now passes the value through and answers a bad instant with 400 E_BAD_INSTANT.

Found on the way

link state tested l.stateSinceMs for truth, so a cable pulled at t=0 — the first change in a run's life —
printed its state with no instant at all, while every later change printed one.

Evidence

test/link-instant.test.js — 37 checks:

  • the engine stamps a change at the instant of the question (atMs 60000, reconvergeAtMs 90000) and both the
    cable and the board remember it; a named instant wins; a settled board still starts at 0;
  • "abc", -1, {} and NaN are refused with E_BAD_INSTANT and the cable is not touched;
  • the console prints converges again at 90000 ms, and link state reads changed at 60000 ms (0 ms ago);
  • a change at t=0 now prints changed at 0 ms instead of printing nothing;
  • the control plane and the data plane agree on the number: getConvergence().convergedAtMs equals the reconverge
    instant the console promised, the schedule says which change it is reacting to, a ping at the cut reports
    converging until exactly that instant, and after it the engine stops blaming a process that has finished and
    names the cable instead;
  • over HTTP: no instant means 0 on a settled board, a named instant is used, "abc" and -1 are 400 E_BAD_INSTANT
    with codes, and the refused requests never moved the cable.

Reverting engine/simulator.js fails 6 of 37, engine/cli.js 5, server/index.js 3 — and the printouts
show the old answers verbatim (converges again at 30000 ms; atMs: "abc" → 200 with the cable moved).

docs/CONVERGENCE.md states the rule for all three cases; docs/CLI.md says that no at means now.

Suite: 196 suites, 7,538 assertions, 0 failed. Syntax: 264 files, OK.

A cable says when it was pulled, and both doors say the same thing. Fixes #1385. `setLinkState()` read `Number(o.atMs) || 0`, so a change with no instant named was stamped **t=0** — always. Typed into a console standing at t=60000: ``` R1#link down l1 Link l1 (...) is now down. Network converges again at 30000 ms. <- half a minute before the moment it was asked about ``` The same board asked the same question through the API with `atMs: 60000` answered **90000**. The two doors disagreed, and one of them was nonsense. `markTopologyChange()` — two methods up, written for exactly this reason in #1331 — already had the right rule: the operator's instant, else 0. `setLinkState()` now uses it. ## The rule, at both doors * an instant that **is named** is the one used; * an instant that is **not named** is the instant the question is being asked at (a settled board has none, and 0 is where a board's clock starts — unchanged behaviour there); * an `atMs` that is not a time at or after 0 is refused as **`E_BAD_INSTANT`** instead of quietly becoming zero. That last one mattered: `atMs: "abc"` used to **move the cable** and stamp it at 0. The server's `Number(body.atMs) || 0` coerced it before the engine could see it, and mapped every failure to `404 no such link`. The server now passes the value through and answers a bad instant with `400 E_BAD_INSTANT`. ## Found on the way `link state` tested `l.stateSinceMs` for truth, so a cable pulled at t=0 — the first change in a run's life — printed its state with **no instant at all**, while every later change printed one. ## Evidence `test/link-instant.test.js` — **37 checks**: * the engine stamps a change at the instant of the question (`atMs 60000`, `reconvergeAtMs 90000`) and both the cable and the board remember it; a named instant wins; a settled board still starts at 0; * `"abc"`, `-1`, `{}` and `NaN` are refused with `E_BAD_INSTANT` **and the cable is not touched**; * the console prints `converges again at 90000 ms`, and `link state` reads `changed at 60000 ms (0 ms ago)`; * a change at t=0 now prints `changed at 0 ms` instead of printing nothing; * the control plane and the data plane agree on the number: `getConvergence().convergedAtMs` equals the reconverge instant the console promised, the schedule says which change it is reacting to, a ping at the cut reports `converging` until exactly that instant, and after it the engine stops blaming a process that has finished and names the cable instead; * over HTTP: no instant means 0 on a settled board, a named instant is used, `"abc"` and `-1` are `400 E_BAD_INSTANT` with codes, and the refused requests never moved the cable. Reverting `engine/simulator.js` fails **6 of 37**, `engine/cli.js` **5**, `server/index.js` **3** — and the printouts show the old answers verbatim (`converges again at 30000 ms`; `atMs: "abc"` → `200` with the cable moved). `docs/CONVERGENCE.md` states the rule for all three cases; `docs/CLI.md` says that no `at` means now. Suite: **196 suites, 7,538 assertions, 0 failed**. Syntax: 264 files, OK.
A cable says when it was pulled, and both doors say the same thing (#1385)
All checks were successful
CI / Classify the change (pull_request) Successful in 11s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 15s
CI / Test (Node 20) (pull_request) Successful in 2m42s
CI / Test (Node 18) (pull_request) Successful in 2m52s
CI / Server smoke test (pull_request) Successful in 26s
CI / Docker build (pull_request) Successful in 43s
CI / Test (Node 22) (pull_request) Successful in 2m28s
b3057e336b
setLinkState() read `Number(o.atMs) || 0`, so a cable change with no instant named was stamped t=0 -
always. Typed into a console standing at t=60000, `link down l1` recorded the pull at t=0 and then
answered "Network converges again at 30000 ms": half a minute before the moment it was asked about. The
same board asked the same question through the API with atMs: 60000 answered 90000, so the two doors
disagreed and one of them was nonsense.

markTopologyChange() - two methods up, written for exactly this reason in #1331 - already had the right
rule: the operator's instant, else 0. setLinkState now uses it.

  * an instant that is named is the one used;
  * an instant that is not named is the instant the question is being asked at (a settled board has none,
    and 0 is where a board's clock starts, so unchanged behaviour there);
  * an atMs that is not a time at or after 0 is refused as E_BAD_INSTANT instead of quietly becoming
    zero - `atMs: "abc"` used to move the cable and stamp it at 0.

The server passed `Number(body.atMs) || 0`, which coerced a mistyped instant to zero before the engine
could see it, and mapped every failure to 404 "no such link". It now passes the value through and
answers a bad instant with 400 E_BAD_INSTANT.

A display defect found on the way: `link state` tested `l.stateSinceMs` for truth, so a cable pulled at
t=0 - the first change in a run's life - printed its state with no instant at all, while every later
change printed one.

Evidence: test/link-instant.test.js, 37 checks. The engine stamps a change at the instant of the
question (atMs 60000, reconverge 90000) and the cable and the board both remember it; a named instant
wins; a settled board still starts at 0; "abc"/-1/{}/NaN are refused and the cable is not touched. The
console prints "converges again at 90000 ms" and `link state` reads "changed at 60000 ms (0 ms ago)"; a
change at t=0 now prints its instant instead of printing none. The control plane and the data plane
agree on the number: getConvergence().convergedAtMs equals the reconverge instant the console promised,
the schedule says which change it is reacting to, a ping at the cut reports 'converging' until exactly
that instant, and after it the engine stops blaming a process that has finished and names the cable. Over
HTTP: no instant means 0 on a settled board, a named instant is used, "abc" and -1 are 400 E_BAD_INSTANT
with codes, and the refused requests never moved the cable.

Reverting engine/simulator.js fails 6 of 37, engine/cli.js 5, server/index.js 3 - the printouts show the
old answers verbatim ("converges again at 30000 ms"; `atMs: "abc"` -> 200 with the cable moved).

docs/CONVERGENCE.md states the rule for all three cases; docs/CLI.md says that no `at` means now.

Suite: 196 suites, 7,538 assertions, 0 failed. Syntax: 264 files, OK.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-10 21:12:00 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge!1386
No description provided.