Skip to content

perf(rpc): omit unset optionals and a false isError from history entries - #849

Merged
huichen merged 6 commits into
mainfrom
perf/omit-false-iserror
Sep 25, 2026
Merged

huichen merged 6 commits into
mainfrom
perf/omit-false-iserror

Conversation

@huichen

@huichen huichen commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Two field-level trims on the SessionEntryPayload / MessageBlock contract, both the same class as #842: a field that carries no information when it is unset, on a page that mostly consists of such fields.

1. usage / run subfields

MessageUsage and MessageRun were the last structs in this contract without skip_serializing_if, so an entry carrying them spelled out every unset member. Nearly every entry carries a run, and its unset members were a null on each one.

Measured through the shipping serde over the three heaviest real sessions, before and after reconciling exactly (before − saved == after for all three):

entries before B after B saved share
6,300 12,357,563 12,275,730 −81,833 −0.66%
2,462 4,809,110 4,777,095 −32,015 −0.67%
2,166 3,748,708 3,720,576 −28,132 −0.75%

Null detail: run.error ×6,293 (13 B each) + usage.cacheWriteTokens ×1.

2. isError: false

MessageBlock::is_error is set from the journal with unwrap_or(false), so every non-failing tool result carried an explicit "isError": false. No consumer can tell that from an absent flag — the phone reads if (block.isError && …) — so the page spent ~15 bytes per tool result saying nothing happened.

blocks with false before KiB after KiB saved
3,144 11,141.9 11,092.7 49.1 KiB (0.44%)
1,242 4,144.0 4,124.6 19.4 KiB (0.47%)
1,072 3,118.0 3,101.2 16.8 KiB (0.54%)

That is ~1.35% of the trimmed page the phone actually receives, and it grows as a share as the other trims land. true is still written — the only value that carries information — and this pairs with recording the real outcome, so a success will send no flag at all once failures set it.

The predicate replaces Option::is_none rather than sitting beside it. Both uninformative spellings have to be skipped: with a matches!(_, Some(false)) predicate alone, None starts serializing as null again — undoing #842. My own test for the unset case caught exactly that before it went anywhere.

Compatibility

Serialization-only in both cases. Deserialization is untouched: an explicit null subfield, or an explicit false/null isError, from an older peer or a cached page decodes to the same value. Pinned by tests.

The one expectation that had to change is packages/rpc/src/parity.rs's get_state fixture, which asserts the canonical output shape — updated to the new canonical value (a tighter exact-object assertion, not a relaxed one) with a comment saying why.

Verification

  • future-rpc 131 pass (129 + 2 new); cargo fmt --check + cargo clippy --all-targets -D warnings clean on pinned 1.97.
  • Consumers of the changed wire crate: future-agent session::display, future-tui 2095 pass, desktop backend remote_host::business + lean + bridge_tests::history — all pass.
  • Falsified: making the predicate never-skip fails "a false flag must be omitted"; a Some(false)-only predicate fails the unset case (this is the bug described above).

A `run` object rides nearly every history entry, and a completed run has
only some members set, so the serializer spelled the rest out as `null`.
Measured through the shipping serializer over three real sessions'
`get_session_entries` dumps, those nulls are 0.66-0.75% of the page:

  session1  12,357,563 -> 12,275,730 B  (-81,833: run.error x6,293,
                                                   usage.cacheWriteTokens x1)
  session2   4,809,110 ->  4,777,095 B  (-32,015: run.error x2,459,
                                                   usage.cacheWriteTokens x2)
  session3   3,748,708 ->  3,720,576 B  (-28,132: run.error x2,164)

- `MessageUsage` and `MessageRun` now carry `skip_serializing_if`, matching
  `MessageBlock` / `SessionEntryPayload`. Deserialization is unchanged: an
  explicit `null` written by a peer or cached page decodes as before, which
  the new tests pin in both directions.
- Every consumer reads these through optional access: the shared
  thread-projection `SessionEntry` declares each subfield optional-null and
  reads it under `?.` / `!= null` guards, Rust consumers only map Options to
  proto (or never read the fields). The one exact-shape expectation, the
  get_state parity fixture, moves to the new canonical output.
- `tests/measure_usage_run_nulls.rs` is the ignored instrument that produced
  the numbers (and reproduces the "before" line on a base-commit checkout).
`MessageBlock::is_error` is set from the journal with
`unwrap_or(false)`, so a tool result that is not an error carries an explicit
`"isError": false` on the wire. No consumer can tell that from an absent
flag — the phone reads `if (block.isError && …)` — so a history page was
spending ~15 bytes on every tool result saying nothing happened:

  blocks with false   before KiB   after KiB   saved
              3,144     11,141.9    11,092.7   49.1 KiB (0.44%)
              1,242      4,144.0     4,124.6   19.4 KiB (0.47%)
              1,072      3,118.0     3,101.2   16.8 KiB (0.54%)

That is ~1.35% of the trimmed page the phone actually receives, and it grows
as a share as the other trims land.

`true` is still written: it is the only value that carries information, and
this pairs with recording the real outcome — once failures set it, a success
sends no flag at all instead of a `false`.

The predicate deliberately replaces `Option::is_none` rather than sitting
beside it, because both uninformative spellings have to be skipped: with
`is_false` alone, `None` would have started serializing as `null` again,
undoing #842. A test for the unset case caught exactly that.

Deserialization is unchanged: an explicit `false` or `null` from an older
peer (or a cached page) still decodes to the same value.
@huichen
huichen enabled auto-merge (squash) September 25, 2026 18:08
… case

`get_session_entries_renders_roles_and_run_stats` asserted
`blocks[0].isError == false`, which is the old canonical shape: a successful
tool result no longer writes the flag, because every consumer already reads
an absent `isError` as "not an error".

Rather than only relaxing the assertion to "the key is absent", which would
also pass if the flag were dropped unconditionally, the fixture now carries a
second, failing tool call and asserts `isError == true` on it. That keeps the
informative value covered at this layer, where before only the `false` case
was.

Caught by CI, not by my local scoping: I had run the consumer crates' modules
closest to the change and missed this file. The full `future-agent` lib run
(1876) is what actually covers it.
Missed rustfmt after editing the fixture; CI's workspace fmt check caught it.
No behaviour change.
@huichen
huichen merged commit d69fae2 into main Sep 25, 2026
12 checks passed
@huichen
huichen deleted the perf/omit-false-iserror branch September 25, 2026 19:16
huichen added a commit that referenced this pull request Sep 25, 2026
`excludes_second_owner_and_releases_on_drop` failed 3 times in ~20 full-suite
runs and never once in isolation (150 single runs, 320 concurrent runs of the
same test binary, several full-suite runs). Each time with only:

    assertion failed: InstanceGuard::at(directory.path()).is_ok()

That says nothing about *why*. The failure is on the re-acquire **after**
`drop(guard)` — not on the contended-acquire assertion, which is what I had
assumed before capturing the real message — so the two candidates are "the lock
was not released" and "the `open` failed for an unrelated reason". Those point
at completely different owners, and one of them is a real product bug.

The assertion now reports the error, so the next occurrence is diagnosable
instead of costing another investigation. No behaviour change: the test asserts
exactly what it did before.

One hypothesis already ruled out: **file-descriptor exhaustion**. The suite runs
1312 tests green under `ulimit -n 256`, so the library's own fd use is not
near the limit.

Not fixed — diagnosed. This is deliberately not part of the payload-trim PR
(#849): unrelated subject, and it should be reconsidered if the cause turns out
to be a product bug.
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