Repository navigation
fix(ios): load chat history again, and keep your place as older messages arrive - #163153
Marvinthebored wants to merge 13 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. What this changesAdds older-history paging and preserves the reader’s position, while rendering narration and answers as separate messages. Example: An older page loads above HISTORY_ANCHOR_499 while the reader is near the top.
Review scores
ProductKind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep this useful history repair open: the prior finding is fixed, but the intentional response-presentation change still needs an owner decision. Priority: P2 Decision needed
Before merge
FindingsNone. Provenance
Agent review detailsHow this fits togetherNative Apple chat transports fetch Gateway history into the shared chat view model; transcript projection and scroll owners turn those messages into positioned SwiftUI rows. flowchart TD
Gateway[Gateway history] --> Transport[Apple chat transport]
Transport --> Model[Session history owner]
Model --> Projection[Transcript projection]
Projection --> Rows[Measured message rows]
Rows --> Viewport[Native prepend viewport]
Viewport --> Reader[Reader position]
Technical reviewBest possible solution: Land the history paging and position repair while retaining grouped response presentation unless its owner approves separate messages. Do we have a high-confidence way to reproduce the issue? Current main lacks the older-page loading path, and supplied native simulator traces exercise the prepend failure boundary; no target code was executed during this review. Is this the best way to solve the issue? Session-owned paging and row-based preservation address the central defect, but changing response presentation is separable from that repair. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ce7788f5a24e. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +1207, Tests +1313, Docs 0. Total +2520 across 36 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (27 earlier review cycles; latest 8 shown)
Reviewed November 9, 2026, 1:39 PM ET / 18:39 UTC (Revision 28). |
|
@clawsweeper re-review Head is now 776b11e50db (rebased on main after #168919). Please review this head. |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
This pull request has been automatically marked as stale after 7 days without qualifying human activity. |
…reams Native history paging keeps the reading position when earlier messages load. The transcript moves to follow only when the user sends a message; history refreshes, cache hydration and tool streams no longer move the reader. The first history page appears before optional metadata completes. Split out of the original change so each concern can be reviewed on its own: chat focus and Talk routing, local command drafts, sidebar nesting, voice rows and transcript order are separate pull requests.
…, and page past empty history pages
The landing now follows the reader's own row (a UIKit marker on the measured row) instead of sampling SwiftUI geometry: a stale same-pass read cannot undo the correction, a rebuilt row is re-acquired, stability needs observed frames, a rubber band at the top edge is finished rather than kept, and no new page starts while one is landing. A page that projects no rows still continues paging. All history groups render under one ForEach and the chat view owns which completed-work folds are open, so new turns and run-group rebuilds keep a fold the reader opened. Adds simulator probes for decelerating, stall+touch, ticking-below, late-growth and uneven-row landings with a strict drift gate, and a regression test for the fold reset.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Related: #163121, #124759
Companion: #163146
What Problem This Solves
Loading older messages, refreshing history, or receiving streamed content can move an iOS reader away from the message they were reading. On real history the jump can be a whole page: the reader lands on rows they never scrolled to.
User Impact
Readers keep their place when older history loads, including while they are still flinging at the top, while a landing stalls the main thread, while a live row below keeps changing height, and when rows above finish sizing after the page lands. Newly sent questions stay anchored with the keyboard hidden; the visible keyboard follows the live reply. Cached conversations reopen at the latest reply without shifting when fresh history arrives. A completed-work disclosure the reader opened stays open as new turns arrive.
Why This Change Was Made
ChatNativePrependViewportcorrect the offset in the page's own layout pass and then follow that row frame by frame until it settles. It ignores a same-pass read of the row's pre-page position, re-acquires the marker when SwiftUI rebuilds the row, counts only observed frames as stable (a main-thread stall cannot end it early), finishes a top-edge rubber band instead of keeping it, undoes a first size change that turns out not to be the page, and starts no new page while one is landing. A page that projects no rows, or only adds work above an unchanged first message, continues to the next page once the landing settles.VStackunder oneForEach, so every row has a measured height and a stable identity (see Rendering choices).Rendering choices
Measured rows instead of
LazyVStack. The precedent cited for lazy history, deb1686, is #147770, a CI SimSlim/release-qualification change; itsChatViewedit fixed a scroll-target starvation and states that lazy rendering "remain[s] intact". It records no design rationale for lazy history. A lazy stack estimates the heights of rows it has not built and re-estimates them when a page lands. On real history with tall tool output and code, the size change for one page of about 125 messages was 134,442 pt, the reader's row left the built window and was torn down, and the landing could only guess. This reproduced on device (test builds of this branch with a lazy list) and in the simulator:testPrependWithUnevenOlderRowsPreservesReaderfails 2/2 withLazyVStackand passes with the measured list. Measured rows make the correction exact.Response frame. This PR draws each narration segment, tool step and the final answer as its own message instead of inside #156944's single response frame. Narration often carries a large share of the reply (findings, caveats, intermediate results), and as separate messages it keeps the same visual weight as the answer, during the run and afterwards. This intentionally reverses #156944's grouped presentation;
docs/platforms/ios.mdis updated to match.ClawSweeper P2 (fold reset). Fixed two ways: the redundant eager prefix/suffix partition is gone (one
ForEach, so a new turn no longer moves a group between partitions), and the open state lives in the chat view rather than the row.testOpenedCompletedWorkStaysOpenAcrossNewTurnsopens a fold and sends five turns: it fails with the previous partition and row-local state ("Five new turns must not collapse the work the reader opened") and passes on this head.Evidence
Follow-up verification: the empty-projection continuation now runs before requiring a reading anchor. An executable Swift harness using the production completion fragment fails the empty-anchor case before this repair and passes nine paging/restore/cancellation boundaries afterward. Native i18n source verification and pinned SwiftFormat pass. The two completed reviews and native 9 / UI 5 / kit 16 results above are retained from the integration revision.
November 10 integration validation
Merged main
7010349a97dand corrected prepend capture ownership. On commit3e19267270c(tree48b46e3efea3c86649bbec9a5a8df18a751663c1), focused completed-work tests passed 16/16. The product-identical pre-fixture-correction tree passed 9/9 native viewport tests and 5/5 selected UI tests (empty projected page, latest-output restoration, opened-work persistence, decelerating prepend, and uneven prepend); five rendered attachments were inspected. The later changes only correct tool-result test fixtures and an assertion about retained disclosure membership; narration behavior is unchanged.Simulator builds used
LINT_BYPASS=1. Separately, pinned SwiftFormat passed for the corrected test file; scoped SwiftLint found zero non-size diagnostics on added lines, with inherited diagnostics and a file-length advisory retained. Test-line ratchet passed 6,602,414 / 6,602,417; its ceiling is unchanged from the merged main parent. These are focused checks, not a full-suite or exact-head phone validation.Current head
4e2f760e6f8c04b342190993e9b021e1d281c32c, rebased onto maind20f161513f. Rebase integration preserves current cursor/delta/maxBytes contracts alongside offset paging; the row-following viewport and its unit tests are byte-identical to the previously reviewed implementation. The two prior local review findings remain fixed.Current CI-mode simulator proof
Xcode 27.1, pinned SwiftFormat 0.63.1/SwiftLint 0.65.1, simulator MarvinIOSVerification, two build jobs,
GITHUB_ACTIONS=true. This is the repository's advisory size-limit CI-mode, not a strict normal local build. No Watch dependency omission, lint shim, or testing-only product-source adaptation was used. Canonical localization baseline generation passed withchanged=false; project generation and the Xcode build/lint phases passed.The first five passed on
220cf377be6; the final head changes only three test lines to open the nested tool-result disclosure before expecting its text, matching the existing upstream disclosure test. Product source is identical between those heads. The original persistence-test attempt failed at that precondition before sending any turns; after correcting it, the unchanged five-turn persistence assertion passed on the final head. An initial rebase-only formatting violation was fixed before these results.Inspected synthetic screenshots and measured output: proof record. The latest-output before/after pair provides presentation context, not a performance benchmark. The fifth-turn screenshot shows the reply; the earlier offscreen fold's retained state is asserted by the test, not visible in that image.
Before: independent scroll-state head, before this history change
After: measured history, separate messages
Scope limits. This is focused simulator proof, not a full current suite or phone validation. The historical first-run 711 pt intermittency and optional-metadata test failures below were not re-investigated in this run; no claim that those failures were fixed. The keyboard-after-send test separately reproduces on unadapted main in the companion scroll PR and was not rerun on this history head.
Retained historical proof and limitations (older heads and adapted environments)
Head
776b11e50db, rebased on main17416f83ecf(after #168919). Simulator: iPhone 17, iOS 26.5, built from the exact commit with the repository's pinned SwiftFormat 0.63.1, SwiftLint 0.65.1, XcodeGen 2.46.0 and Node 26.12.1. The Watch app dependency was removed from the generated simulator project only, because the Watch WebRTC prebuild needs Rust nightly-2026-10-02, which the test host does not have; every Swift file under test is this commit's. The table is from the pre-rebase head888851564620(the landing code is byte-identical on this head); the full suite was rerun on776b11e50db, with the results below the table.testPrependWhileDeceleratingAtTopPreservesReader(flings at the top while the page loads)testPrependLandingDuringStallWithTouchPreservesReader(2.5 s main-thread stall, touch queued) ×2testPrependWithTickingRowBelowPreservesReader(live row below changes height)testPrependWithUnevenOlderRowsPreservesReader(older pages much taller) ×2testPrependWithLateGrowingRowsAbovePreservesReader(rows grow 0.4 s after landing)testLoadingEarlierHistoryPreservesReadingPositiontestLongHistoryPrependPreservesReaderAndTrueLatest(two 101-row pages, return to latest)testDisclosurePrependPreservesReaderWithMoreHistory×4 /…WhenHistoryExhaustedtestEarlierHistoryContinuesPastEmptyProjectedPagetestPagedHistoryCanBeReadBackToOldestAndReturnToLatesttestOpenedCompletedWorkStaysOpenAcrossNewTurns(P2)testCompletedWorkDisclosureKeepsFinalReplyVisibletestT299RichTranscriptFirstHistorySwipeRemainsResponsive/testT299RichHistoryWindowCrossingRemainsResponsivetestManualReturnThroughRichHistoryDoesNotTeleportBacktestNewlySentTurnWithCompletedReplyKeepsQuestionAnchor/testStreamingReplyKeepsQuestionAnchorAfterKeyboardDismissedSendtestManualReaderDoesNotJumpDuringToolStream/testLongTranscriptFlingScrolling×2ChatNativePrependViewportTests(app unit tests)swift test --filter Chat(OpenClawKit)On
776b11e50db. The full rerun passed 22 of 27. The decelerating and both stall+touch probes failed with the same ~711 pt drift (711/739/711), and long-history and one fling run failed. That run was the first on a freshly built tree and simulator, with the probes run first. Repeat runs of the exact head then passed everything: decel 3/3, stall+touch 3/3, long-history 3/3 and fling 2/2 untraced, plus decel 6/6 and stall+touch 6/6 with landing traces compiled in (0 failures in 21 probe runs). Viewport unit tests 6/6 andChatkit tests again passed. The first-run failure is not reproduced and its root cause is not identified; it is recorded here, not claimed fixed.The probes measure the reader's row on screen before the request and after the page settles; a pass is the row still on screen within 4 pt. The gesture probes touch only while the page is pending.
Pre-existing failures, not addressed here.
testEarlierHistoryButtonWorksBeforeMetadataCompletesandtestHistoryFirstPageAppearsBeforeOptionalMetadataCompletestime out on this head and also on the previous head of this PR, c107976544 (same assertion, same waiter). The first-page-before-metadata behavior was shown earlier on d4df452 with a temporary proof fixture and harness that were not kept (validation record); it is not re-proven on this head.Device. iPhone test build 102465 carries this landing and measured list on the author's device build (not this exact commit). Real history, 8 landings: no lost row and no size-only guess; the tester reported small glitches and no jump. Landings freeze the main thread for 100–300 ms on long histories. Test build 102464 with a lazy list jumped: 7 of 9 landings lost the row or fell back to a size-only guess.
Native i18n verification, repository SwiftLint (strict) and pinned SwiftFormat passed on the changed files and in the Xcode build phases.
AI-assisted.