Skip to content

fix(ios): chat stalls while typing and receiving background events - #187610

Merged
obviyus merged 2 commits into
openclaw:mainfrom
ben-milanko:fix/ios-chat-stalls-upstream-20261029
Nov 8, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
ben-milanko:fix/ios-chat-stalls-upstream-20261029

Conversation

@ben-milanko

Copy link
Copy Markdown
Contributor

Related: #124759

What Problem This Solves

Native chat can stall during typing and background session activity, including with an empty transcript or hidden tool activity.

User Impact

Removes unnecessary work competing with typing and scrolling while preserving model selection, sign-in, session refresh, settings, approvals and Talk behavior. This is a partial performance repair; it does not establish that all lag reported in #124759 is resolved.

Why This Change Was Made

Closed model menus eagerly group the full catalog while constructing composer controls. Their contents now use the existing deferred-content view. Sidebar and operator listeners filter their own event names on the Gateway actor before unrelated frames enter their bounded buffers or MainActor loops. Explicit cancellation releases replaced and stopped subscriptions; the sidebar's refresh-coordinator cleanup remains intact.

The original development-fork work also hoisted Home's alias lookup. That change is omitted here because #169197 already caches alias resolution on upstream. The port preserves current-main menu sign-in/disabled behavior and carries no development signing or build settings. One inherited empty-string assertion uses isEmpty to pass the pinned lint check; the broader formatting-only changes from the fork are omitted.

Evidence

Acceptance rule: constructing closed clean and full model pickers with 2,000 synthetic catalog entries must not observe projection-only favorites/recents; background subscriptions must retain their owner events after 500 unrelated frames exceed the 200-frame buffer. These are deterministic work/retention checks, with no wall-clock thresholds or inferred device speedup.

  • On upstream base b367b1fd64d8daa5f91aa7a8a78b9a90f92d0df6, both new composer cases fail because changing favorites/recents invokes the observation callback. With the patch, both pass and the callback remains at zero. The candidate regression takes 0.121 seconds; no timing threshold is asserted.
  • Fresh Xcode 27.1 / Swift 6.4 shared-package validation passed 120 tests in four suites (31.911 seconds of test runtime; 65.813 seconds for the incremental compile/test command). This includes composer state, model picker/selection and Gateway event-subscription tests.
  • All six files pass SwiftFormat 0.63.1, SwiftLint 0.65.1 and Swift syntax parsing. Normal pre-commit protocol/determinism and native-i18n checks pass.
  • Local AutoReview completed a full P0-P2 assessment of the functional patch against the base above, with no actionable findings. The subsequent one-line assertion cleanup is behavior preserving and passes the same focused checks.
  • Current-upstream iOS app-specific event regression execution and physical-device latency profiling remain unverified. Hosted CI is pending; the shared-package result does not replace those checks.
  • Prior development-fork verification passed 82 focused native tests on each iPhone and iPad simulator, including the event-buffer regressions, plus typing, model-menu, scrolling and draft-retention interactions. Those runs cover the original fork, not this new upstream base.
  • A physical-iPhone user reported that the combined development build was substantially more usable, with minor stutters remaining. The build includes other fork changes, so this is subjective combined-build feedback, not an isolated measurement of this patch.
  • Original implementation and review context: fix(ios): reduce chat input and sidebar stalls ben-milanko/openclaw#13. No dependency on that fork's other changes is introduced.

Prepared by Alder, Ben's AI assistant, on Ben's behalf.

@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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro 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: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro 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

This PR defers native model-menu construction and filters unrelated Gateway events before they enter iOS background listeners.

Example: Typing a 97-character draft with 512 available models while five background sessions run agent turns.

  • Before: The maintainer measured 617 model-list groupings during typing.
  • After: Typing triggered zero groupings; opening the model menu triggered one.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong scoped runtime evidence and a focused patch; the overall rating remains limited by its explicitly partial coverage of the broader lag report.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): obviyus exercised the candidate on an iPhone 17 simulator against a real Gateway with 512 models and five concurrent background sessions, recording eliminated typing-time grouping, reduced listener traffic, retained wake-word updates, and successful model selection/default restoration; inspected screenshots corroborate the visible paths and resolve the prior candidate-proof request.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Partial
User problem: Native chat performs unnecessary model-menu and background-event work while users type or scroll.
Reason: The measured work reduction has clear value and preserves existing controls, but intentionally addresses only part of the broader linked lag report.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR provides useful, distinct performance work with no actionable introduced defect found; exact-head CI remains in progress.

Priority: P2
Reviewed head: 0cbbdfee3022c20a511c308a6c7937469ef5c894

Before merge

None.

Findings

None.

Agent review details

How this fits together

Shared SwiftUI composer controls turn the model catalog into menu choices, while iOS sidebar and operator listeners consume Gateway events to update sessions, settings, approvals, and Talk.

flowchart LR
  A[Model catalog] --> B[Deferred model menu]
  B --> C[Composer controls]
  D[Gateway events] --> E[Gateway actor filters]
  E --> F[Sidebar listener]
  E --> G[Operator listener]
Loading

Technical review

Best possible solution:

Retain this focused work reduction while treating broader physical-device transcript lag as separate work.

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

The maintainer's alternating real-Gateway simulator runs reproduce eager grouping and unnecessary listener delivery on main; they do not establish a measurable typing-latency improvement.

Is this the best way to solve the issue?

