Skip to content

fix(ios): switched chats open at their first message instead of the latest - #187124

Merged
obviyus merged 4 commits into
openclaw:mainfrom
jorge-monalee:ios-chat-switch-scroll
Nov 8, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
jorge-monalee:ios-chat-switch-scroll

Conversation

@jorge-monalee

@jorge-monalee jorge-monalee commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: on iPhone, switching to another chat shows the start of that chat instead of its latest message while the rest of the chat's load is still running.

User Impact

User impact: a chat opened from the sidebar lands on its latest message as soon as the transcript appears, instead of sitting at the top until every background request for that chat (health check, session list, mark-read, model catalog) has finished.

Why This Change Was Made

OpenClawChatView did its one initial scroll-to-latest only when isLoading turned false. That flag covers the whole session bootstrap: history, then the health poll, the 50-row session list, mark-read and the model catalog. The transcript (cached or live) paints well before that, and .defaultScrollAnchor(.bottom, for: .sizeChanges) does not keep the bottom when a switched chat grows from empty, so the reader sat at the top for the remaining round trips.

Transcript changes that arrive before the initial position is settled now re-apply that initial position; the end-of-load restore is unchanged. The initial-position helper only sets the follow target and enqueues a scroll command, and that command already drops requests from a previous session, so it is safe to re-run per change.

Accepted edge case: a reader who scrolls up during that loading window is pulled back to the initial position on the next transcript change, until the load settles. The window is short and the previous behavior was worse (no scroll at all).

The iOS screenshot fixture gains --openclaw-chat-switch-fixture (two long fake chats) and --openclaw-slow-model-catalog-fixture (holds the model catalog for 6 s, standing in for a slow Gateway round trip). The new testSwitchingChatsOpensAtLatestMessage UI test uses both. The regenerated native source inventory (apps/.i18n/native-source.json) records that fixture's new strings.

Evidence

Simulator recording, iPhone 17 Pro on iOS 27.0, Xcode 27.1, fake fixture data only. The left side is main (dadf912); the right side is the same build with this fix applied. The clip opens the sidebar and taps "Launch plan". On main, the chat stays on its first message until the held model catalog finishes, then jumps. With the fix, it opens on the latest message.

Switching to "Launch plan": main shows the first message, the fix shows the latest message

chat-switch-before-after.mp4
  • UI test: OpenClawSnapshotUITests/testSwitchingChatsOpensAtLatestMessage. On main it fails with CHAT_SWITCH_LANDED_AWAY_FROM_LATEST (44.6 s). With the fix it passes (33.8 s). Both results come from the same job, with an incremental rebuild in between: fork run 40789182509. The snapshot UI tests are not part of PR CI; run it with xcodebuild test -project apps/ios/OpenClaw.xcodeproj -scheme OpenClawUITests -destination '<iPhone simulator>' -only-testing:OpenClawUITests/OpenClawSnapshotUITests/testSwitchingChatsOpensAtLatestMessage. No cheaper layer covers this: the defect is SwiftUI's runtime scroll behavior.
  • Position trace: three sidebar switches (B, A, B), sampled through XCUITest about once a second. On main, the latest message first appears 4.0–4.7 s after each switch; until then the chat's first message is on screen. With the fix, the latest message is in place at the first sample of every switch.
  • Without the held catalog, main still lands at the top for 264 ms in-process (an instrumented run logged rows painting at about 3,100 pt from the bottom). With a real Gateway, that window covers every remaining bootstrap round trip.
  • Local review: autoreview --mode branch --base dadf9122058 over this tree, P0–P2: scoped-clean, no findings. One flagged uncertainty — whether restoreInitialScrollPosition() has side effects — checked: it only sets the follow target and enqueues a scroll command.
  • Lint: pinned SwiftFormat 0.63.1 --lint reports 0 of 3 changed files needing formatting. Pinned SwiftLint 0.65.1 --strict on the changed app sources reports only the existing function_body_length advisory on the untouched seedMessages (fork run 40793921673).
Instrumented scroll log, first switch (evidence branch only, not in this PR)

Before (main):

00:13:07.668 sessionTarget -> agent:main:launch-plan loading=true rows=0
00:13:07.835 timeline rows=17 performed=false loading=true
00:13:07.852 geometry distance 3050 -> 3390 performed=false
00:13:14.208 isLoading -> false performed=false rows=17
00:13:14.220 command scrollTo anchorY=1.000000
00:13:14.364 geometry distance 230 -> 0 performed=true

After (this PR):

00:18:06.370 sessionTarget -> agent:main:launch-plan loading=true rows=0
00:18:06.597 timeline rows=17 performed=false loading=true
00:18:06.598 restore rows=17 loading=true
00:18:06.665 command scrollTo anchorY=1.000000
00:18:12.975 isLoading -> false performed=false rows=17

@clawsweeper

clawsweeper Bot commented Oct 29, 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.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T00:27:40.444661Z
We couldn’t complete this review. Comment @codex review to try again.
462e48d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Position opened chats when transcript rows appear instead of waiting for background loading to finish.

Example: Switch from Release checklist to Launch plan while the fixture holds the model catalog for six seconds.

  • Before: The first message remains visible until loading finishes, then the transcript jumps down.
  • After: The latest message appears as soon as the transcript renders.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused repair with inspected product evidence and a meaningful regression; infrastructure failures leave required CI gates unresolved.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): At reviewed head 129afe9, obviyus exercised real sidebar switches and cold launch on an iPhone 17 simulator running iOS 27 against an isolated current-main Gateway with a real agent; inspected before/after captures show latest output immediately after switching with the fix, and the comment records a red/green production-hunk revert check.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Opening another iPhone chat initially shows its oldest messages while background requests finish.
Reason: This restores the existing iOS latest-output contract, and the collaborator's current-head check confirms the intended behavior.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a current iOS positioning bug with no actionable code findings; required CI remains unresolved.

Priority: P2
Reviewed head: 129afe90c8e962981e9d670c261be0b4bf7dba8b

Before merge

None.

Findings

None.

Agent review details

How this fits together

The shared Apple chat view receives session transcript updates from its view model and issues session-scoped positioning commands to SwiftUI.

flowchart TD
  A[Sidebar session selection] --> B[Chat view model bootstrap]
  B --> C[Transcript rows appear]
  B --> D[Background requests finish]
  C --> E[Initial position helper]
  D --> E
  E --> F[Session scoped scroll command]
  F --> G[SwiftUI transcript viewport]
Loading

Technical review

Best possible solution:

Land the existing focused repair once required CI gates are satisfied.

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

Current-main source establishes the delayed-positioning path, and obviyus supplies current-head simulator/Gateway reproduction with inspected before/after captures; no target code was executed during this review.

Is this the best way to solve the issue?

The patch restores the existing initial-position invariant through its current owner, preserves platform-specific targets and post-load handling, and adds one meaningful UI regression with two fixture-only launch arguments.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Pending initial positioning changes intended behavior with a stated reason (ab2761f: Reader-managed scrolling introduced the initial-scroll gate to separate restoration from subsequent turn following.)
  • Platform-specific restoration targets keeps the original intent (a104bee: Reopened iOS chats should show current output while macOS retains latest-turn restoration.)
  • Local fixture transport keeps the original intent (59ed641: Provide an offline Apple Review chat transport; this PR extends that existing fixture owner for UI reproduction.)
  • Generated native string inventory keeps the original intent (f02d16e: Keep native string extraction deterministic without parallel-PR inventory conflicts.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • christopheraaronhogg: Raw commit ab2761f adds apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatView.swift:583 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ab2761f3a59a; files: apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatView.swift)
  • RoboClaw: Raw commit a104bee adds apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatView.swift:22 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a104beedfc90; files: apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatView.swift)
  • Marvinthebored: Raw commit f2c27f0 adds apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatView.swift:1188 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f2c27f09ea53; files: apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatView.swift)

PR surface

Source +68, Tests +23. Total +91 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 71 3 +68
Tests 1 23 0 +23
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 94 3 +91

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:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Switching chats temporarily shows the wrong reading position, with automatic recovery after loading and no established data loss.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-29T00:56:28.203Z sha 32e154b :: needs maintainer review before merge. :: none

Reviewed November 8, 2026, 4:50 AM ET / 09:50 UTC (Revision 2).

# Conflicts:
#	apps/ios/Sources/Chat/AppleReviewDemoChatTransport.swift
#	apps/ios/UITests/OpenClawSnapshotUITests.swift
@obviyus

obviyus commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Maintainer end-to-end check. I merged current main into the branch (129afe90c8e). The only conflicts came from main splitting the snapshot UI tests into several files, so the new test now lives unchanged in OpenClawSnapshotUITests+Chat.swift. The product change is unchanged.

Setup: an iPhone 17 simulator on iOS 27, paired to an isolated Gateway running current main with a real agent. There were two real sessions, each with six long numbered agent replies. Every switch below is a real sidebar tap, recorded and read at 10 fps.

Scenario main This PR
Sidebar switch A→B Opens at B's first message for ~1.8 s, then jumps to the end Latest message in the first frame after the sidebar closes
Switch B→A, then A→B First message for ~0.5 s each time, then jumps Latest message right away, both times
Cold launch into a chat (--openclaw-chat-session) First message shows during reconnect, then jumps down Rows first appear at the end and stay there through the reconnect
Reader scrolled up after the load, new reply arrives Pulled down to the new turn Same as main

Root cause: the first scroll to the bottom waits for isLoading to clear, which takes the whole session load, and handleTimelineChange ignores transcript changes until that first scroll happens. While that first scroll is still pending, the PR reapplies the initial bottom position on each transcript change, using the existing restoreInitialScrollPosition().

Tests

  • OpenClawSnapshotUITests/testSwitchingChatsOpensAtLatestMessage passes with the fix. With only the ChatView.swift change reverted, it fails with CHAT_SWITCH_LANDED_AWAY_FROM_LATEST.
  • OpenClawKit swift test: 615 tests passed across the chat view, reader and scroll suites.
  • SwiftFormat and swiftlint --strict are clean.

Thanks @jorge-monalee!

main: switched chat shows its first message, then jumps to the latest

PR: switched chat shows the latest message as soon as the sidebar closes

@obviyus

obviyus commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 8, 2026
@obviyus
obviyus merged commit 5be01fd into openclaw:main Nov 8, 2026
129 of 139 checks passed
@obviyus

obviyus commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 9, 2026
…atest (openclaw#187124)

* test(ios): cover landing at the latest message after switching chats

* fix(ios): switched chats open at the top until the session finishes loading

* chore(i18n): refresh native source inventory for the chat switch fixture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: ios App: ios P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants