perf(client): load older thread history on demand #21476
takeover/terminal-preview-24/viewport-server fromtakeover/terminal-preview-24/viewport-client·opened View on GitHubStack: #21475 (server/contracts) → #21476 (client hydration).
Large threads still open with whole tool-heavy turns. This client layer opts into the server viewport, merges older history on demand, and preserves prompt recall and rewind for messages outside the first window.
History support fills missing entities without overwriting live state; deferred checkpoint file lists hydrate only while their metadata still matches. Cache v5 discards incompatible v4 entries on upgrade and protects rollback to older clients. Mobile Review retains historical file counts. ArrowUp loads one older page at a boundary and cancels on edits or changed composer context; paged prompts can still use Edit from here.
Rebuilt from @maria-rcks’s #18220. This is the client layer of a two-layer replacement based on current main. The combined rebuild is 30 files, 1,818 additions and 143 deletions, compared with the original 99-file layer. Rendering, sidebar, editor, settings, bootstrap and native cleanup churn were omitted; current main already contains the related rendering/persistence improvements. This PR makes no paint, typing or streaming latency claim.
Focused regressions: initial client/cache suites 64/70 → 70/70; recall and HTTP view requests 66/73 → 73/73; rewind 136/137 → 137/137 (extended an existing test). Scoped lint, formatting and web/client-runtime/mobile typecheck pass. Final integrated check: all 374 tests across the ten changed test files pass. Independent Claude Opus 5.5 and GPT-6-Sol whole-stack reviews covered fork isolation, legacy clients/servers, live hydration races and composer history; all confirmed findings were fixed and rechecked.
Live Linux web proof uses disposable synthetic projections, without starting an agent turn. On the same 5,002-row thread, the legacy compact HTTP response remains 3,694,234 bytes while the viewport response is 58,369 bytes and 76 rows (75 plus its initiating prompt): 98.42% fewer bytes. Load earlier turns retrieves the remaining 4,927 rows and exposes command 0001. Prompt and final answer remain visible once, composer input and cache reload work. A separate 10-turn fixture verifies ArrowUp from prompt 10 to paged prompt 9, and a paged prompt’s Edit from here confirmation opens and cancels. Rewind completion and run guards are covered by the focused event/milestone test; a real provider rollback was not dispatched against this synthetic fixture.
Before: whole-turn snapshot, 5,002 visible rows (main 9077e818d8, actual baseline capture).

After: 76 initial rows with earlier history available (current implementation).

Paging interaction (a functional recording, not a latency benchmark):
Older command 0001 after hydration:

