Skip to content

test(remote): rerun the lean-lane measurement on a real nats-server - #856

Merged
huichen merged 3 commits into
mainfrom
perf/verify-real-broker
Sep 25, 2026
Merged

huichen merged 3 commits into
mainfrom
perf/verify-real-broker

Conversation

@huichen

@huichen huichen commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Follows #854, which replaced the plaintext-tap model with a measurement of what a phone actually receives and decrypts. Its broker was the in-process FakeNats; this runs the same measurement against a real nats-server process (v2.15.0, randomly chosen port, loopback TCP).

Result: the fake was not flattering us

--broker both runs both and compares:

VERIFY_E2E_COMPARE {"liveEqual": true, "historyEqual": true, ...}

fakeLive and realLive are identical field for field — live lane declared/undeclared messages, wire bytes and plaintext bytes; history full and paged. So every number in #854's report holds on a real broker, and the replayed fixture agrees too (live 1415/1195/5, 2031/1723/7; history 14305/550/14311/556).

The server's own accounting, cross-checked

The strongest evidence that NATS adds nothing on this leg is not our own count but the server's: /connz reports what it relayed to the phone connection, and that is compared against what the harness received and decrypted.

That comparison initially failed, deterministically, and finding out why was the useful part:

left: 72696018 (server out_bytes)   right: 72695986 (decrypted)      -> +32 B
left:  176880 (server out_msgs)     right:  176878 (received)       -> +2 msgs

My first guess — client-consumed control frames — was wrong. The cause is this harness's own subscription-readiness probe: await_subscription subscribes to {pattern}.verify-sub-probe on the phone connection and publishes "verify-sub-probe" (16 bytes) to it, and replay_live_lane runs twice per measurement. Two messages, 2 × 16 = 32 bytes, counted by the server and not by the harness.

The probe now reports its payload size and the accounting subtracts it, so the comparison stays an exact equality instead of acquiring a tolerance — a tolerance would have stopped catching per-message framing or header inflation, which is precisely what this check exists to detect.

Also in this branch

Two fixes to the measurement tooling, both found by running it for real:

  • async_nats::Client::flush() proves the bytes left this process, not that the server processed the SUB. On a real broker the subsequent PUB from another connection can overtake it and the event is silently dropped — one run in eight waited 30s and timed out. Replaced with a same-connection publish/subscribe echo: the server handles one connection's commands in order, so the echo proves registration. 8/8 stable since.
  • The script keyed only on result markers, so a test that panicked after printing the numbers still counted as a pass. It now fails on a non-zero exit code.

Scope

Real E2EE, real bridge, real subscribe-and-decrypt, real broker. The agent hop is still MockPlatform/MockAgent, and the journal and history pages are still read read-only from the real agent.db and a live agent via grpcurl. The wire == plaintext + HEADER(28) + TAG(16) and FRE2 assertions are unchanged from #854.

Verification

I reran the broker measurement myself rather than taking the report's word: the byte-equality claim in the accompanying note did not hold and is what led to the accounting fix above. After it, --broker real exits 0 and --broker both reports both equalities — reproduced twice.

cargo fmt --check and cargo clippy --all-targets -D warnings clean on pinned 1.97; the fixture test (verify_e2e_lean_lane_real_crypto_round_trip) passes, and the three broker-dependent tests stay #[ignore]d so CI needs no server.

The received-bytes harness ran on an in-process FakeNats: real E2EE, real
bridge, real client — but not a real broker process. Give the harness a
Broker choice and rerun the same measurement through `nats-server` on a
loopback port, so the numbers are witnessed by the server that production
would use.

Subscriptions are now synchronised with a publish/subscribe echo instead of
Client::flush(): flush only proves the bytes left this process, while the
server handles one connection's commands in order, so the echo of a publish
sent after the SUB proves registration. Without that, a publish could
overtake the SUB and be dropped (reproduced: ~1 fixture run in 5 stalled on
its first message).

When the script passes VERIFY_E2E_NATS_MONITOR, the test also snapshots the
server's own /connz counters for the phone connection before and after the
measured traffic and asserts the window delta equals what the harness
received and decrypted — a broker-side witness for every payload byte.

scripts/measure/verify-e2e-bytes.py (the post-#847 location) starts the
server, prints its version and launch command, runs both brokers and
compares the decoded results. It now also fails on a non-zero test exit
code: a panic after the result markers were printed looked like a pass.
# Conflicts:
#	desktop/src-tauri/src/remote/verify_e2e.rs
#	scripts/measure/verify-e2e-bytes.py
The real-broker accounting compared the server's `/connz` delta for the phone
connection against what the harness received and decrypted, and asserted they
were equal. They are not, and my reruns failed deterministically by exactly
32 bytes and 2 messages:

    left: 72696018 (server out_bytes)   right: 72695986 (decrypted)
    left:  176880 (server out_msgs)     right:  176878 (received)

The cause is this harness's own subscription-readiness probe, not the
transport: `await_subscription` subscribes to `{pattern}.verify-sub-probe` on
the **phone** connection and publishes `"verify-sub-probe"` (16 bytes) to it,
and `replay_live_lane` runs twice per measurement. That is 2 messages and
2 x 16 = 32 bytes the server counts and the harness does not.

Rather than loosen the assertion to a tolerance — which would stop it
catching the thing it exists to catch — the probe now reports its payload size
and the accounting subtracts it, so the comparison stays an **exact**
equality. Per-message framing or header inflation would still fail it.

The measurement itself is unaffected and reproduces: real broker and the
in-process fake agree byte-for-byte (`liveEqual: true, historyEqual: true`),
and the real-broker fixture numbers are identical to the fake's.
@huichen
huichen enabled auto-merge (squash) September 25, 2026 20:28
@huichen
huichen merged commit 419d22d into main Sep 25, 2026
12 checks passed
@huichen
huichen deleted the perf/verify-real-broker branch September 25, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant