The same lab replays identically, and now something says so (#1419) #1420

Merged
jaylouisw merged 1 commit from test/replay-identical into main 2026-11-11 04:01:36 +00:00
Owner

Closes #1419.

Three engine modules compute with the simulator's own step rather than a clock, and say so in a comment (engine/flow.js:177, engine/nat.js:15, engine/dhcp.js:15). Nothing enforced it - the same shape as the six drifts already landed in this repository.

The failure it protects against is silent. One Date.now() in a newly written module and two servers running the same document publish different payloads: an unreproducible test, or a diff between two boards that reads as a real difference.

Two guards, because each catches what the other cannot

Statically - no Math.random(, Date.now(, new Date(, performance.now(, crypto.randomUUID( or process.hrtime in engine/*.js, comment- and string-aware (the modules discuss every one of them in prose, so a scan that flagged its own documentation would be switched off within a week). The scanner is itself checked against a source that does contain them, so it cannot quietly stop working.

Behaviourally -

  • the same lab built twice in one process, and again after a real 1.2 s wall-clock wait, fingerprints the same (every show output on every device plus serialize());
  • the same document, loaded into two independent server processes and driven through the same command script (vlan, a static route, an address change, two pings), publishes a byte-identical state payload - 12 KB of runtime, counters, MAC/ARP/LLDP rows, routes and cable verdicts;
  • reading one server's board a real second later changes nothing, which is what fails first if a clock-derived field is ever added to fullState().

A guard that cannot fail is not a guard

  • the fingerprint is fed three different labs - another VLAN, another address, one cable fewer - and required to tell them apart;
  • the payload compared across the two servers is required to be one traffic crossed: a device with counters.counted, packets counted, a forwarding table learned. Two empty boards are byte-identical too.

Evidence. 25 checks. Planting Math.random() in engine/lag.js fails the static guard by name (lag.js: Math.random()); adding s.generatedAt = Date.now() to fullState() fails both the two-server comparison and the second-later read, quoting the first differing byte. Restored: 25/25. Suite: 210 suites, 8,046 assertions, 0 failed; syntax 278 files OK. Docs: docs/ARCHITECTURE.md, "The same lab replays identically" - including where wall-clock time is allowed (server side of the socket, a request log, Last-Modified).

Closes #1419. Three engine modules compute with the simulator's own `step` rather than a clock, and say so in a comment (`engine/flow.js:177`, `engine/nat.js:15`, `engine/dhcp.js:15`). Nothing enforced it - the same shape as the six drifts already landed in this repository. **The failure it protects against is silent.** One `Date.now()` in a newly written module and two servers running the same document publish different payloads: an unreproducible test, or a diff between two boards that reads as a real difference. ### Two guards, because each catches what the other cannot **Statically** - no `Math.random(`, `Date.now(`, `new Date(`, `performance.now(`, `crypto.randomUUID(` or `process.hrtime` in `engine/*.js`, comment- and string-aware (the modules discuss every one of them in prose, so a scan that flagged its own documentation would be switched off within a week). The scanner is itself checked against a source that *does* contain them, so it cannot quietly stop working. **Behaviourally** - - the same lab built twice in one process, and again after a real 1.2 s wall-clock wait, fingerprints the same (every `show` output on every device plus `serialize()`); - the same document, loaded into **two independent server processes** and driven through the same command script (`vlan`, a static route, an address change, two pings), publishes a **byte-identical** state payload - 12 KB of runtime, counters, MAC/ARP/LLDP rows, routes and cable verdicts; - reading one server's board a real second later changes nothing, which is what fails first if a clock-derived field is ever added to `fullState()`. ### A guard that cannot fail is not a guard - the fingerprint is fed three *different* labs - another VLAN, another address, one cable fewer - and required to tell them apart; - the payload compared across the two servers is required to be one **traffic crossed**: a device with `counters.counted`, packets counted, a forwarding table learned. Two empty boards are byte-identical too. **Evidence.** 25 checks. Planting `Math.random()` in `engine/lag.js` fails the static guard by name (`lag.js: Math.random()`); adding `s.generatedAt = Date.now()` to `fullState()` fails both the two-server comparison and the second-later read, quoting the first differing byte. Restored: 25/25. Suite: **210 suites, 8,046 assertions, 0 failed**; syntax 278 files OK. Docs: `docs/ARCHITECTURE.md`, "The same lab replays identically" - including where wall-clock time *is* allowed (server side of the socket, a request log, `Last-Modified`).
The same lab replays identically, and now something says so (#1419)
All checks were successful
CI / Classify the change (pull_request) Successful in 10s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 12s
CI / Test (Node 20) (pull_request) Successful in 2m46s
CI / Test (Node 18) (pull_request) Successful in 2m54s
CI / Server smoke test (pull_request) Successful in 28s
CI / Docker build (pull_request) Successful in 40s
CI / Test (Node 22) (pull_request) Successful in 2m31s
77994999eb
Three engine modules compute with the simulator's own step and say so in a comment - 'no Math.random(), no Date.now(), the same lab replays identically' - and nothing enforced it. That is the same shape as the six drifts already landed in this repository: a rule written down once, reimplemented per surface, checked nowhere.

The failure it protects against is silent. One Date.now() in a new module and two servers running the same document publish different payloads; the symptom is an unreproducible test, or a diff between two boards that looks like a real difference.

Two guards, because each catches what the other cannot:

- statically, the engine source contains no Math.random(, Date.now(, new Date(, performance.now(, crypto.randomUUID( or process.hrtime - comment- and string-aware, since the modules discuss all of these in prose. The scanner is itself checked against a source that does contain them, so it cannot quietly stop working.
- behaviourally, the same lab built twice in one process and again after a real wall-clock second fingerprints the same (every show output plus serialize()); the same document driven through two independent servers with the same command script yields a byte-identical state payload; and reading one server's board a second later changes nothing.

Both would be worthless if the fingerprint saw nothing, so it is fed three different labs - another VLAN, another address, one cable fewer - and required to tell them apart; and the payload compared across the two servers is required to be one traffic crossed (packets counted, a forwarding table learned), because two empty boards are byte-identical too.

Evidence: 25 checks. Planting Math.random() in engine/lag.js fails the static guard by name (lag.js: Math.random()); adding a Date.now() field to fullState() fails both the two-server comparison and the second-later read, with the first differing byte quoted. Restored: 25/25.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-11 04:01:33 +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!1420
No description provided.