Repository navigation
perf(rpc): omit unset optionals and a false isError from history entries - #849
Merged
Merged
Conversation
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
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
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.
This was referenced Sep 25, 2026
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.
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 field-level trims on the
SessionEntryPayload/MessageBlockcontract, 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/runsubfieldsMessageUsageandMessageRunwere the last structs in this contract withoutskip_serializing_if, so an entry carrying them spelled out every unset member. Nearly every entry carries arun, and its unset members were anullon each one.Measured through the shipping serde over the three heaviest real sessions, before and after reconciling exactly (
before − saved == afterfor all three):Null detail:
run.error×6,293 (13 B each) +usage.cacheWriteTokens×1.2.
isError: falseMessageBlock::is_erroris set from the journal withunwrap_or(false), so every non-failing tool result carried an explicit"isError": false. No consumer can tell that from an absent flag — the phone readsif (block.isError && …)— so the page spent ~15 bytes per tool result saying nothing happened.falseThat is ~1.35% of the trimmed page the phone actually receives, and it grows as a share as the other trims land.
trueis 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_nonerather than sitting beside it. Both uninformative spellings have to be skipped: with amatches!(_, Some(false))predicate alone,Nonestarts serializing asnullagain — 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
nullsubfield, or an explicitfalse/nullisError, 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'sget_statefixture, 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-rpc131 pass (129 + 2 new);cargo fmt --check+cargo clippy --all-targets -D warningsclean on pinned 1.97.future-agentsession::display,future-tui2095 pass, desktop backendremote_host::business+lean+bridge_tests::history— all pass.Some(false)-only predicate fails the unset case (this is the bug described above).