Repository navigation
perf(remote): cut the lean lane's envelope and its argument-less tool_start - #873
Merged
Merged
Conversation
…_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
enabled auto-merge (squash)
September 26, 2026 08:48
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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.eventIdalone — an{session}:{run}:{epoch}:{idx}string, ~96 B per event — was 20.3% of the whole lane.Verified against every consumer of this subject:
StreamEvent+normalizeReplayEventstype,data,runId,idxtype,runId,idx,datacoalescedCountNothing 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
inputphase oftool_startA tool call announces itself twice:
inputwhen the model begins writing the call,executionwhen the arguments are complete and the tool runs. Across six real runs, all 1,608inputphases 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 untilexecutioneither way). The one long gap, an approval wait, has its ownapproval_requestevent, which the phone already handles.Gating
Both trims are gated on
lean_events_v1:publish_eventcomputes 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_idtobuild_event_body. That is whereeventIdcame 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)
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_start42–46% (per-command metadata; the shell command itself is the bulk),tool_end22%, 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, thecoalescedCountmerge marker surviving, a non-object body left alone.tool_start_drops_the_bodies_only_write_and_edit_carryextended — theinputphase goes,executionstays, a phase-less payload is forwarded rather than dropped.lean_lane_drops_streamed_content_and_keeps_the_tool_outcomeextended — the trimmed envelope on the wire, plus a publishedinputphase that must not appear.a_client_that_did_not_declare_keeps_the_full_laneextended — every legacy envelope key asserted present.lean_event_bodyand 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 theinput-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 --checkandcargo clippy --all-targets -D warningsclean. Render harness: all fivelean-render-*scenarios exit 0 against the regenerated fixtures; the fixture diff is exactly the nineinputphases 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 (runId37 B,type20 B,idx13 B per event) are all read, so holding them is holding real information.