Skip to content

feat(ios): load older chat history without losing your place - #199038

Closed
roboclaw-bot wants to merge 1 commit into
mainfrom
openclaw/ios-older-history-paging
Closed

roboclaw-bot wants to merge 1 commit into
mainfrom
openclaw/ios-older-history-paging

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #192232

Stacked on #192232 (Marvinthebored) at d3363988721e329abce8d2d6dbd6db51b82f120e, open and not modified. The publisher squashed that head, merged cleanly with main 1ac07b333, plus the authored change into one commit, so #192232's changes appear here: do not merge before #192232; rebase after it lands. Authored delta only: git diff $(git merge-tree --write-tree d3363988721e329abce8d2d6dbd6db51b82f120e 1ac07b333) f1a51ca1d6b9930a6bce819a80f9e73f332f7b79.

What Problem This Solves

Native iOS chat shows only the latest history page; older messages cannot be loaded, so long conversations are cut off at the top.

User Impact

Scrolling toward the top of a chat loads earlier messages automatically, and the message you are reading stays exactly where it was. A small, localized Show earlier messages control at the top of the transcript appears only when older history exists; it covers chats too short to scroll and is reachable by VoiceOver and Switch Control as an ordinary button. At most three earlier pages stay in memory: the farthest page is dropped and reloaded on return, and returning to the latest message releases them. Grouping, word fade, sidebar animation and live-edge behavior are unchanged.

Draft for the Mac verification loop: native build, tests, screenshots and performance are pending; no Swift toolchain was available, so no Swift test has run.

Why This Change Was Made

Native chat discarded the olderCursor/newerCursor/windowReset fields chat.history already returns; the iOS transport already forwards opaque cursors. No Gateway protocol change.

  • Separate owner. ChatOlderHistory keeps the pages read above the live tip. The live delta/outbox owner keeps the tip; a full tip read only reports its new first row and boundary, so trimmed rows join the newest page. A tip that no longer reaches the pages ends them rather than showing a gap.
  • Staleness. A page is admitted only while its session, route/cursor generation and boundary are unchanged; session/agent/route/branch switches, rewind, reset and compaction cancel reads and discard pages. windowReset means the boundary is unusable, not exhausted: pages and boundary drop until the next full tip read.
  • Sizes from source. Pages are the Gateway's default 200 rows (limit ?? 200, src/gateway/server-methods/chat-history-handler.ts) under the iOS transport's existing 256 KiB cursor budget. The resident window is three read pages (≤600 rows, ≤768 KiB of page payload) beside the tip. One action reads at most three consecutive pages that add no visible rows, matching Control UI (docs/web/control-ui.md).
  • Bounded window. Reading up past three pages drops the newest read page and shows only the read pages (no live edge or live work at their bottom). Scrolling down rereads with newerCursor, drops the farthest page above, and reattaches at the tip. Jump to latest or sending returns to the tip.
  • Reader position. ChatReaderPageAnchor records realized rows' content positions before a page change and, after List lays it out (a scroller layout sentinel, since equal-height swaps keep the content size), shifts the offset by their content-relative move. It never undoes the reader's scrolling and ends once settled; at the live edge the existing follower owns the offset.
Accepted edge cases and integration points

Accepted edge cases (rare, recoverable):

  • A full tip read that no longer meets the pages (e.g. reconnecting after a page of new messages) ends them.
  • Rows the tip hands to the newest page while the reader is away from the live edge stay until they return, like the tip's own delta growth.
  • A chat shorter than two screens does not auto-load, because the reader never crosses the threshold; the top control covers it.
  • Question cards and the subagent-wait row keep their place at the bottom even while a window has left the tip.
  • The shared protocol's default cursor read returns the tip; only the iOS Gateway transport and the paged fixture read pages, and the control is iOS-only.

Integration points with frozen drafts (not edited):

Evidence

Checked here:

  • Two local P0–P2 autoreview passes on the authored delta. The first found four P2s: three fixed (equal-height swaps skipping the offset hold; a stale read leaving paging stuck; snapshot rows duplicated after a window returned — the last two with regressions), one accepted above (tip-transferred rows). The second pass was clean.
  • pnpm native:i18n:verify: changed=false after baseline.

Authored, not run (no Swift toolchain here):

  • ChatOlderHistoryTests: boundary decoding, seam stitching across tip slide/gap, snapshot de-duplication, three-page eviction/reread/reattach, replaced-session and moved-boundary reads discarded, windowReset ending pages (not exhaustion).
  • UI tests on the synthetic 2,000-row --openclaw-paged-history-fixture: accessible labeled button in a two-row chat loads the page above; a held page lands above the reader's row within 1 pt.

Pending Mac verification

At f1a51ca1d6b9930a6bce819a80f9e73f332f7b79 with Xcode/Swift 6.3 and a task-owned simulator:

