Skip to content

fix(mobile): keep repeated-prefix native chat replies streaming (STA-3333) - #12501

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/sta-3333-stream-prefix
Aug 4, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/sta-3333-stream-prefix

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Native chat could swallow a real assistant reply while it was still streaming. The streaming bubble was gated on text alone: if the newest folded transcript turn started with the streamed text, the bubble was hidden as "the transcript already caught up". That test can't tell catch-up from coincidence — when a new reply happens to repeat the previous turn's prefix ("Done.", "The tests pass.", any stock opener), the older turn matched and the live reply never rendered. The user saw the working indicator spin with no visible text until the whole turn landed.

The gate is now stateful. It records which transcript tail was live when the current stream segment began, and hides the bubble only when the tail moved during that segment and leads with the streamed text — i.e. the real turn actually landed. An older identical turn can no longer suppress anything. A stream that isn't an extension of the previous tick (the next reply part) re-anchors to the tail that predates it.

Two things make that baseline survivable in the real app:

  • Ownership. The gate lives in MobileNativeChatOverlay, which returns null when chat is hidden but is never unmounted — so the baseline outlives the chat list below it. Putting it in the list would reset it on every chat↔terminal toggle, which is exactly when the bug bites.
  • Scope key, not route identity. Gate state is keyed to nativeChatStreamScopeKey (host / workspace / tab), which is stable across view toggles. The pre-existing streamIdentity — which additionally encodes the view so a delayed answer-send or stop can't land in the wrong place — is deliberately not reused here; a view-gated key would drop the baseline on the very toggle this fix is about. Both are asserted against each other in use-mobile-native-chat-controller.test.ts.