Not verified here: Electron desktop, macOS, Windows, iOS or Android runtime. Shared cache, history and checkpoint-count behavior was typechecked for the affected clients. Remote/relay/tunnel transports and provider-specific rollback were not exercised live.
Five independent whole-stack review rounds completed; both final reviewers found no confirmed code blockers. Earlier findings fixed fork control isolation, boundary prompts, indexed reads, paged recall and rewind. A suggested optimization to skip one batched metadata refresh per history page was left out because no regression was measured.
Prompt-budget regression: with a 20,000-byte policy, the initiating prompt and tail previously encoded to 33,799 bytes; the window now includes prompt costs and fits in 18,702 bytes. The existing test also recovers all 303 rows through cursors and preserves unavoidable oversized prompts with an explicit overflow flag. No test-count increase.
Checkpoint-budget regression: the final viewport now defers file lists for inactive runs removed by byte trimming, while preserving files for visible runs and active controls. The existing fixture falls from 1,092,600 to 898,006 bytes; 25/26 → 26/26 passing, with no test-count increase. Source projections and legacy file lists remain unchanged.
The current proof was rechecked against the final diff: the client patch is unchanged after the server fixes, and the measured synthetic thread has no checkpoint files affected by the final deferral change.
The byte policy remains a soft limit when mandatory control state or a single required row and its prompt are larger than the available budget. The overflow flag reports the final encoded payload. Human approval is still required for this feature; no merge is requested.
Implemented with Codex GPT-6.1-Sol; tests with GPT-6-Astra; independent reviews with Claude Opus 5.5 and GPT-6-Sol, through T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge changed the title
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge added labelsmacroscope-review
Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
019417c4-870e-4cf8-9436-be44dc34bf88
📥 Commits
-
Reviewing files that changed from the base of the PR and between e172ad80cdfe6fc80a78cc2ecfd89190234fe106 and 2c4cf9a4bd0130402a902eae3e2be596fb96522e.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- 🔍 Trigger review
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
b8215a13-6426-44cf-9843-86cc808ca042
📥 Commits
-
Reviewing files that changed from the base of the PR and between 50e81b87fa6e3757d3262e96d5d54f3da649d269 and e172ad80cdfe6fc80a78cc2ecfd89190234fe106.
📒 Files selected for processing: 18
-
apps/mobile/src/features/review/reviewModel.tsapps/web/src/components/ChatView.logic.test.tsapps/web/src/components/ChatView.logic.tsapps/web/src/components/ChatView.tsxapps/web/src/components/chat/ChatComposer.tsxapps/web/src/components/chat/composerPromptHistory.test.tsapps/web/src/components/chat/composerPromptHistory.tspackages/client-runtime/src/platform/orchestrationCache.test.tspackages/client-runtime/src/platform/orchestrationCache.tspackages/client-runtime/src/state/boundedThreadSnapshotHttp.test.tspackages/client-runtime/src/state/boundedThreadSnapshotHttp.tspackages/client-runtime/src/state/environmentHttpAuth.test.tspackages/client-runtime/src/state/threadCheckpoints.tspackages/client-runtime/src/state/threadHistoryHttp.tspackages/client-runtime/src/state/threadHistoryMerge.test.tspackages/client-runtime/src/state/threadHistoryMerge.tspackages/client-runtime/src/state/threads-sync.test.tspackages/client-runtime/src/state/threads.ts
Limit details: You’ve used all 10 included reviews currently available.
-
📝 Walkthrough
-
The change adds support and viewport data to thread-history requests, merges older pages and deferred checkpoint files into projections, and enables paged prompt recall in the composer. Rewind tracking can also resolve a target run from a visible local user turn item.
Changes: Paged thread history and prompt recall
Layer / File(s) Summary Request history and viewport support
packages/client-runtime/src/state/threadHistoryHttp.ts,packages/client-runtime/src/state/boundedThreadSnapshotHttp.ts,packages/client-runtime/src/state/threads.ts,packages/client-runtime/src/state/*test.tsHistory requests without a view include support data. Bounded snapshot subscriptions request viewport-window data. Tests cover request parameters and subscription flags. Merge older pages and checkpoint support
packages/client-runtime/src/state/threadHistoryMerge.ts,packages/client-runtime/src/state/threadHistoryMerge.test.ts,packages/client-runtime/src/state/threads-sync.test.ts,packages/client-runtime/src/state/threadCheckpoints.ts,packages/client-runtime/src/platform/orchestrationCache.ts,packages/client-runtime/src/platform/orchestrationCache.test.ts,apps/mobile/src/features/review/reviewModel.tsOlder pages merge support entities and visible items into the projection. Matching older checkpoints can supply deferred files. Checkpoint summaries, cache versioning, and the mobile subtitle account for deferred file counts. Load and navigate paged prompt history
apps/web/src/components/ChatView.tsx,apps/web/src/components/chat/ChatComposer.tsx,apps/web/src/components/chat/composerPromptHistory.ts,apps/web/src/components/chat/composerPromptHistory.test.tsChatView supplies visible user-message history and an older-page callback to server-thread composers. ChatComposer can load earlier history during backward navigation and cancels stale or blocked recalls. Tests cover cancellation, failures, and retries. Rewind tracking
Layer / File(s) Summary Resolve rewind target from visible turn items
apps/web/src/components/ChatView.logic.ts,apps/web/src/components/ChatView.logic.test.tsThe rewind wait can resolve a target run from qualifying visible user turn items when projected messages do not contain it. The test waits for the target run to become rolled back after an earlier rollback failure. Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Feature
Sequence Diagram(s)#
sequenceDiagram participant ChatComposer participant ChatView participant ThreadsState participant ThreadHistoryEndpoint ChatComposer->>ChatView: request older prompt history ChatView->>ThreadsState: load earlier history page ThreadsState->>ThreadHistoryEndpoint: fetch page with cursor and support data ThreadHistoryEndpoint-->>ThreadsState: return history page ThreadsState-->>ChatView: update projection and history cursor ChatView-->>ChatComposer: resolve page-load callback ChatComposer->>ChatView: read refreshed prompt historySuggested reviewers:
maria-rcks
Merge Risk: ⚪ Minimal · up to
e172a-
This change adds paged thread history and prompt recall in the composer, and it requests support data and the viewport window from the server. The cache schema version is bumped, so old thread caches are discarded. No concrete merge-blocking problem was identified.
Pre-merge checks:
4-
Check name Status Explanation Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Title check The title clearly summarizes the primary change: loading older client thread history on demand. Description check The description clearly explains the problem, implementation, scope, compatibility behavior, verification results, UI evidence, limitations, and review status. It provides substantial detail for the r… Full details: Description check
-
Explanation
The description clearly explains the problem, implementation, scope, compatibility behavior, verification results, UI evidence, limitations, and review status. It provides substantial detail for the required sections.
-
✨ Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Thanks for the client work. #24589 (553203c57b) bounds long-turn snapshots, and #26240 supplies older-history loading across clients. Please cut this down to the remaining paged composer prompt recall and checkpoint-file hydration needed by the server remainder, rather than adding another viewport loading path.
Note
🤖 Claude Fable 5.2 responding on behalf of Theo
Closing with #21475. Older history loads on demand since #26240, and rewind works for paged prompts on
main.One part is not on
main: ArrowUp prompt recall past the loaded window.mainrecalls prompts from the loaded window only. That is a feature, not a perf gain, and needs its own small PR if we want it.t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — This PR adds asynchronous older-history loading and changes initial thread hydration from the previous bounded history shape to a viewport-window flow, with corresponding support metadata, checkpoint hydration, rollback, and cache behavior. Because these defaults affect existing users and activate substantial downstream processing, the changes warrant human review.
No code changes detected at
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).2c4cf9a. Prior analysis still applies.