Skip to content

perf(remote): fetch a lean shell row's command on tap (#851) - #851

Merged
huichen merged 5 commits into
mainfrom
perf/lazy-shell-args
Sep 25, 2026
Merged

huichen merged 5 commits into
mainfrom
perf/lazy-shell-args

Conversation

@huichen

@huichen huichen commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

A lean history page kept every shell call's arguments, and on the heaviest sessions the commands alone were ~1/3 of the bytes a phone actually reads — bytes no phone surface shows until the row is opened. The trim now drops a shell-like call's arguments whole (read/write/edit keep the path keys their row label derives from), and the row fetches its command back by identity when it is opened.

  • agent: new get_tool_call_args reads one call's name/arguments from message_blocks by (session, run, tool_call_id), mirroring get_tool_output (miss = explicit nulls, never another call's arguments).
  • desktop remote host: the command is reachable only while the client's lean_events_v1 declaration is in force. An undeclared client gets the same Unsupported command an older bridge would give, and its pages still carry every argument (behaviour unchanged).
  • mobile: a history tool row with no target and a call identity fetches it on tap through useConversationController (cached per session+run+call, so a virtualized remount never re-asks), shows the command, and leaves the row exactly as it was when the fetch fails. The page and the row carry toolCallId + the entry's runId for exactly this.

Measured (real sessions, shipping trim, per phone page)

python3 scripts/measure/measure-lean-history.py --sessions 3 --pages 3 (new --pages mode: the phone's own backward pages, 3 user exchanges each, newest first; the trim and byte counts run in the shipping Rust code):

session pages untrimmed old trim this change Δ vs old trim
20260922-121436 30 11.75 MiB 3.85 MiB 2.83 MiB −1.02 MiB (−26.5%)
20260902-134522 9 4.56 MiB 1.25 MiB 0.94 MiB −0.31 MiB (−24.8%)
20260902-135436 6 3.56 MiB 1.13 MiB 0.77 MiB −0.36 MiB (−31.9%)
all 45 pages 45 19.87 MiB 6.23 MiB 4.54 MiB −1.69 MiB (−27.1%)

First page (first screen) of the top session: 236 entries, 396,653 B untrimmed → 168 KiB under the old trim → 109,527 B now (−34.8% vs old). Average per-page saving vs the old trim 27.9% (12.5–50.0%).

Validation

  • agent: cargo test -p future-agent --lib get_tool_call_args (hit/miss/cross-session/cross-run) — 1882 lib tests green.
  • rpc: cargo test -p future-rpc --lib (command policy).
  • desktop: cargo test --lib remote_host::lean (trim unit tests) and the two bridge e2e tests lean_history_trims_only_for_a_client_that_declared_it / tool_call_args_is_reachable_only_for_a_client_that_declared_lean (declared vs undeclared, identity forwarded to the agent, missing identity refused locally, withdrawal takes the command away).
  • mobile: npx jest --runInBand (2060 tests), tsc --noEmit, eslint; desktop npx vitest run (1255 tests) for the shared-package consumers.
  • clippy --all-targets -D warnings on future-agent, future-rpc and desktop/src-tauri.

Real-data audit: the newest page of the heaviest session keeps toolCallId on all 120 calls and runId on all 113 assistant entries, while shell rows lose arguments (file rows keep path); the same call resolves in the live agent.db to shell|{"command":"cd ... && git ..."}. A running agent that predates this change answers unknown command: get_tool_call_args, which is exactly the failure the row must (and does) tolerate.

A lean history page kept every shell call's arguments, and on the heaviest
sessions the commands alone were ~1/3 of the page a phone actually reads —
bytes no phone surface shows until the row is opened. The trim now drops a
shell-like call's `arguments` whole (read/write/edit keep the path keys their
row label is derived from), and the row fetches its command back by identity
when it is opened:

- agent: `get_tool_call_args` reads one call's name/arguments from
  message_blocks by (session, run, tool_call_id), mirroring `get_tool_output`.
- desktop remote host: the command is reachable only while the client's
  `lean_events_v1` declaration is in force; undeclared clients get the same
  "Unsupported command" an older bridge would give, and their pages still
  carry every argument (behaviour unchanged).
- mobile: a history tool row with no target and a call identity fetches it on
  tap through `useConversationController` (cached per session+run+call, so a
  virtualized remount never re-asks), shows the command, and leaves the row
  exactly as it was when the fetch fails.
@huichen huichen changed the title perf(remote): fetch a lean shell row's command on tap perf(remote): fetch a lean shell row's command on tap (#851) Sep 25, 2026
@huichen
huichen enabled auto-merge (squash) September 25, 2026 18:18
The measurement script reports bytes; this one reports the shape behind them —
which argument keys a shell row keeps versus loses, and that the toolCallId and
runId a lazy fetch needs survive — through the same shipping Rust trim.
Merging origin/main brought the lean render-verification fixtures (#850), which
are generated *through* the shipping trims — so this change's trim (a shell
call's arguments are now fetched on open, not carried by the page) has to
regenerate them, and the generator's self-check has to assert the new rule
(file rows keep a path, shell rows keep nothing).

The harness also answers the on-open fetch from the full page, so the history
scenario keeps asserting that the command appears after the tap — now through
the same lazy path the phone uses. Falsified by making the mock resolver return
null: the scenario then fails with 'the history row target is wrong'.

Re-captured locally on http://localhost:8098: lean-render-history, -live,
-live-mid, -full, -full-history all pass (the live lane still shows commands —
it never trimmed them).
@huichen
huichen merged commit 0fe0319 into main Sep 25, 2026
22 of 24 checks passed
@huichen
huichen deleted the perf/lazy-shell-args branch September 25, 2026 18:54
huichen added a commit that referenced this pull request Sep 25, 2026
… shape (#855)

The render fixtures froze the pre-#848/#849 wire: every history
`tool_result` spelled out `isError` — `false` on the exit-127 failure and on
the successes (which never carry a flag now), and `true` only on a
hand-authored probe row. `lean-render-history` asserted that shape, so it
would have stayed green against a page the phone no longer receives.

- the full fixture records the real failure (`isError: true` on the exit-127
  call) and omits the uninformative flag everywhere else (#849);
- the lean page is regenerated through the shipping trim, and the generator's
  self-check asserts the shape on both the full page and its trimmed form;
- both history scenarios flip: the exit-127 row reads 运行失败 (its command
  still arrives through the on-open fetch #851 added) and the soft-fail grep
  reads 已运行. lean-render-full-history's single failing row is that same
  recorded failure.

Verified in the real mobile render surface: all five lean scenarios pass, the
two new assertions were falsified (dropping the fetch trigger and restoring
the old `isError: false` shape each fail the step), and the live full-feed
`failed === 2` check still holds.
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