Skip to content

fix(tui): load a transcript past tonic's 4 MiB default cap - #800

Merged
huichen merged 2 commits into
mainfrom
fix/tui-grpc-limit
Sep 23, 2026
Merged

huichen merged 2 commits into
mainfrom
fix/tui-grpc-limit

Conversation

@huichen

@huichen huichen commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Symptom

Switching to a long session in the TUI:

Switched to session: Jev 技能推荐 — its transcript could not be loaded
(Error, decoded message length too large: found 10342115 bytes, the limit is: 4194304 bytes).

Cause

The Agent encodes responses up to MAX_GRPC_MESSAGE_SIZE (32 MiB), but tonic's decoding limit is 4 MiB and applies per client. get_messages returns a whole session transcript in one message, so a 10 MB session was encoded fine by the Agent and then rejected by the TUI's client — which had never raised the limit. The desktop did raise it; the TUI, CLI, channel and loop clients did not (MAX_GRPC_MESSAGE_SIZE was a private constant in two crates, so there was nothing for them to share).

Change

  • future_rpc::transport now owns the cap (MAX_GRPC_MESSAGE_SIZE) and a helper agent_client(channel) that builds the generated client with it applied to decoding and encoding — the crate that owns the wire contract is the single place the two ends can agree.
  • Every Rust client builds through the helper: TUI (unary calls, event stream, print mode, agent health probe), CLI, channel bridge, loop. The desktop's three call sites use it too, and it keeps its own gRPC channel cache untouched.
  • The Agent server's private constant is gone — it uses the shared one, so a response can no longer be encoded larger than a client is willing to decode.

The desktop already carried the 32 MiB cap, so its behaviour is unchanged; this is why the same session loaded there but not in the TUI.

Tests

  • packages/rpc/tests/wire_roundtrip.rs::agent_client_decodes_a_response_past_tonics_default_limit — pins the asymmetry at the wire layer: a 5 MiB response is rejected by a plain generated client and decoded by agent_client.
  • tui/src/rpc/grpc_client.rs::oversized_transcript_loads — the reported path: a 6 MiB get_messages (the switch-session transcript load) decodes instead of failing.

Verification

  • cargo test -p future-rpc -p future-tui -p future-cli -p future-loop; cargo test -p future-channel --lib; cargo test -p future-agent --lib grpc::
  • cargo check --manifest-path desktop/src-tauri/Cargo.toml --all-targets
  • cargo clippy -p … --all-targets --no-deps -D warnings (the two 1.96 nonminimal_bool hits are pre-existing local-toolchain false positives in untouched code — channels/src/feishu/feishu_rest.rs:317, agent/src/session/compaction_ops.rs:79; CI runs the pinned 1.97)
  • cargo fmt --check on every touched crate (workspace + desktop/src-tauri)

Switching to a long session failed with "its transcript could not be
loaded (Error, decoded message length too large: found 10342115 bytes,
the limit is: 4194304 bytes)": the Agent's own cap is 32 MiB, so the
10 MB `get_messages` response was encoded fine and only the TUI's client
rejected it. tonic's *decoding* default is 4 MiB and applies per client
— the desktop had raised it, the TUI (and the CLI, channel and loop
clients) never did.

Own the cap once in `future_rpc::transport` (`MAX_GRPC_MESSAGE_SIZE`)
and build clients through `agent_client(channel)`, which applies it to
decoding and encoding. Every Rust client goes through it now, and the
Agent server uses the same constant, so a response can never be encoded
larger than a client will decode.

Regression tests: a 6 MiB transcript decodes through the shared client
at the TUI layer, and a 5 MiB response proves the asymmetry at the wire
layer (a plain generated client rejects it, `agent_client` decodes it).
@huichen
huichen enabled auto-merge (squash) September 23, 2026 09:57
@huichen
huichen merged commit cb90f5d into main Sep 23, 2026
12 checks passed
@huichen
huichen deleted the fix/tui-grpc-limit branch September 23, 2026 10:06
huichen added a commit that referenced this pull request Sep 23, 2026
* test(tui): re-record the help goldens stale since /skill-recommend

`make test-tui-tmux` was already red on main: #798 added the
`/skill-recommend` row to the help card but did not re-record the three
goldens that show it (they still read "↓ 26 more" / "↑ 26 above"). The
Rust pane was byte-compared against them and lost.

Recorded with `tui/tests/tmux-diff.sh --record`; the only changes are the
new row and the two counts it shifts.

* feat(tui): page session history instead of loading it whole

Switching to a long session read its entire transcript in one response
(`get_messages`), which is why a 10 MB session stalled and why a session
past the 32 MiB wire cap could not be opened at all (#800 raised the
client cap; this removes the unbounded read).

The TUI now reads display history through the agent's indexed pager:
`get_session_entries` with the exclusive backward cursor `before`
(`i64::MAX` = the tail) and `limit` counted in user exchanges. A switch
loads the newest ten exchanges; scrolling up past the top of the
transcript fetches the ten before those, until the session begins. Each
page is bounded, and the rows are the same display projection the
desktop renders.

- `SessionEntriesPage` (tui/src/rpc/types.rs) parses a page and keeps the
  continuation cursor. It also accepts the legacy whole-history
  `messages` shape, so one mapper renders both.
- `load_history_tail` reads the tail page and falls back to
  `get_messages` when the pager answers with nothing *or* errors: an
  agent that predates backward paging, and a session with no persisted
  history (e.g. an ephemeral one, which the pager rejects), still have a
  live context — "no page" must not read as "no conversation".
- `App::history_paging` holds the cursor, keyed by session id: a page
  that was in flight when the user switched away is dropped instead of
  prepended into another transcript, and a page that claims more history
  without advancing its cursor ends the walk (the guard the desktop's
  page loop already applies).
- `ChatArea::prepend_messages` inserts above the transcript and shifts
  `viewport_top` by the height it measured, so the reader keeps their
  place. When the reader is still at the top (the normal case — that is
  what triggered the load), the view is moved to show the loaded page
  instead of anchoring to invisible rows.
- `HistoryWriter::shift`/`rebase` keep the scrollback watermark aligned:
  the terminal scrollback is append-only, so prepended rows are never
  written there, and the next flush must not mistake the shifted
  transcript for new content and write a second copy.
- History rows now render the compaction checkpoint the mapper already
  handled (it was unreachable through `get_messages`, whose LLM wire shape
  has no `kind`/`checkpoint`).

Fallback: an empty/failed pager read still ends at `get_messages`, which
is the previous behaviour and now only runs when paging cannot answer.

Verified against the real agent (isolated home, real journal): with 14
planted exchanges, `before=i64::MAX, limit=10` returns e2e-05..reply-14
with `hasMore`/`nextOffset=8`, the next page returns the rest with no
cursor, and the real TUI in tmux loads the tail on switch and the older
page on PageUp.
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