streamLive (the pane's working state) distinguishes "no observation this render" from "the stream ended", so a textless tick mid-turn no longer re-anchors the baseline onto a reply that has just landed.

Split from #12373 (fix 9 of 10 in that QA sweep), rebased onto main as an independent PR. #12373 stays open; none of its other fixes (reconnect history, cached transcript, stale status, prompt cards, paging, write lock, tool summaries) are included here.

Refs STA-3333.

Screenshots

A/B on the iOS simulator against a mock desktop, same scenario, two Metro servers: A = main (e9cf106), B = this branch at fed9ca38 — the only commit since is test-only, so the production code in these shots is the code at head. Bundle provenance was verified by grepping each served bundle (A has the old lastText.startsWith rule and none of the new gate symbols; B has canAnchor/baselineTailId/nativeChatStreamScopeKey and zero occurrences of the old rule).

A — main: the reply is swallowed. A prior "Done." turn exists; the agent starts a new reply that also begins "Done.". The pane shows Agent is working + Stop, but only one "Done." is on screen — the live reply never renders, and it is still absent 12 s later.

main: reply swallowed main: still swallowed 12s later
A-11-swallowed.png A-12-swallowed-persists.png

B — this branch: the reply streams, and does not duplicate. Same scenario now renders the second "Done." live (left). When that reply's own turn lands while the pane is still working, the synthetic bubble is withdrawn and the count stays at two — no duplicate (right).

branch: repeated-prefix reply streams branch: its own turn lands, still 2 bubbles
R4-B1-repeated-prefix-streams.png R4-B2-turn-landed-no-dup.png

B — the two orderings that previously broke it. Left: the transcript lands the reply before the throttled status text arrives while the pane stays working (a subagent still running) — exactly two bubbles, no third. Right: a chat→terminal→chat peek taken while idle tears the transcript down to empty; the reply that arrives afterwards still streams, and is stable 12 s on.

transcript beats the status text: no duplicate after an idle terminal peek: still streams
R4-B3c-late-status-no-dup.png R4-B4-after-peek-streams.png
the peek itself (idle, chat→terminal→chat) stable 12s after the bubble appears
R4-B4d-back-to-chat-idle.png R4-B5-stable-12s.png

Testing

  • pnpm lint — root + mobile oxlint, audit:code-quality:native, check:max-lines-ratchet (352 grandfathered, no new bypasses), oxfmt --check: clean. No max-lines disables and no per-file cap bumps added.
  • pnpm typecheck — root three-project tsc and mobile tsc --noEmit: clean.
  • pnpm test — full mobile suite at 1c1afe52: 405 files, 3035 passed / 3 skipped. Root suite does not cover mobile/ and no src/ file is touched.
  • React Doctor changed-lines gate (check:react-doctor:changed): 0 issues.
  • check:reliability-gates — 65 gates, passed.
  • iOS simulator A/B against a mock desktop — see Screenshots. Both arms driven through the real UI (touch frames to the simulator; no OS-level input injection).
  • pnpm build — not run; no build-affecting change (React Native UI logic only). CI covers it.
  • Added or updated high-quality tests that would catch regressions — see below.

mobile-native-chat-streaming-gate.test.ts (new, 17 tests) drives sequences of (folded, streamingText, streamLive) ticks through one gate and locks the decision table: the repeated-prefix reply stays visible (the actual regression), the bubble hides once the real turn lands, an identical repeated reply is suppressed only by its own turn, hiding persists for the rest of the segment, a new reply part re-anchors, re-anchoring also clears the remembered text so the next turn's opener isn't misread as a new segment, a hidden gap taken mid-turn keeps the baseline, a hidden gap taken between turns does not adopt the empty tail, a reply whose turn lands before its status text is not adopted as history, a gate mounted mid-turn anchors on the first tail it sees, the first-tick fallback, reference-identity idempotency for a repeated tick, scope-swap baseline reset, and empty/whitespace text.

MobileNativeChatOverlay.test.ts (new, 6 tests) exercises the same behaviors through the real component — including both chat↔terminal peek orderings and a scope swap — so the ownership/lifetime decision is covered, not just the pure function. MobileNativeChatView.test.ts keeps one placement test for the gated bubble; mobile-native-chat-render-data.test.ts now asserts only placement of the synthetic row (between transcript and pending), since whether it renders at all is the gate's call.

The suite was mutation-checked against the production source (never the tests): 28 mutants, 22 killed. The decisive one reverts the gate to main's rule by dropping the tailId !== baselineTailId clause — it fails 14 tests, including the two that name the user-visible bug, which is what proves these tests could not pass against main. Others: dropping either conjunct of the anchor condition, inverting or removing segment-start detection, making advanceGate allocate a fresh object every render (kills all 6 overlay tests via an infinite render), reusing a gate across a scope change, collapsing streamScopeKey back to streamIdentity, view-gating streamLive, and bypassing the gate in the overlay.

Of the 6 survivors, 4 are provably equivalent mutants that no test can kill — text.startsWith('') is always true, so the prevText !== '' conjunct is redundant; showLoading on folded vs messages cannot differ because a loading session always returns the shared empty array; seeding the gate with a null scope is reset on the first derive; and nativeChatAgentWorking vs nativeChatStreamLive only diverge while chat is hidden, where the tail is null and the gate is inert anyway. The 5th (the assistant-role guard on the tail) is inherited unchanged from main. The 6th was a real gap in new code and is now closed by the 17th test.

AI Review Report

Reviewed across four rounds of independent same-model passes on three dimensions (correctness, tests/scope, render+perf), looping until clean. Two real defects were found and fixed in fed9ca38 before this report:

  1. Duplicate bubble (a regression vs main). A textless status tick re-anchored the baseline onto a reply that had just landed in the transcript, so the next text tick rendered it a second time. Reproduced with a trace harness ([null,null,"Done.","Done."]) and fixed by refusing to anchor on textless ticks taken inside a live turn.
  2. Headline bug still reproduced on one path. A chat→terminal peek taken while idle empties the transcript, and that empty tail was adopted as the baseline, stranding it ([null,null,null,"Done.",null] — flash, then vanish). Fixed by refusing to anchor on a null tail.

The combined condition — anchor only on a textless tick that carries a real tail and is either outside a live turn or on a gate that has never anchored — satisfies both plus the mount-mid-turn case. The one case it gives up is a transcript-first landing on the gate's very first tick (a ≤50 ms window), which degrades to main's existing suppress-on-prefix behavior.

The change cannot swallow a reply that main rendered. caughtUp requires tailLeadsWithStream, which is main's entire suppression predicate, plus a second conjunct — so this gate's suppression set is a strict subset of main's. A randomized differential run (2.4M ticks over varied text / tail / streamLive / scope sequences) found zero cases where this branch returns null and main returns text. That bounds the whole regression surface to one class — a spurious extra bubble — rather than leaving it open-ended.

Other findings verified and addressed:

  • Render purity / loops. The gate advances via the sanctioned derived-state render-time adjustment. advanceGate returns the same object when nothing moved, so a repeated (text, tail) pair produces no setState and the adjustment settles in one pass; the idempotency test asserts reference equality (toBe), so a future change that allocates a fresh gate per render — which would loop — fails the test. Convergence was proven twice by independent methods: exhaustive enumeration of the gate's state space (46,080 cases, three applications each — 0 non-settling, 0 flipped derived values) and randomized second passes (200,000 — 0 non-settling). Under real React, the worst case observed over 5,000 randomized updates was 2 passes, never 3, with no cross-component-update warnings.
  • Render cost. Measured with react-test-renderer against main as baseline: the extra pass is confined to the overlay's own function body — React discards the children of a render-phase-updated pass — so MobileNativeChatView renders exactly once per streaming tick, same as main, and the fold useMemo recomputes zero times during a turn. Wall clock is +13.8 µs/tick vs main on a realistic ~6.5 KB reply, i.e. +0.28 ms of CPU per second of streaming, or 0.03% of the 50 ms throttle window. While chat is hidden the gate is fully inert: streamingText is view-gated to undefined and the session returns a reference-stable empty transcript, so advanceGate returns by reference and setState never fires — 0 view renders and 0 fold calls per tick. While the bubble is suppressed the branch is strictly better than main, which kept rebuilding list data as the raw text grew.
  • Cross-chat leakage. The gate carries its own scopeKey and self-resets when the caller's identity differs, so a stale baseline from another tab can never license showing a bubble here; locked at both the gate and component level.
  • Dead code. The test-only buildMobileNativeChatData one-shot helper was deleted rather than left as a second, diverging copy of the rule.

Cross-platform: no keyboard shortcuts, shortcut labels, file paths, shell invocation, git commands, or Electron main-process code are touched. This is React Native renderer logic that behaves identically on iOS and Android and is agnostic of the desktop host OS, so it is unaffected by the macOS/Linux/Windows and native/WSL/SSH host distinctions. It reads only already-parsed transcript messages, so local worktrees, SSH worktrees, and folder workspaces are all equivalent here. No git provider (GitHub/GitLab) surface is involved.

Security Audit

No new input parsing from untrusted sources, no command execution, no path handling, no auth or secret handling, no dependency changes, and no IPC/RPC surface change (no new methods; existing subscribe/read paths are untouched). The gate holds two short strings and a message id in renderer memory and derives a boolean; it renders no new content — the streamed text was already rendered through the same Text path before this change, so there is no new injection surface. Agent-provided text is only compared with String.prototype.startsWith, never evaluated or interpolated into a command. No follow-up needed.

Notes

  • Scope is deliberately narrow: only the streaming bubble gate. The reconnect-replay, cached-transcript, stale-status, prompt-card, paging, write-lock, and tool-summary fixes from fix(mobile): native chat QA sweep — reconnect history, stale status, prompt-card and paging fixes (STA-3333) #12373 are not included and that PR remains open.
  • Behavior when text arrives on the gate's very first tick is intentionally unchanged (legacy suppress-on-prefix): with no tail ever observed there is no baseline to judge against, and a duplicated bubble is the worse failure. It self-corrects on the next textless tick outside a turn.
  • The gate treats a stream that isn't an extension of the previous tick as a new segment. If the upstream status feed ever delivers throttled partials out of order, the effect is a re-anchor (bubble shows), never a swallow.

Text alone can't tell "the transcript caught up with this stream" from
"a new reply repeats the previous turn's prefix", so the old suppress-on-
prefix rule swallowed genuine repeated replies. A stateful gate remembers
which transcript tail predates the current stream segment and hides the
bubble only when that tail moved during the segment, scoped to the active
host/workspace/tab/session so a swapped chat can't inherit a baseline.

Refs STA-3333.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The mobile native chat now uses a stateful streaming gate to suppress duplicate transcript content. The controller exposes stream liveness and a session scope key. The overlay derives gated streaming state before visibility checks and passes folded messages to the view. The chat view renders pre-folded messages and nullable streaming text. Tests cover repeated replies, hidden views, stream changes, transcript landing, mounting, and streaming row placement.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the mobile native chat streaming fix for repeated-prefix replies.
Description check ✅ Passed The description covers the required sections with detailed behavior, screenshots, testing, AI review, security audit, and notes.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Mobile QA — iOS Simulator A/B (/orca-mobile-emulator-qa)

Real device-client build against a mock desktop host (MOCK_NATIVE_CHAT=1), driven only by the sanctioned orca emulator tap CLI — no Computer Use, AppleScript, or OS-level input injection.

Rig: iOS Simulator STA-3333 QA · Expo dev client com.stably.orca.mobile · Metro :8097 · mock host :6833 · worktree-unique control files under mktemp -d.

Scenario (the exact reported bug): transcript ends on the assistant turn "Done."; the agent then starts a new reply that also begins "Done.". Both arms start from an identical idle state and receive an identical agentStatus flip to { state: 'working', lastAssistantMessage: 'Done.' }.

A/B

main (before) this branch (after)
Idle baseline — identical starting state main idle branch idle
Agent starts the repeated-prefix reply main swallowed
🐞 "Agent is working" + Stop, but the reply is swallowed — the user watches a bare spinner.
branch visible
✅ the streaming bubble renders.

No-duplicate regression check

Once the real turn lands in the transcript, the synthetic bubble is suppressed — exactly two "Done." rows (the two real turns), no third:

no duplicate

Local gates at 838cb67

  • tsc --noEmit (mobile) — clean
  • mobile-native-chat-streaming-gate.test.ts + MobileNativeChatView.test.ts + mobile-native-chat-render-data.test.ts — 29 passed
  • full mobile vitest — 404 files / 3024 passed / 3 skipped
  • oxlint (root + mobile), React Doctor changed-lines, changed-code quality, max-lines ratchet — all clean

Working tree is clean; no QA scaffolding is committed to the branch.

The gate lived in MobileNativeChatView, but MobileNativeChatOverlay returns
null whenever the user peeks at the terminal — that unmounts the view and
throws the baseline away, so the repeated-prefix reply was swallowed again on
the way back. Move the gate (and the fold memo it reads) up to the overlay,
which stays mounted across those toggles.

While hidden the transcript is empty and the throttled stream reports no text,
which the gate would have read as "idle" and re-anchored on. Pass the agent's
working state so a textless tick inside a live segment holds the baseline
instead. The scope key is now keyed off the tab rather than the view-gated
chat resolution, so it survives the toggle too; streamIdentity keeps its exact
previous value because the delayed-send guards compare against it.

Also drops a dead disjunct in the caught-up test: a null baseline is already
unequal to every real tail id.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
mobile/src/session/use-mobile-native-chat-controller.test.ts (1)

443-478: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Extract the shared harness and the deprecation-warning suppression.

This suite repeats the Harness component and the console.error filter that the earlier suite in this file already defines. The only difference is activeSessionTab. Extract one harness factory that accepts the tab plus one suppressRendererWarning helper, then reuse both. A third suite would otherwise copy the same block again.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 47fe5a2c-2543-473e-800b-3c35167611bf

📥 Commits

Reviewing files that changed from the base of the PR and between e9cf106 and 41aaa9d.

📒 Files selected for processing (10)
  • mobile/src/session/MobileNativeChatOverlay.test.ts
  • mobile/src/session/MobileNativeChatOverlay.tsx
  • mobile/src/session/MobileNativeChatView.test.ts
  • mobile/src/session/MobileNativeChatView.tsx
  • mobile/src/session/mobile-native-chat-render-data.ts
  • mobile/src/session/mobile-native-chat-streaming-gate.test.ts
  • mobile/src/session/mobile-native-chat-streaming-gate.ts
  • mobile/src/session/use-mobile-native-chat-controller.test.ts
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • mobile/src/session/use-mobile-native-chat-streaming-bubble.ts

…ests

The overlay regression test replayed the transcript before the stream text on
the way back from the terminal view. That ordering is backwards: the session
withholds `messages` until a fresh read settles (an RPC round trip) while the
throttled stream text returns in ~50ms — and with the transcript already back,
a gate that got discarded on the toggle still passes. Replay the real order,
which pins the gate's lifetime as intended.

Swaps the hidden-gap duplicate case for the in-view one (a tool frame clears
the assistant text mid-turn), which is where the hold actually earns its keep;
the hidden-gap direction stays covered at the gate level.
A textless status tick was re-anchoring the gate's pre-stream baseline, so
two paths still rendered wrong:

- The reply's transcript push beats its throttled status text whenever the
  pane stays `working` past the turn (a live subagent or background task).
  The tick in between adopted the just-landed reply as history, and the
  status text that followed rendered it a second time — a duplicate bubble,
  and a regression against main's suppress-on-prefix rule.
- Peeking at the terminal between turns empties the transcript. That empty
  tail was adopted as the baseline, so the next repeated-prefix reply was
  swallowed again — the bug this PR exists to fix.

Only a tick that carries a real tail and sits outside a live turn anchors
now, with an exception for a gate that has never anchored: mounted mid-turn,
the first real tail it sees is the best history it will ever get.

Also drop `buildMobileNativeChatData`, a test-only builder this PR had wired
the new gate into; its green test asserted the exact suppression this PR
removes. Its fold/pending/image coverage moves to the builder the view calls.
Mutation testing found the `prevText` reset on an anchoring textless tick
unpinned: keeping the previous turn's text there reads the next turn's
opener as a new segment, re-anchors onto the reply that just landed, and
renders it a second time — the same duplicate-bubble class already fixed
twice on this branch.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Follow-ups found during review — deliberately not in this PR

Four things surfaced across the review passes. None is a regression from this change and none belongs in this diff, so they're recorded here rather than fixed.

1. A duplicate bubble that this gate cannot fix (OpenCode / any hook that keeps lastAssistantMessage across turns).

The gate's input is a single string. When an agent starts a new turn and the hook still reports the previous turn's lastAssistantMessage as the preview, mobile receives a tick that is byte-identical to the case this PR exists for: a live turn, a preview string, and a transcript tail whose text starts with it. There is no discriminator left — the sequence is indistinguishable from "a genuine new reply repeats the previous turn's prefix". So the gate shows the bubble, and for that one hook the previous reply is briefly echoed. Show-over-hide is the deliberate trade: a duplicate that resolves on the next tick beats a swallowed reply that never appears.

The fix has to be upstream, where the discriminator still exists. The staleness is created by one line in src/shared/agent-hook-listener.ts:570:

lastAssistantMessage: update.clearLastAssistantMessage
  ? undefined
  : (update.lastAssistantMessage ?? previous.lastAssistantMessage)

That ?? previous is the carry-forward. Two things about it are worth knowing before anyone specs the fix:

  • The identical bug class is already solved three lines up, for interactivePrompt (:566-567): "don't inherit previous.interactivePrompt — valid only for its one AskUserQuestion event; carrying it forward leaves a stale live card." Same shape, same consequence.
  • The plumbing already exists. clearLastAssistantMessage (:535, :568) is a real field — but it has exactly one producer (:1919), on a Stop event where no message could be recovered. Nothing clears at turn start.

Do not simply set clearLastAssistantMessage at turn start, though — that is the obvious-looking fix and it regresses desktop. lastAssistantMessage is the fallback summary line for agents that aren't streaming a tool: worktree-card-compact-agent-row.tsx:38-55 returns toolName/toolInput for a working agent and otherwise falls through to lastAssistantMessage, so clearing it would blank the sidebar and dashboard summary for every stretch of a turn with no tool running — which is most of the thinking/streaming time. DashboardAgentRowMessage.tsx renders the same string and use-notification-dispatch.ts:201 puts it in the notification body; it is also persisted across sleep/resume (agent-session-resume.ts:53, workspace-session-sleeping-agents.ts:96).

So the discriminator has to be additive: carry the preview's turn id (or a previewIsStale boolean) alongside the text, leaving the text itself intact. Consumers that want a summary keep reading it as they do today; the mobile gate reads the flag and declines to treat a stale preview as a live stream.

2. Stale comment in src/shared/native-chat-streaming.ts:4-5.

"Desktop and mobile both use this so the show/hide rule can't drift between platforms."

That was already untrue before this PR. git grep "shared/native-chat-streaming'" <main> -- mobile/ returns nothing on main — the only importers are four desktop renderer files plus its own test. Mobile has always had its own rule. Worth correcting so the next reader doesn't assume changing that file moves mobile too.

3. Segment-start detection is prefix-based, and that is a chosen bound.

segmentStart fires when the new streamed text is not an extension of the previous tick's text. If a hook ever emits throttled partials out of order, or a later reply part is a strict prefix of an earlier one, the gate re-anchors instead of detecting the new segment. The failure direction is a visible bubble, never a swallow, which is why it's acceptable — but a preview sequence number upstream would make it exact rather than heuristic.

4. Gate ownership could be narrowed later.

The gate currently lives in MobileNativeChatOverlay because that component survives the chat↔terminal toggle while the chat list does not. Hoisting it into the controller was considered and rejected for now: it would fix only one of the four lifetime cases and would put render-phase state in a hook shared by non-chat consumers. Replacing the useState + render-phase setGate with a mutated ref was also rejected — a ref mutated during render survives an abandoned concurrent render, which would leave accumulated stream history behind and is exactly the class of bug React's derived-state pattern avoids.

@brennanb2025
brennanb2025 merged commit e4aadcc into main Aug 4, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…3333) (stablyai#12501)

* fix(mobile): keep repeated-prefix chat replies streaming

Text alone can't tell "the transcript caught up with this stream" from
"a new reply repeats the previous turn's prefix", so the old suppress-on-
prefix rule swallowed genuine repeated replies. A stateful gate remembers
which transcript tail predates the current stream segment and hides the
bubble only when that tail moved during the segment, scoped to the active
host/workspace/tab/session so a swapped chat can't inherit a baseline.

Refs STA-3333.

* fix(mobile): keep the streaming gate alive across chat/terminal toggles

The gate lived in MobileNativeChatView, but MobileNativeChatOverlay returns
null whenever the user peeks at the terminal — that unmounts the view and
throws the baseline away, so the repeated-prefix reply was swallowed again on
the way back. Move the gate (and the fold memo it reads) up to the overlay,
which stays mounted across those toggles.

While hidden the transcript is empty and the throttled stream reports no text,
which the gate would have read as "idle" and re-anchored on. Pass the agent's
working state so a textless tick inside a live segment holds the baseline
instead. The scope key is now keyed off the tab rather than the view-gated
chat resolution, so it survives the toggle too; streamIdentity keeps its exact
previous value because the delayed-send guards compare against it.

Also drops a dead disjunct in the caught-up test: a null baseline is already
unequal to every real tail id.

* test(mobile): model the real re-show ordering in the streaming-gate tests

The overlay regression test replayed the transcript before the stream text on
the way back from the terminal view. That ordering is backwards: the session
withholds `messages` until a fresh read settles (an RPC round trip) while the
throttled stream text returns in ~50ms — and with the transcript already back,
a gate that got discarded on the toggle still passes. Replay the real order,
which pins the gate's lifetime as intended.

Swaps the hidden-gap duplicate case for the in-view one (a tool frame clears
the assistant text mid-turn), which is where the hold actually earns its keep;
the hidden-gap direction stays covered at the gate level.

* fix(mobile): stop the streaming gate adopting a reply as its own history

A textless status tick was re-anchoring the gate's pre-stream baseline, so
two paths still rendered wrong:

- The reply's transcript push beats its throttled status text whenever the
  pane stays `working` past the turn (a live subagent or background task).
  The tick in between adopted the just-landed reply as history, and the
  status text that followed rendered it a second time — a duplicate bubble,
  and a regression against main's suppress-on-prefix rule.
- Peeking at the terminal between turns empties the transcript. That empty
  tail was adopted as the baseline, so the next repeated-prefix reply was
  swallowed again — the bug this PR exists to fix.

Only a tick that carries a real tail and sits outside a live turn anchors
now, with an exception for a gate that has never anchored: mounted mid-turn,
the first real tail it sees is the best history it will ever get.

Also drop `buildMobileNativeChatData`, a test-only builder this PR had wired
the new gate into; its green test asserted the exact suppression this PR
removes. Its fold/pending/image coverage moves to the builder the view calls.

* test(mobile): pin the textless anchor's text reset

Mutation testing found the `prevText` reset on an anchoring textless tick
unpinned: keeping the previous turn's text there reads the next turn's
opener as a new segment, re-anchors onto the reply that just landed, and
renders it a second time — the same duplicate-bubble class already fixed
twice on this branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant