Repository navigation
fix(tui): load a transcript past tonic's 4 MiB default cap - #800
Merged
Merged
Conversation
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
enabled auto-merge (squash)
September 23, 2026 09:57
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.
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.
Symptom
Switching to a long session in the TUI:
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_messagesreturns 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_SIZEwas a private constant in two crates, so there was nothing for them to share).Change
future_rpc::transportnow owns the cap (MAX_GRPC_MESSAGE_SIZE) and a helperagent_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.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 byagent_client.tui/src/rpc/grpc_client.rs::oversized_transcript_loads— the reported path: a 6 MiBget_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-targetscargo clippy -p … --all-targets --no-deps -D warnings(the two 1.96nonminimal_boolhits 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 --checkon every touched crate (workspace +desktop/src-tauri)