One shape for throughput, and a copy (#1329) #1330

Merged
jaylouisw merged 1 commit from fix/counter-shape into main 2026-11-10 03:37:18 +00:00
Owner

One shape for throughput, and a copy.

Fixes #1329.

The last block of the state payload built by hand on the way out:

counters: counters[d.id] || { bytesIn: 0, bytesOut: 0, packetsIn: 0, packetsOut: 0, flowsOpened: 0, flowsRefused: 0 }

Measured on a CX 6000 with two hosts after a ping:

1. a device that has carried traffic:
   bytesIn,bytesOut,packetsIn,packetsOut,flowsOpened,flowsRefused,drops,ports          (8)
2. a device that has carried nothing:
   bytesIn,bytesOut,packetsIn,packetsOut,flowsOpened,flowsRefused                     (6)
   -> counters.drops.total on an idle device is undefined
3. busy === t.flowState.counters.h1 : true
   -> writing 999999 to the record the payload handed out changed the engine
  • One field, two shapes. The engine's record has drops (with byReason, unported) and ports; the fallback
    had neither — so a client summing drops across a lab read NaN on exactly the devices most likely to be quiet, and
    nothing distinguished "no drops" from "not counted".
  • The payload was the engine's live record. Third instance of this family after #1323 (link endpoints) and #1325
    (layout).

Fixes

flow.counterSnapshot(state, devId) returns the whole shape always — drops {total, byReason, unported}, ports
with each port's tallies and its own drop reasons — copied at every level, plus counted so "nothing has ever
crossed this device" is not the same answer as a zero. fullState() carries it.

Evidence

test/counter-payload.test.js — 16 checks. Three devices in three states (carried traffic, forwarded frames only,
never existed) have identical key sets and a numeric drops.total, with ports empty only for the one that carried
nothing. Editing the snapshot — top level, inside drops.byReason, inside a port tally — leaves the engine unchanged.
Seven fields match the record they came from, and each port comes across with its own drop count. Over HTTP: two
unrelated devices have the same keys, drops is present with a number and a reason map, an untouched device says
counted: false, and writing to a response does not reach the next read.

Recorded in the docs because the payload cannot express them: device totals count transport payload while port
tallies count every frame (a switch that only forwards has port tallies and zero device packets), and a link state
change flushes learned entries (#1256).

With server/index.js and engine/flow.js reverted the suite cannot run: flow.counterSnapshot is not a function.

docs/ARCHITECTURE.md: "Throughput: two counts, one shape".

Suite: 180 suites, 7,069 assertions, 0 failed.

One shape for throughput, and a copy. Fixes #1329. The last block of the state payload built by hand on the way out: ```js counters: counters[d.id] || { bytesIn: 0, bytesOut: 0, packetsIn: 0, packetsOut: 0, flowsOpened: 0, flowsRefused: 0 } ``` Measured on a CX 6000 with two hosts after a ping: ``` 1. a device that has carried traffic: bytesIn,bytesOut,packetsIn,packetsOut,flowsOpened,flowsRefused,drops,ports (8) 2. a device that has carried nothing: bytesIn,bytesOut,packetsIn,packetsOut,flowsOpened,flowsRefused (6) -> counters.drops.total on an idle device is undefined 3. busy === t.flowState.counters.h1 : true -> writing 999999 to the record the payload handed out changed the engine ``` * **One field, two shapes.** The engine's record has `drops` (with `byReason`, `unported`) and `ports`; the fallback had neither — so a client summing drops across a lab read NaN on exactly the devices most likely to be quiet, and nothing distinguished "no drops" from "not counted". * **The payload was the engine's live record.** Third instance of this family after #1323 (link endpoints) and #1325 (layout). ## Fixes `flow.counterSnapshot(state, devId)` returns the whole shape always — `drops {total, byReason, unported}`, `ports` with each port's tallies **and its own drop reasons** — copied at every level, plus `counted` so "nothing has ever crossed this device" is not the same answer as a zero. `fullState()` carries it. ## Evidence `test/counter-payload.test.js` — **16 checks**. Three devices in three states (carried traffic, forwarded frames only, never existed) have identical key sets and a numeric `drops.total`, with `ports` empty only for the one that carried nothing. Editing the snapshot — top level, inside `drops.byReason`, inside a port tally — leaves the engine unchanged. Seven fields match the record they came from, and each port comes across with its own drop count. Over HTTP: two unrelated devices have the same keys, `drops` is present with a number and a reason map, an untouched device says `counted: false`, and writing to a response does not reach the next read. Recorded in the docs because the payload cannot express them: device totals count **transport payload** while port tallies count **every frame** (a switch that only forwards has port tallies and zero device packets), and a link state change flushes learned entries (#1256). With `server/index.js` and `engine/flow.js` reverted the suite cannot run: `flow.counterSnapshot is not a function`. `docs/ARCHITECTURE.md`: "Throughput: two counts, one shape". Suite: 180 suites, 7,069 assertions, 0 failed.
One shape for throughput, and a copy (#1329)
All checks were successful
CI / Classify the change (pull_request) Successful in 13s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 13s
CI / Test (Node 20) (pull_request) Successful in 3m11s
CI / Test (Node 18) (pull_request) Successful in 3m26s
CI / Server smoke test (pull_request) Successful in 33s
CI / Docker build (pull_request) Successful in 58s
CI / Test (Node 22) (pull_request) Successful in 2m50s
0a9172a3ac
The last block of the state payload built by hand on the way out:

  counters: counters[d.id] || { bytesIn: 0, ..., flowsRefused: 0 }

Two faults in one line. Measured on a CX 6000 with two hosts after a ping:

  1. a device that has carried traffic: bytesIn,bytesOut,packetsIn,packetsOut,flowsOpened,flowsRefused,drops,ports
  2. a device that has carried nothing: the same six minus drops and ports, so a client adding up drops read
     undefined on exactly the devices most likely to be idle, drew NaN, and could not tell "no drops" from
     "not counted";
  3. busy === t.flowState.counters.h1 - true. Writing 999999 to the record the payload handed out changed the engine.
     Third instance of this family after #1323 (link endpoints) and #1325 (layout).

Fixes: flow.counterSnapshot(state, devId) returns the whole shape always - drops with byReason and unported, ports
with each port's tallies and its own drop reasons - copies at every level, and `counted` to separate "nothing has
ever crossed this device" from a zero it measured. fullState() carries the snapshot, and the dead local that fed the
old fallback is gone.

test/counter-payload.test.js: 16 checks. Three devices in three states (carried traffic, forwarded frames only, never
existed) have identical key sets and a numeric drops.total, with ports empty only for the one that carried nothing;
editing the snapshot - at the top level, inside drops.byReason, inside a port tally - leaves the engine unchanged;
seven fields match the record they came from, and each port comes across with its own drop count; over HTTP two
unrelated devices have the same keys, drops is present with a number and a reason map, an untouched device says
counted: false, and writing to a response does not reach the next read.

Two distinctions recorded in the docs because the payload cannot express them: device totals count transport payload
while port tallies count every frame (a switch that only forwards has port tallies and zero device packets), and a
link state change flushes learned entries (#1256).

With server/index.js and engine/flow.js reverted the suite cannot run: `flow.counterSnapshot is not a function`.

docs/ARCHITECTURE.md: "Throughput: two counts, one shape".

Suite: 180 suites, 7,069 assertions, 0 failed.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-10 03:37:14 +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!1330
No description provided.