test "$(git rev-parse HEAD)" = f1a51ca1d6b9930a6bce819a80f9e73f332f7b79
swift test --package-path apps/shared/OpenClawKit --filter 'ChatOlderHistoryTests|ChatHistoryDeltaTests|ChatReaderScrollStateTests|ChatViewModelTests' --no-parallel
scripts/lint-swift.sh ios
scripts/format-swift.sh ios
pnpm native:i18n:verify
pnpm ios:build
IOS_SIM="<task-owned simulator UDID>" pnpm ios:test \
  OpenClawUITests/OpenClawSnapshotUITests/testShortChatOffersEarlierMessagesAsAnAccessibleButton \
  OpenClawUITests/OpenClawSnapshotUITests/testEarlierPageLandsAboveTheReaderWithoutMovingIt \
  OpenClawUITests/OpenClawSnapshotUITests/testKeyboardOpenPreservesTranscriptAndFollowsLiveEdgeAfterSend \
  OpenClawUITests/OpenClawSnapshotUITests/testSwitchingChatsOpensAtLatestMessage
IOS_SIM="<task-owned simulator UDID>" pnpm ios:test OpenClawTypographyTests SwiftUIRenderSmokeTests

Red controls, in a separate checkout of this head (build failures don't count): (1) restore ChatView.swift to the dependency head — both new UI tests must fail; (2) remove only the .chatReaderRowMarker(...) line — the reader-place test must fail with READER_ROW_MOVED_WHEN_PAGE_LANDED.

Screenshots pending: before/after of the top of a long chat, the Show earlier messages control visible, the transcript after a page loads (reader row unchanged), and VoiceOver focus on the control.

Performance pending: on the 2,000-row fixture (--openclaw-screenshot-mode --openclaw-initial-tab chat --openclaw-initial-destination chat --openclaw-paged-history-fixture) and a long real Gateway chat, scroll from latest to first and back. Record offset drift per page landing (≤1 pt), resident rows (tip + ≤600), peak memory and Animation Hitches versus the dependency head on the same device; include detached-window scrolling and VoiceOver activation.

Contributor credit: Vyctor Brzezowski and Mike Nguyen.

Work sessions

Linked for team reference; these sessions aren’t public.

Worked on by

Worked on by:
- @mikengyn
- @vyctorbrzezowski

Co-authored-by: mikengyn <[email protected]>
Co-authored-by: vyctorbrzezowski <[email protected]>
OpenClaw-Publication: a7e5c619-5af5-4049-998c-9a2b04e03fe9
@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: ios App: ios size: XL labels Nov 14, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 14, 2026
@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

Adds cursor-based older-history loading to iOS chat while preserving the reader’s position and bounding resident pages.

Example: Read a 2,000-message conversation whose initial page contains messages 1801–2000.

  • Before: Scrolling to message 1801 reaches the end of accessible history.
  • After: Scrolling upward loads messages 1601–1800 above the reader without moving the message being read.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The feature is worthwhile, but the changed paging behavior lacks executed proof and has two source-verified integration defects.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Long iOS conversations stop at the earliest message in the initially loaded history page.
Reason: Reading earlier conversation content has clear value, and maintainer authorship supplies direction for the feature.

Merge readiness

⛔ Needs changes before merge - 3 items remain

Keep this useful, maintainer-authored draft open; two paging integration defects need repair, and the rendering dependency must land first.

Priority: P2
Reviewed head: f1a51ca1d6b9930a6bce819a80f9e73f332f7b79

Before merge

  • Continue past pages that add no visible transcript rows (P2) - With tool activity hidden, an older page containing only tool-result messages decodes to a nonempty array, then disappears in ChatView.shouldDisplayMessage and transcriptPresentation. This guard ends the action after that page. Because the visible geometry remains in the same older-loading region, the geometry callback does not advance again, leaving automatic loading stuck even when visible messages exist immediately beyond it. Continue within the existing bounded loop based on visible presentation progress rather than decoded-array emptiness.
  • Include resident older-page messages in reaction eligibility (P2) - Loading a saved user or assistant message into olderHistory makes it visible without adding it to viewModel.messages. The existing savedReactionMessageID check searches only messages, so messageReactions returns [] and canReact returns false for every such older message: existing reactions disappear and the reaction action is unavailable. Update the reaction owner's message lookup to recognize resident history pages while retaining its existing session and access checks.
  • Complete next step - After fix(ios): stops chat from going blank after sending a message or a reply arrives #192232 lands, the author should rebase this stack and resolve the reported conflict while preserving current-main streaming and finalization repairs.

Findings

  • [P2] Continue past pages that add no visible transcript rows — apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel+HistoryPages.swift:49-51
  • [P2] Include resident older-page messages in reaction eligibility — apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel+Reactions.swift:175-180

Tests

  • Low-value test apps/shared/OpenClawKit/Tests/OpenClawKitTests/ChatStreamingListRenderingTests.swift: Remove or replace the 'streaming completion state reaches nested list items' case: it asserts builder flags and copied typography without exercising streaming rendering or reveal.
  • Missing end-to-end proof: Provide redacted native before/after evidence of older-page loading, reader-position preservation, eviction/reread and return to latest, accessible activation, and the repaired hidden-page and reaction cases; the proposed regressions have not been shown red on base and green on head.
Agent review details

How this fits together

The shared Apple chat model decodes Gateway history responses, retains older pages separately from the live tip, and supplies the iOS transcript and scroll owners with presentation rows.

flowchart TD
  A[Gateway chat history] --> B[iOS chat transport]
  B --> C[Shared chat model]
  C --> D[Live transcript tip]
  C --> E[Older history pages]
  D --> F[iOS transcript List]
  E --> F
  F --> G[Reader position anchors]
Loading

Technical review

Best possible solution:

Land the rendering dependency, then complete cursor paging with visible-row continuation and reaction support through the existing owners.

Do we have a high-confidence way to reproduce the issue?

Source establishes that main discards page cursors and exposes only the loaded tip; the two findings are traceable through production consumers, without executing target code.

Is this the best way to solve the issue?

Separating bounded read pages from live delta/outbox ownership is coherent, but presentation visibility and reaction eligibility must consume the newly loaded history.

Full review comments:

  • [P2] Continue past pages that add no visible transcript rows — apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel+HistoryPages.swift:49-51
    With tool activity hidden, an older page containing only tool-result messages decodes to a nonempty array, then disappears in ChatView.shouldDisplayMessage and transcriptPresentation. This guard ends the action after that page. Because the visible geometry remains in the same older-loading region, the geometry callback does not advance again, leaving automatic loading stuck even when visible messages exist immediately beyond it. Continue within the existing bounded loop based on visible presentation progress rather than decoded-array emptiness.
    Confidence: 0.95
  • [P2] Include resident older-page messages in reaction eligibility — apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel+Reactions.swift:175-180
    Loading a saved user or assistant message into olderHistory makes it visible without adding it to viewModel.messages. The existing savedReactionMessageID check searches only messages, so messageReactions returns [] and canReact returns false for every such older message: existing reactions disappear and the reaction action is unavailable. Update the reaction owner's message lookup to recognize resident history pages while retaining its existing session and access checks.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against f091e80650aa.

Provenance checked

  • Native scrolling and transcript rendering changes intended behavior with a stated reason (ab2761f: Reader-managed scrolling preserves manual reading position and exposes explicit return-to-latest navigation; the declared rendering dependency explains the List and synchronous-follow replacement.)
  • Live history cursor ownership keeps the original intent (2065cee: Avoid repeated full-history downloads while keeping canonical refresh and route/transcript invalidation under one owner.)
  • Streaming Markdown lists changes intended behavior with a stated reason (a53461b: Lists originally stayed on the streaming prose path to preserve progressive reveal; the inherited replacement uses item-level reveal to align streaming and final geometry.)
  • Streaming versus durable reply deduplication keeps the original intent (fa8fc42: Suppress a streaming copy once its durable reply is present; the inherited changes extend matching to paced text and run identity.)

Testing

Proof path: none.

Security

None.

Evidence

What I checked:

Likely related people:

  • Marvinthebored: Raw commit 2065cee adds apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel+HistoryReconciliation.swift:722 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2065ceecbe46; files: apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel+HistoryReconciliation.swift)

