Repository navigation
perf(remote): send a phone only the event content it renders - #844
Merged
Merged
Conversation
A run's live lane costs 67-77 MB raw / 4.2-4.6 MB coalesced, and almost all
of it is content no phone surface shows: `thinking_delta` and `tool_delta`
are per-token streams, and `tool_end` carries the tool's captured output
that only its exit code is read from.
A client that declares `lean_events_v1` now receives the same events with
that content removed. Measured through the shipping code over the three
heaviest real runs (`scripts/measure-live-lane.py`):
full coalesced lean coalesced saved msgs
4.60 MB 0.76 MB 83.4% 8,713 -> 1,335
4.37 MB 0.77 MB 82.4% 8,472 -> 1,442
4.20 MB 0.44 MB 89.5% 8,689 -> 925
- `thinking_delta`, `tool_delta`, `toolcall_delta` are not published. The
per-token types are dropped on a slice compare, before the queue, so the
hot path never parses them.
- `tool_end` / `tool_result` keep `exit_code`, `is_soft_fail`,
`target_path` and `error`; only the captured output goes.
- `run_snapshot` drops its folded `snapshotEvents`, which the client never
reads (it treats the event as a resync signal).
Every other event is forwarded byte-for-byte, so a future event type cannot
be silently reshaped.
Three properties make this a removal rather than a fidelity trade:
`thinking_start`/`thinking_end` alone open and close a reasoning row, a tool
target already rides `tool_start`'s complete `tool_args`, and a tool outcome
is on `tool_end` as structured fields. The client therefore reads `exit_code`
instead of parsing an `[exit: N]` footer out of the output — so the feed is
opt-in, and the flag is cleared on every new connection rather than latched,
because a client that did not declare it still does all three from the text.
The durable replay path is rewritten to match (`get_events_since` and the
snapshot bootstrap), or a reconnect would pull the dropped content back. A
page's cursor fields are computed *before* the rewrite: dropping an event
must not move `nextSinceIdx`, or a client resuming from it would re-fetch a
range whose events are always dropped. The folded projection riding a replay
page keeps its events and their `idx` — both the desktop and the client
reject an empty or reordered list — so only its text is blanked.
huichen
enabled auto-merge (squash)
September 25, 2026 16:32
This was referenced Sep 25, 2026
huichen
added a commit
that referenced
this pull request
Sep 25, 2026
…ll (#850) * test(mobile): verify the lean lane through the real render surface The lean lane's client half (#844/#846) is three reads: a reasoning row from its boundary alone, a tool target from `tool_start`'s complete arguments, and a tool outcome from `tool_end`'s structured fields. They are covered by unit tests against the projector, but nothing had fed them to the screens the phone actually draws. This adds a render fixture set and five screenshot-harness scenarios: - `scripts/screenshots/gen-lean-render-fixtures.mjs` authors the full-feed wire shapes (live lane and history page) and derives the lean ones through the shipping Rust trims (a new ignored test in `remote_host::lean`, driven the same way `measure-lean-history.py` drives its measurement) — so a capture cannot test a hand-trimmed paraphrase of the wire. - `?leanRender=<mode>` feeds those slices to the real conversation screen; the projection, components, i18n and layout stay the shipped implementation. - The scenarios assert the three reads plus the control: the same run as the full feed must not regress (reasoning body, `[exit: N]` outcome path), and the trimmed payloads must stay off screen. The mid-run scenario reproduces a real bug in the client half, fixed in the next commit: a bodyless reasoning slot after a tool call was swallowed by the tool run's "hop over whitespace-only text". * fix(thread-projection): keep a bodyless reasoning row after a tool call `buildSegments` gathers a run of adjacent tool slots while hopping over whitespace-only text between them. The hop tested `!current.text.trim()` for every slot type, so a reasoning slot with no body — the normal case in the lean feed, whose deltas are never published — read as whitespace and was dropped: its row disappeared, and the tool calls on either side of it were glued into one burst. Only a text slot can be glue between tools. A bodyless reasoning row after a tool call (the live tail of a run that thinks again, or between two calls) now renders, with a regression test for both shapes. * style(desktop): rustfmt the lean fixture generator The generator test was added while working in the mobile harness, so the desktop backend's rustfmt was never run on it. CI's `cargo fmt --check --manifest-path desktop/src-tauri/Cargo.toml` caught it. No behaviour change: rustfmt only.
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.
Problem
A run's live lane costs 67–77 MB raw / 4.2–4.6 MB after coalescing, and almost all of it is content no phone surface shows:
thinking_delta— 57–84% of the raw bytes, a per-token stream. The phone renders a collapsed "思考/思考中" row, never the text.tool_delta— 4–41%. It re-sends the accumulated argument snapshot per fragment; the row's target is already derivable fromtool_start's completetool_args.tool_end— carries the tool's captured output, of which the phone reads only the exit code.Change
A client that declares
lean_events_v1receives the same event lane with that content removed.thinking_delta,tool_delta,toolcall_deltatool_end/tool_resultexit_code,is_soft_fail,target_path,errorkeptrun_snapshotsnapshotEventsEvery other event is forwarded byte-for-byte, so a future event type cannot be silently reshaped. The per-token types are dropped on a slice compare before the queue, so the hot path never parses them; only the per-call types are parsed at all.
Measured effect
Through the shipping code over the three heaviest real runs —
scripts/measure-live-lane.pynow runs both lanes and prints the comparison:Message count matters as much as bytes: a phone pays an AEAD open, a JSON parse and a radio wake per message, not per byte.
Why this is a removal, not a fidelity trade
Three properties do the work:
thinking_start/thinking_endalone open and close a reasoning row; a tool's target already ridestool_start's completetool_args; and a tool's outcome is ontool_endas structured fields.The last one is why the client now reads
exit_codeinstead of parsing an[exit: N]footer out of the output — and therefore why the feed is opt-in: a client that did not declare it still does all three from the text. The flag is cleared on every new connection rather than latched, so an older build on the same pairing cannot inherit the previous client's declaration.Replay is trimmed too
Leaving
get_events_sinceand the snapshot bootstrap alone would pull the dropped content straight back on the next reconcile, so both are rewritten as well. One ordering constraint is load-bearing and documented at the call site: a page's cursor fields are computed before the rewrite. Dropping an event must not movenextSinceIdx/watermark, or a client resuming from that cursor would re-fetch a range whose events are always dropped — an endless loop.The folded projection that rides a replay page is treated differently on purpose: both the desktop and the client validate its events for length and ordering (and the desktop rejects an empty list), so its events keep their
idxand only the text is blanked.Verification
cargo fmt --check+cargo clippy --all-targets -D warningsclean (pinned 1.97).tsc --noEmit+eslintclean.tsc+eslintclean. Confirmed the tests resolve@future-os/thread-projectionto this worktree, not the main tree.thinking_deltathe first event on the wire; removing the structuredexit_coderead fails two tests; restoring the empty-text filter drops the reasoning row.Known, pre-existing, not from this diff
useSkillRecommendation→ "skips a skill already shown today" fails identically on clean main. The test seeds a UTC date (toISOString().slice(0,10)) while the hook uses the local day, so it only fails between 00:00 and 08:00 local. Worth a one-line fix in its own PR.prune_preview_cache_removes_expired_filesis flaky under full-suite load (passes in isolation; 3 full runs gave fail/pass/pass).preview_cache_dir()is one process-wide directory and a sibling test callsclear_preview_cache(), whichremove_dir_alls it. A test-isolation bug, not a behaviour bug.instance::tests::excludes_second_owner_and_releases_on_dropfailed once in a full run and passes everywhere else.Deliberately out of scope
Trimming history entries (
get_session_entries: reasoning text, tool-result text, toolarguments→ the four keys the client reads). That path needs a per-client field rewrite and touchesentry.role, which the mobile projector and the TUI read directly, so it deserves its own PR.