Skip to content

test(remote): measure the lean lane as received, over real E2EE - #854

Merged
huichen merged 5 commits into
mainfrom
perf/verify-e2e-bytes
Sep 25, 2026
Merged

huichen merged 5 commits into
mainfrom
perf/verify-e2e-bytes

Conversation

@huichen

@huichen huichen commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

The trims (#841–#846, #849, #851) were all measured the same way: reconstruct the desktop's published body in Python, or observe the FakeNats tap. Both are models of the wire, and the second one is worse than it sounds — the lane tests next door run with Transport::legacy_fixture(), which seals nothing, so their tap counts plaintext before encryption.

This adds a measurement of what a client actually receives and decrypts.

What it wires

  • The production transport: build_transport() with one secure::Transport shared by the command loop and the event drain, so events go through the real ordered queue.
  • A real phone handshake: secure_pair() (Noise XXpsk0, PSK from the invitation URL) plus an independent NATS connection.
  • Per message: decrypt with the real channel, then assert the FRE2 prefix and wire == plaintext + HEADER_LEN(28) + TAG_LEN(16). A plaintext path cannot satisfy that, which is what makes this a measurement of the wire rather than of a model.

Covers the live lane, and the history page on both shapes the phone uses (get_session_entries full, and before+limit paged). Two states are flipped by declaring or withdrawing lean_events_v1 through the real apply_declared_features, and the undeclared state is asserted byte-identical to the source journal — including after withdrawing the declaration, which catches a lane that latches.

Measured (three heaviest real runs, 2026-09-26)

undeclared declared wire
live lane (run 1) 174,791 msgs / 70.3 MB 2,082 msgs / 1.06 MB −98.49%
live lane (run 2) 166,685 msgs / 66.6 MB 2,792 msgs / 1.27 MB −98.10%
live lane (run 3) 154,907 msgs / 60.9 MB 2,060 msgs / 0.85 MB −98.61%
history full 264–358 KB 44–49 KB −82.7% … −87.6%
history paged (512 KiB budget) 2.4×–4.7× the entries in the same budget —

Scope, stated in the report itself

  • The broker is the in-process FakeNats (real core-NATS line protocol, not an external process). The real-broker rerun is a separate task, todo_2d5e8b4fb8d9.
  • The bridge→agent hop is a scripted mock; the history pages and journals are real.
  • Only lean_events_v1 is flipped, to isolate its effect — the phone also declares coalescing and gzip, so its absolute numbers are only smaller.

Included here: the ignored measurement test (measure_real_e2ee_bytes) and scripts/measure/verify-e2e-bytes.py, which dumps a real run's journal from the read-only agent.db and the real history page via grpcurl (converting protojson int64 strings back to numbers — SessionEntryPayload's deny_unknown_fields + i64 would otherwise fail to decode the whole page).

Verification

  • cargo test --lib verify_e2e → the self-contained fixture test passes; the measurement is #[ignore] and driven by the script.
  • Full desktop lib: 1314 pass; cargo fmt --check + cargo clippy --all-targets -- -D warnings clean on pinned 1.97.

Two flakes seen in one full run and gone on a re-run (instance::…excludes_second_owner…, remote::commands…desktop_settings_management_is_shared_and_allowlisted). This branch touches three files — a new #[cfg(test)] module, its declaration, and the script — and none of them registers a command or touches an allowlist, so neither can be caused by it.

The existing lane tests count bytes at the FakeNats tap while the state runs
Transport::legacy_fixture(), i.e. plaintext before encryption. Add a harness
that wires the production v2 path instead — one secure::Transport shared by the
command loop and the event drain (build_transport), a phone-side Channel from
the real secure_pair handshake, and a subscription whose messages are counted
on receipt and again after Channel::open. Every record is asserted to be a
sealed one (FRE2 prefix, wire == plaintext + HEADER + TAG).

It measures both declaration states over the same journal (live lane) and both
get_session_entries shapes (full and before-paged), asserting the undeclared
state is byte-identical to the source and that withdrawing the declaration
restores it. The ignored measure_real_e2ee_bytes test replays a real run dump
supplied by scripts/verify-e2e-bytes.py (read-only agent.db + grpcurl dump of
the real history page, protojson int64 strings converted back to numbers).
`scripts/` was reorganized by #847 while this branch was open, and it settled on
`scripts/measure/` for measurement scripts. Moving this one there is more than a
path change: the script located the repo root with `parents[1]`, which was
correct at `scripts/` and points at `scripts/` itself one level deeper. It now
matches the two siblings already in that directory (`parents[2]`), verified by
resolving the path and by `--help`.

The doc comments and the test's `#[ignore]` reason were updated with it.
@huichen
huichen enabled auto-merge (squash) September 25, 2026 19:46
@huichen
huichen merged commit 9063b70 into main Sep 25, 2026
12 checks passed
@huichen
huichen deleted the perf/verify-e2e-bytes branch September 25, 2026 20:18
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