Skip to content

test(remote): measure what one lazy shell fetch costs against what it saves - #860

Merged
huichen merged 1 commit into
mainfrom
test/measure-lazy-fetch
Sep 25, 2026
Merged

huichen merged 1 commit into
mainfrom
test/measure-lazy-fetch

Conversation

@huichen

@huichen huichen commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

What

The lean history page drops a shell call's arguments whole (the largest unread payload left after the trim) and the phone asks the command back when the row is opened. This measures the way back: what one fetch costs in real sealed bytes, against the command bytes the page dropped — so "lazy" is verified rather than assumed.

Why it is worth a test

  • It closes the last item of the lazy-shell-fetch follow-up: byte re-measurement, over the existing real Noise/AEAD harness (--broker both, so fake and real nats-server).
  • It adds coverage the feature never had: the declared-state fetch through real E2EE. Until now this path was unit-tested only. The scripted agent gained a get_tool_call_args arm answering from the same recorded entries get_session_entries serves, scoped by run as well as id — so the mock cannot answer an identity the real agent would refuse.
  • The measurement itself asserts the properties it needs instead of assuming them: the undeclared page carries the commands, the lean page carries none, both pages of the full read describe the same shell calls, and the fetch returns the dropped command whole.

Measured (three heaviest real sessions, real broker v2.15.0)

sample paged page shell commands share rows mean fetch overhead break-even
1 492,267 B 34,462 B 7.0% 73 472 B 441 B 37/73 = 51%
2 422,436 B 26,558 B 6.3% 64 414 B 451 B 30/64 = 47%
3 1,032,898 B 22,970 B 2.2% 135 170 B 466 B 36/135 = 27%

--samples 3 --broker both still reports liveEqual: true, historyEqual: true, so this adds no new broker asymmetry.

Two honest findings.

  1. The fetch can give the saving back — opening more than ~a quarter to a half of a page's shell rows costs more than carrying them. Typical use (opening the few rows you actually want) does save.
  2. The saving this targets is smaller than an earlier figure suggested: the commands dropped are 2.2–7.0% of the undeclared page. The 25% figure quoted earlier was the commands' share of the already-trimmed remainder — the two are not interchangeable, and only the former is a page-level saving. Per tap, a fetch costs 1.9–3.7× the command it recovers, and the overhead is essentially all envelope (≈100 B of ids + 44 B record header each way).

The lane's savings still come overwhelmingly from the trim itself (66–71% of page bytes); the command drop is a small extra bought with a tap.

Checks

  • cargo test --manifest-path desktop/src-tauri/Cargo.toml --lib — 1315 passed
  • cargo fmt --check / cargo clippy --all-targets -D warnings — clean
  • The measurement runs end to end from a clean checkout of this branch (--samples 1 --broker fake), needing only the live agent's db + socket, like the other measurements in scripts/measure/.

verify_e2e.rs gains shell_calls_in + fetch_tool_call_args and the VERIFY_E2E_LAZY_FETCH line; the script reports it beside the existing lanes.

… saves

The lean history page drops a shell call's `arguments` whole and the phone
asks the command back when the row is opened. This measures the way back in
real sealed bytes, so "lazy" is verified rather than assumed.

The scripted agent answers `get_tool_call_args` from the same recorded
entries `get_session_entries` serves, scoped by run as well as id, which also
gives the declared-state fetch its first coverage through real E2EE (it was
unit-tested only).

Measured over three real sessions on both brokers: the commands dropped are
2.2-7.0% of the undeclared page, and one fetch costs 441-466 B of overhead
(request + reply minus the command it returns, essentially all envelope), so
opening more than ~a quarter to a half of a page's shell rows costs more than
carrying them. Typical use still saves.

Note the share is smaller than an earlier figure quoted for this work: 25%
was the commands' share of the *already-trimmed* remainder, not of the page.
@huichen
huichen enabled auto-merge (squash) September 25, 2026 21:49
@huichen
huichen merged commit 386f3bb into main Sep 25, 2026
12 checks passed
@huichen
huichen deleted the test/measure-lazy-fetch branch September 25, 2026 21:57
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