PR surface

Source +1633, Tests +545, Docs +1. Total +2179 across 40 files. Added test files: 4.

View PR surface stats
Area Files Added Removed Net
Source 28 1965 332 +1633
Tests 11 575 30 +545
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 40 2541 362 +2179

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Useful native-chat history access with a limited iOS blast radius and two focused integration defects.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 14, 2026, 12:31 PM ET / 17:31 UTC.

@vyctorbrzezowski

Copy link
Copy Markdown
Member

Closing: main already ships this.

#200592 (c9285dde971f, merged 2026-11-20) rebuilt the iOS transcript on the web reading model and added older-history paging:

  • ChatViewModel+HistoryPaging.swift decodes olderCursor/hasMore, loads up to three overlapping pages per action, dedupes by __openclaw.id/seq, and drops stale reads after a session change.
  • ChatOlderHistoryPaging.swift loads the next page after an upward scroll within 1200 pt of the top. The boundary row keeps a fixed height and shows Show earlier only after a failed load.
  • ChatReadingPosition.olderPageWillPrepend() keeps the reader's row in place when a page is prepended.

This branch was built on the pre-#200592 transcript (ChatOlderHistory, ChatReaderPageAnchor, stacked on #192232). A rebase would add a second owner for the same paging state. The two parts that main does not have are a three-page memory cap and an always-visible top button. #200592 chose not to add the button (it follows the web model), and nobody has reported a memory problem with long chats. So neither part justifies a port. If one becomes a real problem, it should be a small change to the current owner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: ios App: ios docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants