Skip to content

fix(ios): keep streamed transcripts stable across tool boundaries - #136702

Merged
steipete merged 2 commits into
mainfrom
steipete/fix-this-af58df
Sep 3, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/fix-this-af58df

Conversation

@steipete

@steipete steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

iPhone users report that the chat transcript "jumps up and down constantly", flickers, and shows blank areas while an agent is working (#135250, #135214; a public report on 2026-09-02 that also mentions crashes). Reproduced on an isolated dev gateway with a paced mock model (reasoning → preamble → read tool → final reply), recorded on the simulator and analyzed frame by frame. Four independent owner defects in the shared chat UI and the iOS chat tab produce the symptoms:

  1. Two producers wrote the streaming bubble. After a tool boundary the gateway's chat delta buffer is run-cumulative ("Let me look at the workspace first.Here is…") while the agent assistant stream carries the current item's text. The view model applied both, so the bubble alternated between the two texts several times per second and its height oscillated by a line.
  2. The app retired its own run mid-run. invalidateRunSnapshots() bumps the ownership generation on every streaming event, so any chat.history refresh in flight during streaming came back superseded; refreshIfPending then skipped the gateway's inFlightRun fact and fell through to the message-shape heuristic, which cleared the pending run as soon as history contained the assistant message that carries the tool call. From then on every assistant delta was dropped as a foreign run: no working indicator, blank transcript, until the final arrived. App log: pending refresh delayMs=1500 → pending cleared two seconds after send, agent.wait … CancellationError.
  3. Rebuilt chat view models leaked and kept processing every event. heap showed three live OpenClawChatViewModel instances; each processed every gateway event (ours=false pending=0 twins in the log), ran its own history polling and haptics. The retain chain went through the model's closures capturing the ChatProTab view value and its @State saved values.
  4. A streaming table flipped between prose and table. The block segmenter skipped a trailing table while streaming, so rows were appended to the previous paragraph as prose, the paragraph text was rewritten on every row (restarting the word reveal, text going invisible), and the table popped in only when text followed it: measured as repeated ±25–80 pt up/down shifts.

Also fixes the iPhone edge-drawer drag latching on marginal diagonals (#135250's horizontal shift): a vertical thumb scroll near the left edge could drag the content card sideways and spring back.

Why This Change Was Made

Each fix lands at the owner that records the fact: the view model keeps one canonical producer for live text and never lets a superseded history snapshot retire a run the gateway reports in flight; the chat tab hands the model closures that do not capture the view and detaches a model's transport loop when it is rebuilt; the segmenter keeps prose prefix-stable while a table streams; the drawer commits only on clearly horizontal drags.

User Impact

Agentic replies on iPhone stream without flicker or blank gaps, the working indicator stays until the run really ends, tables render once while streaming, scrolling near the left edge no longer shifts the transcript sideways, and the app stops doing every chat event's work three times.

Evidence

Rig: isolated dev gateway (OPENCLAW_STATE_DIR, token auth, port 18899) with a paced Responses-API mock model (35 ms/word, reasoning summary → preamble → read tool → 12 s model delay → final reply), iOS 27 simulator driven headlessly with idb, recordings analyzed frame by frame (vertical shift of the transcript band; "direction reversals within 1 s" is the up/down signature).

Metric Before After
Live OpenClawChatViewModel instances (heap) 3 1
Agentic run: direction reversals 12 1
Streamed reply with a table: direction reversals 5–6 2
Own run retired mid-run (pending cleared before run observation terminal) yes, at +2 s no
Working indicator during tool phase + model delay disappears stays
Streaming bubble after tool boundary alternates between two texts single per-item text

App diagnostics after the fix (proof run): pending refresh at +2 s, +6 s, +15 s all keep the run; run observation … completed → pending cleared only at the real end.

Tests:

  • swift test --filter 'ChatViewModelTests|ChatMarkdownBlockSegmenterTests|ChatReaderScrollStateTests|ChatStreamingRevealTests': 449 tests, 5 suites, passed. New: superseded pending refresh preserves an in-flight run (fails on the previous code on both assertions), agent assistant text owns the run instead of cumulative chat buffers (agent-first / delta-first / delta-only), detached transport ignores late events and in-flight history, streamed table prefixes preserve prose and only grow table rows, streaming table header waits without hiding inline pipes.
  • xcodebuild test … -only-testing:OpenClawTests/RootSidebarDrawerGestureTests -only-testing:OpenClawTests/RootTabsSidebarRegressionTests -only-testing:OpenClawTests/RootTabsSourceGuardTests: passed (exit 0). RootTabsSidebarRegressionTests had a stale assertion (expected openChat(sessionKey:) in the session button after fix(ios): open session dashboards without nested control UI #132983 switched it to selectSession); repaired here, it is not in the CI -only-testing list.
  • SwiftFormat 0.63.0 (config/swiftformat) and SwiftLint 0.65.1: clean. pnpm ios:build for the simulator: succeeded.
  • Codex autoreview (--mode uncommitted): scoped-clean.

LOC: production +107/−99 (net +8: the recorded per-run "agent text seen" fact, the explicit transport detach lifecycle, and the trailing-table hold-back; the drawer predicate and live-state refactor are net negative); tests +176/−26 plus a 95-line new test file.

Accepted tradeoff: while streaming, a trailing paragraph whose every line starts with | is held back until its table delimiter row arrives (or the message completes), so ASCII-art-style pipe paragraphs appear late rather than flickering.

Not changed (follow-ups): the gateway replays its buffered chat deltas (100+ events in one burst) at run end, which re-adopts a just-finished run for ~150 ms; a "Select Text" sheet and code-block copy on iOS; the background-wake refresh path is dead (no fetch background mode).

Fixes #135250. Refs #135214, #124759; copy/selection landed separately in #135430.

@clawsweeper

clawsweeper Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review September 2, 2026 22:46
@openclaw-barnacle openclaw-barnacle Bot added app: ios App: ios size: L maintainer Maintainer-authored PR labels Sep 2, 2026
@steipete

steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Live proof recordings (iOS 27 simulator, isolated dev gateway, paced mock model with a real read tool call; synthetic content only).

Before (main at 2c2e501, agentic turn): the streaming bubble alternates between two texts after the tool boundary, then the app retires its own run and the transcript goes blank with no working indicator until the final reply lands.

After (this PR, same turn with a 12 s model delay after the tool result): the working indicator persists through the tool phase and the delay, the pre-tool commentary stays as its own message, and the reply streams once as per-item text.

After, #135250 scenario: scrolling through earlier messages while reasoning and the reply stream, including left-edge diagonal swipes that used to latch the drawer and drag the content card sideways. The transcript stays put; only the deliberately horizontal edge swipe at the end opens the drawer.

Metric (frame analysis of the transcript band) Before After
Live OpenClawChatViewModel instances (heap) 3 1
Up/down direction reversals during an agentic reply 12 1
Reversals during a streamed reply with a table 5–6 2
Own run retired mid-run (pending cleared before the terminal observation) at +2 s never
attachment-858501045.mp4
attachment-2315117102.mp4
attachment-3940969079.mp4

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 2, 2026, 7:15 PM ET / 23:15 UTC.

ClawSweeper review

What this changes

The PR repairs iOS chat streaming across tool boundaries by separating live-text ownership, retaining in-flight runs across stale history refreshes, retiring replaced view models, stabilizing streamed tables, and tightening sidebar gesture commitment.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep open. The exact head resolves the prior close-anywhere drawer finding and implements the still-missing iOS transcript/run-state repair; no introduced blocking defect was found. It remains a maintainer-owned, protected PR pending exact-head iOS validation and maintainer review.

Priority: P1
Reviewed head: d54a53cceda3c4dc22e1021708515bded1fbf874
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with useful regression coverage; merge readiness awaits exact-head native validation and maintainer review.
Proof confidence 🌊 off-meta tidepool Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply. The PR body and comment link before/after simulator recordings, but GitHub artifact retrieval was unavailable in this reviewer environment, so they were not independently viewed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply. The PR body and comment link before/after simulator recordings, but GitHub artifact retrieval was unavailable in this reviewer environment, so they were not independently viewed.
Evidence reviewed 6 items Run ownership repair: A history refresh superseded by a live event now preserves the pending owner rather than applying message-shape retirement; an authoritative in-flight snapshot is still handled separately.
Single live-text producer: Once an agent assistant event is seen for a run, cumulative history snapshot text no longer replaces the current streamed item.
Prior drawer finding resolved: Opening eligibility is now evaluated only for a closed drawer, while the presented-drawer path can commit a closing drag from any content-card start; the focused regression test covers x=300/y=400.
Findings None None.
Security None None.

How this fits together

The native iOS chat tab owns an OpenClawChatViewModel that combines gateway history with live agent events into a transcript and tool activity. The same iOS surface handles sidebar gestures while a run is active.

flowchart LR
  A[Gateway history] --> C[Chat view model]
  B[Live agent events] --> C
  C --> D[Run ownership and stream text]
  D --> E[Markdown transcript blocks]
  E --> F[iOS chat tab]
  G[Touch drag] --> H[Sidebar gesture decision]
  H --> F
Loading

Decision needed

Question Recommendation
After exact-head iOS checks finish, should this maintainer-owned transcript and lifecycle repair be accepted for merge? Review after exact-head validation: Confirm the pending iOS build and focused test results, then merge the repaired transcript and drawer behavior.

Why: The protected maintainer label and live session-state behavior require an explicit maintainer decision even though the prior concrete finding is resolved.

Before merge

  • Resolve merge risk (P1) - The net production increase is +9 lines in a bug-fix PR; the added per-run ownership fact, permanent transport retirement, and trailing-table hold-back are the concrete owner-boundary additions, with no smaller existing abstraction apparent.
  • Resolve merge risk (P1) - The change alters live run/session ownership and view-model lifecycle semantics; exact-head iOS build and focused tests are still in progress in the supplied check state.
  • Complete next step (P2) - Complete exact-head iOS validation and obtain maintainer review before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Other +256. Total +256 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 12 381 125 +256
Total 12 381 125 +256

Review metrics

Metric Value Why it matters
Production versus test delta production +108/-99 (net +9); tests +273/-26 The small production growth is concentrated in live-run ownership, teardown, and streaming-table state, while focused regression coverage supplies most of the added lines.

Merge-risk options

Maintainer options:

  1. Validate the live-run lifecycle before merge (recommended)
    Require the exact-head iOS build and focused chat regressions to pass before accepting changes to pending-run ownership and transport teardown.
  2. Pause for device-level confirmation
    Defer merge if maintainers want to reproduce the multi-tool streaming sequence on a physical iPhone before accepting the lifecycle change.

Technical review

Best possible solution:

Retain this owner-boundary repair, then land only after exact-head iOS validation and maintainer review confirm the live-run lifecycle remains stable.

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

Yes—at source level, the focused tests encode the stale-history/live-event ordering and the agent-versus-cumulative-text sequence that exercise the reported failure. This read-only review did not rerun the simulator scenario.

Is this the best way to solve the issue?

Yes. The patch repairs the producers and lifecycle owner rather than masking visual symptoms: it records agent-text ownership, preserves pending runs across superseded snapshots, and retires replaced event loops.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e49922bbab6f.

Labels

Label justifications:

  • P1: The patch addresses an active iOS chat workflow where streamed transcripts can flicker, disappear, or lose the working indicator.
  • merge-risk: 🚨 session-state: The changed pending-run ownership and detached-view-model lifecycle decide whether live gateway events remain associated with the displayed chat session.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply. The PR body and comment link before/after simulator recordings, but GitHub artifact retrieval was unavailable in this reviewer environment, so they were not independently viewed.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the exact-head iOS build and focused chat regressions complete, then obtain maintainer review of the live-run lifecycle change.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-02T22:53:58.190Z sha 701bb4e0ab50a5f35ab84cc7c9d564804049d3fa :: blocked before merge. :: [P1] Preserve close swipes outside the opening edge

@steipete

steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Re the ClawSweeper P1 "Preserve close swipes outside the opening edge": the reported behavior does not occur. The edge/top eligibility check is a Swift condition list whose first clause is !isPresented, so it never runs for a presented drawer; the existing test opening respects edge and navigation eligibility while closing works anywhere already asserts .closing for left swipes starting at x = 45 and y = 44 on a presented drawer, and it passes.

The shape did invite the misread, so the follow-up commit restructures it into an explicit if !isPresented { guard … } opening-only block (no behavior change) and adds the requested content-card start case (x = 300, y = 400 on a presented drawer → .closing).

Rank-up moves: the two "resolve merge risk" items are the same finding and are covered by the above; the production delta stays at the owner boundaries listed in the description.

The iOS chat transcript flickered, jumped, and went blank during agentic runs.
Four owner defects reproduced on a dev gateway with a paced mock model:

- The streaming bubble had two producers after a tool boundary: the chat delta
  carries the gateway's run-cumulative buffer while the agent stream carries the
  current item. Agent text now owns the bubble once observed for a run.
- Every streaming event bumped the run ownership generation, so an in-flight
  history refresh came back superseded and refreshIfPending fell through to
  message-shape inference, retiring the app's own run as soon as the tool-call
  assistant message was persisted. A superseded snapshot never retires a run,
  and inFlightRun guards the heuristic paths.
- ChatProTab closures captured the view value, so rebuilt view models leaked
  (three live) and each processed every gateway event. Closures capture the app
  model and presentation strings; replaced models detach their transport loop.
- The block segmenter skipped a trailing table while streaming, appending rows
  to the previous paragraph and restarting the word reveal on every row. Trailing
  tables now render as they stream; pipe-only fragments wait for a delimiter.

Also make the sidebar drawer commit only on clearly horizontal drags so a thumb
scroll near the left edge no longer shifts the content card sideways, and repair
the stale session-button assertion in RootTabsSidebarRegressionTests.

Fixes #135250
Refs #135214, #124759
Scope the edge and top-exclusion eligibility to closed-drawer opening gestures
in an explicit block (no behavior change) and cover a content-card start on a
presented drawer closing.
@steipete
steipete force-pushed the steipete/fix-this-af58df branch from 21d91e0 to d54a53c Compare September 2, 2026 23:07
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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 rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 2, 2026
@steipete
steipete merged commit 4af3fc2 into main Sep 3, 2026
530 of 539 checks passed
@steipete
steipete deleted the steipete/fix-this-af58df branch September 3, 2026 03:45
@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 3, 2026
…enclaw#136702)

## What Problem This Solves

iPhone users report that the chat transcript "jumps up and down constantly", flickers, and shows blank areas while an agent is working (openclaw#135250, openclaw#135214; a public report on 2026-09-02 that also mentions crashes). Reproduced on an isolated dev gateway with a paced mock model (reasoning → preamble → `read` tool → final reply), recorded on the simulator and analyzed frame by frame. Four independent owner defects in the shared chat UI and the iOS chat tab produce the symptoms:

1. **Two producers wrote the streaming bubble.** After a tool boundary the gateway's `chat` `delta` buffer is run-cumulative (`"Let me look at the workspace first.Here is…"`) while the `agent` `assistant` stream carries the current item's text. The view model applied both, so the bubble alternated between the two texts several times per second and its height oscillated by a line.
2. **The app retired its own run mid-run.** `invalidateRunSnapshots()` bumps the ownership generation on every streaming event, so any `chat.history` refresh in flight during streaming came back superseded; `refreshIfPending` then skipped the gateway's `inFlightRun` fact and fell through to the message-shape heuristic, which cleared the pending run as soon as history contained the assistant message that carries the tool call. From then on every assistant delta was dropped as a foreign run: no working indicator, blank transcript, until the final arrived. App log: `pending refresh delayMs=1500` → `pending cleared` two seconds after send, `agent.wait … CancellationError`.
3. **Rebuilt chat view models leaked and kept processing every event.** `heap` showed three live `OpenClawChatViewModel` instances; each processed every gateway event (`ours=false pending=0` twins in the log), ran its own history polling and haptics. The retain chain went through the model's closures capturing the `ChatProTab` view value and its `@State` saved values.
4. **A streaming table flipped between prose and table.** The block segmenter skipped a trailing table while streaming, so rows were appended to the previous paragraph as prose, the paragraph text was rewritten on every row (restarting the word reveal, text going invisible), and the table popped in only when text followed it: measured as repeated ±25–80 pt up/down shifts.

Also fixes the iPhone edge-drawer drag latching on marginal diagonals (openclaw#135250's horizontal shift): a vertical thumb scroll near the left edge could drag the content card sideways and spring back.

## Why This Change Was Made

Each fix lands at the owner that records the fact: the view model keeps one canonical producer for live text and never lets a superseded history snapshot retire a run the gateway reports in flight; the chat tab hands the model closures that do not capture the view and detaches a model's transport loop when it is rebuilt; the segmenter keeps prose prefix-stable while a table streams; the drawer commits only on clearly horizontal drags.

## User Impact

Agentic replies on iPhone stream without flicker or blank gaps, the working indicator stays until the run really ends, tables render once while streaming, scrolling near the left edge no longer shifts the transcript sideways, and the app stops doing every chat event's work three times.

Evidence (live simulator rig against an isolated dev gateway with a paced mock model, before/after recordings, frame-by-frame motion metrics, app diagnostics log): see the PR body and comments. Shared Swift package: 449 tests passed; iOS drawer/sidebar suites passed; SwiftFormat/SwiftLint clean; Codex autoreview scoped-clean; ClawSweeper exact-head review: no findings.

Fixes openclaw#135250
Refs openclaw#135214, openclaw#124759
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: ios App: ios maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

[Bug]: iOS transcript shifts horizontally and flickers while scrolling during an active run

1 participant