The smallest complete repair reuses the existing deferred-view and filtered-subscription owners, preserves consumer contracts, and adds no cache or parallel rendering path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Shared model menus keeps the original intent (improve(ios): align composer controls with WebUI #132683: Align native composer controls with web while preserving authoritative session-bound actions; later model-catalog and sign-in repairs retained availability restrictions and independent sign-in access.)
  • Sidebar subscriptions and refresh cleanup keeps the original intent (0b080b9: Provide lifecycle-resilient observer digests with stream-before-subscribe ordering, retries, and reconnect recovery; the later roster repair added shared refresh-coordinator cleanup.)
  • Operator event listener keeps the original intent (0cef22e: Synchronize Gateway wake-word changes through the earlier BridgeSession listener; the present handler also owns settings, Talk, and approvals.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Introduced change verified: The pinned introduced diff moves both model-picker projections into the existing ChatDeferredContent boundary and replaces the two all-event streams with filtered, explicitly canceled subscriptions. (apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatComposer+CleanControls.swift:153, 0cbbdfee3022)
  • Current main still contains the targeted work: The inspected production files are unchanged between the pinned base and fetched main: model grouping remains eager, and both listeners still subscribe to unrelated frames. (apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatComposer+Controls.swift:84, dec19a6acb83)
  • Event and lifecycle contracts preserved: Each filter retains every event handled by its consumer, including sidebar sequence-gap recovery and all operator approval events; stream-before-subscribe ordering and refresh-coordinator cleanup remain intact. (apps/ios/Sources/RootSidebarModel.swift:434, 0cbbdfee3022)
  • Candidate-specific runtime evidence: obviyus reports alternating main/candidate runs on an iPhone 17 simulator against a real Gateway, covering typing, background session updates, voicewake.changed delivery, menu opening, model selection, and Default restoration: fix(ios): chat stalls while typing and receiving background events #187610 (comment). The two downloaded screenshots visibly support the sidebar and open-menu checks; the report expressly claims work reduction rather than a frame-rate gain. (0cbbdfee3022)
  • Video inspection limitation: The prepared manifest records “ffprobe failed: spawnSync ffprobe ENOENT”; the browser fallback returned a cache miss. The video was not assessed, and its contents are not needed to substitute for the independently supplied runtime results and inspected screenshots.
  • Feature history and original intent: Scoped history and targeted blame identify the shared composer work from Colin Johnson and Peter Steinberger, observer subscription lifecycle from Peter Steinberger, and subsequent sign-in/sidebar repairs from Marvinthebored. The original wake-word implementation used BridgeSession and filtered voicewake.changed inside its consumer; no requirement to deliver unrelated events was found. (apps/ios/Sources/Model/NodeAppModel.swift:1730, 0cef22ef8321)

Likely related people:

  • Peter Steinberger: Raw commit 0b080b9 adds apps/ios/Sources/RootSidebarModel.swift:184 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0b080b9c2ed7; files: apps/ios/Sources/RootSidebarModel.swift)
  • Colin Johnson: Raw commit 5dd4c6e adds apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatComposer+CleanControls.swift:157 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5dd4c6e3b087; files: apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatComposer+CleanControls.swift)
  • Marvinthebored: Raw commit 7a1f8b2 adds apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatComposer+CleanControls.swift:213 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7a1f8b2e5cb3; files: apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatComposer+CleanControls.swift)

PR surface

Source +37, Tests +100. Total +137 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 113 76 +37
Tests 2 101 1 +100
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 214 77 +137

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 proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The patch removes measured native chat work competing with typing and background updates, without evidence of an urgent availability or delivery regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; 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.

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-29T11:25:45.193Z sha 94ea9b1 :: needs real behavior proof before merge. :: none

Reviewed November 8, 2026, 11:01 AM ET / 16:01 UTC (Revision 2).

@obviyus

obviyus commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Maintainer end-to-end check on an iPhone 17 simulator (iOS 27) against a real Gateway built from current main. I merged current main into the branch.

Setup

  • The Gateway offered 512 models: 12 Anthropic models plus 10 placeholder providers with 50 models each, which are never called.
  • Five other sessions ran agent turns at the same time (6 exec calls each, then a long reply) while I typed a fixed 97-character sentence into an idle chat.
  • A temporary counter in a Debug build (not part of this PR) measured model-list groupings and listener work.
  • Runs alternated between main and this PR.
main This PR
Model list grouped while typing, no load 398× / 291 keys, 316 ms main thread 0
Model list grouped while typing, under load 617× / 388 keys, 500 ms 0
Grouping when the model menu opens n/a 1× (≈6 ms)
Frames reaching the sidebar listener per load window 601 57 (sessions.changed only)
Sidebar listener main-thread time per load window 96.5 ms 45.9 ms
Frames reaching the operator listener per load window 601 0
sessions.changed delivered to the sidebar 60 60

Dropped frames and keystroke round-trip on the simulator were within run-to-run noise, so this doesn't claim a frame-rate gain. What it shows is that the work is gone: no model-list grouping per keystroke, and about 10× fewer frames reaching the main actor during background turns.

Events a listener needs still arrive under load. I called voicewake.set in the middle of the 5-session burst. The operator listener received exactly one frame, voicewake.changed, and the app stored the new wake word.

Functional checks on this PR

  • During the load the sidebar showed all 5 background sessions with live timestamps. Afterwards each one showed Unread.
  • The 512-model menu opens and scrolls.
  • Picking bluepeak/bluepeak-model-001 updated the composer chip, and the Gateway's sessions.list showed that model. Picking Default restored the original model.

Tests

  • swift test --filter ChatComposerStateTests: "closed model pickers defer catalog projection" fails on main for both composer styles and passes here (15/15).
  • OpenClawTests/RootEventSubscriptionTests: 2/2.

Thanks @ben-milanko!

PR: background sessions updated and marked unread after the load

PR: 512-model menu built when opened

pr-proof-typing-menu.mp4

@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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 8, 2026
@obviyus
obviyus merged commit 93858af into openclaw:main Nov 8, 2026
93 checks passed
@obviyus

obviyus commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Merged via squash.

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: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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