Skip to content

perf(remote): cut the lean lane's envelope and its argument-less tool_start - #873

Merged
huichen merged 3 commits into
mainfrom
perf/lean-input-phase
Sep 26, 2026
Merged

huichen merged 3 commits into
mainfrom
perf/lean-input-phase

Conversation

@huichen

@huichen huichen commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Two things the lane was paying for that no subscriber reads, plus a fix to the measurement harness that hid one of them.

1. The envelope (this is the big one)

Every lane event carried schemaVersion, sessionId, eventId, timestamp, epoch, sessionIdx, runSequence. Measured on the three heaviest completed runs, the envelope was 72.9% of the lean lane, and those seven keys were 56.1% of the lane. eventId alone — an {session}:{run}:{epoch}:{idx} string, ~96 B per event — was 20.3% of the whole lane.

Verified against every consumer of this subject:

consumer reads
phone StreamEvent + normalizeReplayEvents type, data, runId, idx
desktop web verification client type, runId, idx, data
the coalescer adds coalescedCount

Nothing else. The desktop does not subscribe to this subject at all (it only publishes), and the TUI speaks gRPC. The dropped keys stay recoverable from the agent's own get_events_since.

2. The input phase of tool_start

A tool call announces itself twice: input when the model begins writing the call, execution when the arguments are complete and the tool runs. Across six real runs, all 1,608 input phases carried empty arguments — the event has no label to show. All it can do is make an empty row appear ~331 ms earlier (median; the row's target is unknown until execution either way). The one long gap, an approval wait, has its own approval_request event, which the phone already handles.

Gating

Both trims are gated on lean_events_v1: publish_event computes them from the same flag that gates the payload trim, and the publisher test asserts a client that did not declare gets the byte-identical legacy body (every envelope key asserted present).

The harness bug this exposed

Both measurement harnesses passed an empty event_id to build_event_body. That is where eventId came to look like a free 13-byte field instead of one of the lane's largest keys — I reported it that way before checking. Both harnesses now build the id the agent assigns.

Measured (three heaviest completed runs, shipping code path, real journals)

events full lane lean before lean after this PR
1 174,791 77,211,152 868,200 379,915 -56%
2 166,685 73,191,176 1,061,942 390,848 -63%
3 154,907 66,961,943 771,999 269,414 -65%

The lean lane is 61.5% smaller than before this change, and the cumulative saving from the untrimmed lane is -99.52%.

What the lane carries now: tool_start 42–46% (per-command metadata; the shell command itself is the bulk), tool_end 22%, usage 10–13%, thinking boundaries 14–17%, visible text 2–7%.

Tests

  • lean_event_body_keeps_only_the_keys_a_subscriber_reads — the retained set, the coalescedCount merge marker surviving, a non-object body left alone.
  • tool_start_drops_the_bodies_only_write_and_edit_carry extended — the input phase goes, execution stays, a phase-less payload is forwarded rather than dropped.
  • lean_lane_drops_streamed_content_and_keeps_the_tool_outcome extended — the trimmed envelope on the wire, plus a published input phase that must not appear.
  • a_client_that_did_not_declare_keeps_the_full_lane extended — every legacy envelope key asserted present.
  • The fixture generator now applies lean_event_body and asserts no fixture event carries a dropped key.

Falsified both ways: with the envelope trim short-circuited, the publisher test fails on eventId is dropped; with the input-phase check neutered, the unit test fails on "the argument-less input phase goes entirely" and the publisher test fails on "unexpected publish".

Desktop backend: 1325 passed / 0 failed (also re-run after merging #871). cargo fmt --check and cargo clippy --all-targets -D warnings clean. Render harness: all five lean-render-* scenarios exit 0 against the regenerated fixtures; the fixture diff is exactly the nine input phases and is a fixed point.

Not in this PR

command (the shell row's label, ~18% of the lane) — the next item, needs the live row to become fetchable first. And the remaining envelope keys (runId 37 B, type 20 B, idx 13 B per event) are all read, so holding them is holding real information.

…_start

Two things the lane was paying for that no subscriber reads.

1. The envelope. Every event carried schemaVersion, sessionId, eventId,
   timestamp, epoch, sessionIdx and runSequence. Measured on the three heaviest
   runs, the envelope was 72.9% of the lean lane and those seven keys were 56.1%
   of it -- eventId alone (a `{session}:{run}:{epoch}:{idx}` string, ~96 B per
   event) was 20.3% of the whole lane. Verified against every consumer of this
   subject (the phone's StreamEvent plus its normalizeReplayEvents, and the
   desktop's own web verification client): they read type, data, runId, idx and
   the coalescer's coalescedCount. Nothing else. The desktop does not subscribe
   to this subject at all, and the dropped keys stay recoverable from the
   agent's own get_events_since.

2. The `input` phase of tool_start. A tool call announces itself twice: input
   when the model begins writing the call, execution when the arguments are
   complete and it runs. Across six real runs, all 1,608 input phases carried
   empty arguments, so the event has no label to show -- it can only make an
   empty row appear ~331ms earlier (median; the row's target is unknown until
   execution either way). An approval wait, the one long gap, has its own
   approval_request event.

Both are gated on lean_events_v1, so a client that did not declare it gets the
byte-identical legacy body: `publish_event` computes the trim from the same
flag that gates the payload, and the publisher test asserts the legacy envelope
keeps every key.

This also fixes the measurement harnesses, which passed an empty event_id to
build_event_body. That is where `eventId` came to look like a free 13-byte field
instead of one of the lane's largest keys; both harnesses now build the id the
agent would have assigned.

Measured through the shipping code path on the three heaviest completed runs:

| | events | full lane | lean before | lean after | this PR |
|---|---:|---:|---:|---:|---:|
| 1 | 174,791 | 77,211,152 | 868,200 | 379,915 | -56% |
| 2 | 166,685 | 73,191,176 | 1,061,942 | 390,848 | -63% |
| 3 | 154,907 | 66,961,943 | 771,999 | 269,414 | -65% |

The lean lane is 61.5% smaller than before this change, and the cumulative
saving from the untrimmed lane is -99.52%. What remains is per-command metadata
(tool_start 42-46%, tool_end 22%), usage (10-13%), thinking boundaries (14-17%)
and visible text (2-7%).
@huichen
huichen enabled auto-merge (squash) September 26, 2026 08:48
@huichen
huichen merged commit f4bb884 into main Sep 26, 2026
12 checks passed
@huichen
huichen deleted the perf/lean-input-phase branch September 26, 2026 09:03
huichen added a commit that referenced this pull request Sep 26, 2026
The live lane still streamed every shell call's command, the largest single
thing it had left (~18%). The history page dropped it long ago and posts the
client to `get_tool_call_args` when a row is opened; this does the same on the
live lane, which is what the row's identity is now for.

Client: a live tool activity carries `toolCallId` and the run it streamed under,
the same pair the persisted projection attaches. Without them the row would be
permanently blank once its target is gone -- `ToolRow` only offers the fetch
when it has both.

Trim: `shell` keeps nothing but its identity on `tool_start`. `read` keeps its
path (the row's own label) and `write`/`edit` the path alone, as before; a tool
this build does not know still keeps everything.

The price, measured rather than assumed: the client exempts a bare
`grep`/`diff`/`test` exiting 1 from being shown as a failure, and its predicate
reads the command. The agent sends the same verdict as `is_soft_fail` on the
outcome (both predicates agree, and the field has been on the wire since
2026-08-19), so the exemption normally needs nothing else. A row from an agent
predating that field now reads as failed instead. Over 20,332 real shell results
every `exit_code: 1` without the flag was a genuine failure -- a piped or `&&`
chain, or a program outside the soft-fail set -- so the shape this costs is one
the running agent does not produce. The render checks assert the price
explicitly, and the full-feed control shows the other reading side by side.

Measured through `scripts/measure/measure-live-lane.py` on the three heaviest
completed runs:

| | events | undeclared | coalesced | lean before | lean now | this PR |
|---|---:|---:|---:|---:|---:|---:|
| 1 | 174,791 | 77.21 MB | 5.33 MB | 379,915 B | 188,061 B | -50.5% |
| 2 | 166,685 | 73.19 MB | 5.07 MB | 390,848 B | 214,189 B | -45.2% |
| 3 | 154,907 | 66.96 MB | 4.92 MB | 269,414 B | 132,513 B | -50.8% |

The lean lane no longer carries a shell command at all; `tool_start` is still
its largest remaining type (~30%), but that is the envelope plus each call's
identity. Cumulative from the untrimmed lane: -99.75%.

Also refreshes CONNECTION.md's ladder, which #870 and #873 had left two
generations stale (it still quoted 0.82/0.82/0.47 MB), and records that the
measurement now builds each event's real `eventId`.
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