fix(client-runtime): load earlier history through folded activity #21957
main fromrefs/pull/21957/head·opened View on GitHubClicking "Load earlier turns" can appear to do nothing when a long completed run spans several history pages. Each click loads one slice, but the new activity stays inside the same collapsed "Worked for" group.
Keep loading until a page reaches a prompt, a notification boundary, or the end of history. Each request keeps the existing server limits. The loading indicator stays active between pages, and a failed request can be retried from the last successful cursor. Targeted history lookups keep their existing behavior.
Fixes #21821, which was accepted as a bug. This change is limited to the shared history loader and its tests. Related PR #21476 touches the same area but does not address this case.
84 focused tests pass. Coverage includes a 531-row history with a large output, empty pages, inherited history, turn boundaries, partial failure and retry, timeouts, concurrent clicks, cursor loops, cancellation, and replacement snapshots. The long-history regression fails against the original loader after one request and passes with eight bounded requests. Scoped lint and client-runtime typecheck also pass.
The screenshots use the real timeline component with controlled history fixtures in Chromium. The HTTP loader was tested separately. Native clients, live provider sessions, and remote transport were not exercised. Very long histories without a boundary can still require many sequential requests.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
c8724bcb-75ad-42d5-a005-865423d5e716
📥 Commits
-
Reviewing files that changed from the base of the PR and between 54983e3f458871dffe755ea908ffe0d60cea101b and ddefd930852e9faa21f0815b45282ba1145b7057.
📒 Files selected for processing: 2
-
packages/client-runtime/src/state/threads-sync.test.tspackages/client-runtime/src/state/threads.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
📝 Walkthrough
-
loadEarliernow continues across eligible history pages until it reaches a user-turn boundary or exhausts history. It also checks cursor progression and request ownership. Tests cover long histories, retries, errors, and concurrent state changes.Changes: Progressive history loading
Layer / File(s) Summary Continue paging through agent-started history
packages/client-runtime/src/state/threads.ts,packages/client-runtime/src/state/threads-sync.test.tsWhen a complete page has more history and no notification or turn-start/queued-turn user message, loadEarlierrequests another page. Tests cover varied page contents, long histories, and stopping at a user-turn boundary.Track cursor and request ownership
packages/client-runtime/src/state/threads.ts,packages/client-runtime/src/state/threads-sync.test.tsThe loader stops if progressive history metadata changes and reports an error for repeated, cyclic, or missing cursors. Tests cover timeout, retry, interruption, replacement, deletion, and concurrent loads. Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarminge,noojuno
Merge Risk: ⚪ Minimal · up to
ddefd-
This change makes "Load earlier turns" continue through folded activity until it reaches a boundary. Tests cover the main failure and retry cases. No merge-blocking risk was found. Very long histories without a boundary may take many sequential requests.
Security architecture risk: 🔵 Low · up to
ddefd-
The inspected changes preserve existing access controls and contain interrupted or failed requests. One loading action can now retrieve many pages, increasing resource use for exceptionally long histories.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The changed flow increases automatic reads and accumulated history for the selected environment and thread projection, including inherited rows returned for that projection. The inspected path does not add tenant, environment, credential, or tool authority; it increases the amount of work performed under existing authority.
Trust Boundaries and Controls
- observed — Every continued page uses the existing authenticated HTTP helper. That helper retains cookie, bearer, or DPoP handling; DPoP authorization requests name the expected environment, and proofs bind the method and constructed URL. The endpoint declaration retains authentication middleware. Server-side enforcement was not independently inspected.
Resilience and Maintainability Implications
- observed — Requests remain sequential, each history request has a six-second default timeout, and repeated, cyclic, or missing continuation cursors cause an error. These controls contain stalled requests and cursor loops, but do not impose an aggregate page, byte, or duration budget across distinct advancing cursors. This is a resource-containment tradeoff, not an established denial-of-service finding.
Hardening Proposals
- proposed — Consider an aggregate continuation budget that pauses with the last successful cursor preserved. This would bound per-action work for unusually large boundary-free histories without changing access controls or discarding partial progress.
-
Pre-merge checks:
4-
Check name Status Explanation Title check The title is concise, uses the repository's conventional format, and accurately describes the main change: loading earlier history through folded activity. Description check The description covers the problem, implementation, scope, linked issue, verification results, test coverage, screenshots, and known limitations. It provides enough detail to evaluate the change. Linked Issues check Issue #21821requires each "Load earlier turns" action to reveal earlier history across activity-only pages while retaining the existing request budget. In `packages/client-runtime/src/state/threads.t…Out of Scope Changes check The whole-PR changes are limited to the shared history loader in packages/client-runtime/src/state/threads.tsand its tests inpackages/client-runtime/src/state/threads-sync.test.ts. The added tes…Full details: Linked Issues check
-
Explanation
Issue
#21821requires each "Load earlier turns" action to reveal earlier history across activity-only pages while retaining the existing request budget. Inpackages/client-runtime/src/state/threads.ts,loadEarliercontinues with the returned cursor when a complete page has more history and has no notification orturn_start/queued_turnuser-message boundary. It keeps loading active between pages, preserves the cursor after failure, rejects cursor loops, and preserves targeted lookup behavior. Tests cover the 531-row, byte- and row-bounded regression and the stated boundary, retry, timeout, cancellation, and snapshot cases.
Full details: Out of Scope Changes check
-
Explanation
The whole-PR changes are limited to the shared history loader in
packages/client-runtime/src/state/threads.tsand its tests inpackages/client-runtime/src/state/threads-sync.test.ts. The added tests verify the linked issue behavior and related loader safety. The targeted-lookup test update preserves existing behavior. No unrelated product area or non-supporting change is shown.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Closing in favour of #24417, which makes the same change. Thanks for the work here!
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — The production history loader now automatically performs multiple sequential requests and merges pages based on data-dependent boundaries, while also changing loading, interruption, retry, and cursor-loop behavior. Despite strong focused test coverage and a localized diff, this is a material existing-path runtime change that merits human review.
Notes:
- Code review disabled. Approvability was decided on eligibility alone.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).