Repository navigation
fix(mobile): keep native chat ask dismissals tab-scoped and gated (STA-3333) - #12497
Conversation
Dismissal state lived in the chat view subtree, which unmounts on a chat<->terminal toggle, so an answered ask card came back on return. It also had no tab scope and no waiting/blocked gate. - move dismissal into the controller, keyed per session tab - gate ask cards on waiting/blocked like the permission path already is, and retire a dismissal off the ungated detected prompt so a working/done status can't be mistaken for the prompt clearing - ignore a dismissal that settles after its prompt cleared or was replaced Refs STA-3333.
|
Warning Review limit reached
Next review available in: 13 seconds You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (12)
📝 WalkthroughWalkthroughNative chat prompts now expose detected asks separately from state-gated visible asks. Dismissal state is scoped by session tab and remains stable across hidden views and transient transcript loading. The controller now filters dismissed asks and exposes a stable ask key with a dismissal callback. The overlay passes these values to the chat view, which dismisses asks after accepted answers or cancellations. Tests cover prompt replacement, transcript reloads, visibility changes, scope isolation, and state gating. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
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. Comment |
A view toggle or tab switch re-subscribes the native-chat transcript, and useMobileNativeChatSession withholds `messages` until that read settles. A transcript-derived ask therefore reads as null while the chat surface is already visible, so the reset effect took it as "the agent moved on" and retired a live dismissal — the answered card came back, which is the bug the off-chat guard was meant to close. Treat an unobserved null as unobserved: `observing` now also requires the read to have settled. A prompt that is already detected stays observable on its own, so a status-derived ask still registers on first paint and an answer taken during that first load is still accepted.
A hook row idle past AGENT_STATUS_STALE_AFTER_MS (30m) projects to `done` with no interactivePrompt, so the transcript fallback is the only source left for a still-pending question. Gating it behind waiting/blocked made that question unanswerable from mobile. Only the sticky status payload needs the gate; `extractPendingAsk` clears itself on the tool result. Also pins the load-window clause in the ask-observability guard, which was behaviourally load-bearing but killed no test.
…ask"
The ask-observability guard only excused `transcriptLoading`, which is true
for an in-flight read alone. useMobileNativeChatSession also withholds
`messages` when the client is gone ('idle') or the tab has not reported a
provider session yet ('waiting-session') — both leave the flag false over an
empty list that was never read. The derived prompt then read as null, the
reset effect took that as "the agent moved on", and a live dismissal was
retired; when the read landed with the question still pending the answered
card came back — the resurfacing bug this guard exists to close.
Gate on the read having actually settled instead. 'error' still counts: it
keeps the last successful read in `messages`, so a prompt that clears under
it is real evidence, unlike a list that was never populated.
Also locks three guards that killed no test: the sticky-status suppression
of the transcript fallback (which is what makes the new paused gate hold in
the post-answer window), the reset effect's identity bail-out, and showAsk's
empty-prompt case. The transcript stand-in now derives `transcriptLoading`
from `status` the way the real hook couples them, so these tests can only
express states the session hook can reach.
Refs STA-3333.
…t input Both wirings were unpinned: swapping `scopeKey` to a constant or feeding the gated `ask` in as `detectedAsk` left the whole mobile suite green.
…es a dismissal `status === 'error'` was treated as settled on the claim that an error keeps the last successful read in `messages`. That only holds for an error that lands on top of an earlier read. The host forwards an initial-drain failure as an error frame carrying an EMPTY list (transcript-watch-error.test.ts), the mobile frame applier checks `frame.error` before the messages array so those rows are discarded, and the session hook's error path never calls `setMessages` — so a first-read error leaves `messages` at the `[]` the identity-change effect wrote. That frame is also not terminal: the watcher keeps `initialDrain` true and a real snapshot follows once the read recovers. So a re-subscribe whose first read errors made the never-populated list read as "no ask", retired the live dismissal, and the recovered snapshot brought the answered card back over the composer — the exact resurfacing this guard exists to close, and most likely on remote/SSH transcript reads. Require rows for the error case. Rows can only be present once a read landed, so the predicate is never wrong in the resurfacing direction; it only declines to retire a dismissal when the transcript was never observed. Also drop the dismiss hook's `detectedAsk = ask` default and make both prompts required. That default silently fed the gated prompt in as the detected one, which is the pre-fix behavior: a paused-out card would read as "prompt gone" and retire the dismissal. tsc now enforces the ungated payload at every call site instead of leaving a trap for the next caller.
… tab A restart, /clear, or resume swaps the provider session inside one tab. The next session's first question is often byte-identical, so a tab-keyed dismissal hid the live card and left the turn blocked with nothing to act on.
Review + QA evidence — head
|
| Gate | Result |
|---|---|
mobile vitest src/session |
928 passed / 114 files |
mobile tsc --noEmit |
0 |
root oxlint mobile/src/session/ |
0 |
code-quality native plugins --deny-warnings |
0 |
| react-doctor changed-lines | 0 |
| max-lines ratchet | 0 new bypasses |
oxfmt --check |
clean |
PR CI on 6b9d5e18b8 |
42 pass, 1 skipping |
Mobile simulator QA — iOS sim, orca emulator rig (no input injection)
Bundle provenance verified first: the 26 MB Metro expo-router/entry.bundle contains nativeChatAskScopeKey (2 hits) and status === 'error' && nativeChatSession.messages.length > 0, so the screenshots below are of the fixed code.
| # | Scenario | Result |
|---|---|---|
| S1 | Hook row aged past AGENT_STATUS_STALE_AFTER_MS → projected to state:'done' with interactivePrompt dropped, ask pending only in the transcript |
Card visible — the core fix (shot) |
| S2 | Answer it | Mock logged [mock] terminal.send mode=accept text="2"; card dismissed (select, dismissed) |
| S3 | chat → terminal → chat round-trip (overlay unmounts) | Still dismissed (terminal, back in chat) |
| S4 | Provider session flips to mock-chat-session-2, byte-identical question |
Re-shows — defect 2 (shot) |
| S5 | Genuinely different question, same session | Re-shows — no over-suppression (shot) |
Honest limitation: there is no matching pre-fix screenshot for S4. The bug requires the dismissal to persist across the session flip, and any bundle swap (Fast Refresh or cold relaunch) resets that React state — so the pre-fix behavior is proven by the mutation test above rather than by a photograph.
Electron smoke
Desktop imports none of the changed modules — grep -rn "use-mobile-native-chat-ask-dismiss\|use-mobile-native-chat-prompts\|use-mobile-native-chat-controller" src config tests is empty — so this is a no-regression check, not a feature check. Launched via $electron + playwright-cli over CDP (no Computer Use, no AppleScript, no OS-level automation or input injection): title Orca, 0 console errors, 1 warning. (shot)
Screenshots are published as a parentless commit on evidence/pr-12497-screenshots (4005f25), not committed to this branch.
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
…A-3333) (stablyai#12497) * fix(mobile): keep native chat ask dismissals tab-scoped and gated Dismissal state lived in the chat view subtree, which unmounts on a chat<->terminal toggle, so an answered ask card came back on return. It also had no tab scope and no waiting/blocked gate. - move dismissal into the controller, keyed per session tab - gate ask cards on waiting/blocked like the permission path already is, and retire a dismissal off the ungated detected prompt so a working/done status can't be mistaken for the prompt clearing - ignore a dismissal that settles after its prompt cleared or was replaced Refs STA-3333. * fix(mobile): keep an ask dismissal through the transcript re-subscribe A view toggle or tab switch re-subscribes the native-chat transcript, and useMobileNativeChatSession withholds `messages` until that read settles. A transcript-derived ask therefore reads as null while the chat surface is already visible, so the reset effect took it as "the agent moved on" and retired a live dismissal — the answered card came back, which is the bug the off-chat guard was meant to close. Treat an unobserved null as unobserved: `observing` now also requires the read to have settled. A prompt that is already detected stays observable on its own, so a status-derived ask still registers on first paint and an answer taken during that first load is still accepted. * fix(mobile): keep the transcript-derived ask outside the paused gate A hook row idle past AGENT_STATUS_STALE_AFTER_MS (30m) projects to `done` with no interactivePrompt, so the transcript fallback is the only source left for a still-pending question. Gating it behind waiting/blocked made that question unanswerable from mobile. Only the sticky status payload needs the gate; `extractPendingAsk` clears itself on the tool result. Also pins the load-window clause in the ask-observability guard, which was behaviourally load-bearing but killed no test. * fix(mobile): treat a never-read transcript as unobserved, not as "no ask" The ask-observability guard only excused `transcriptLoading`, which is true for an in-flight read alone. useMobileNativeChatSession also withholds `messages` when the client is gone ('idle') or the tab has not reported a provider session yet ('waiting-session') — both leave the flag false over an empty list that was never read. The derived prompt then read as null, the reset effect took that as "the agent moved on", and a live dismissal was retired; when the read landed with the question still pending the answered card came back — the resurfacing bug this guard exists to close. Gate on the read having actually settled instead. 'error' still counts: it keeps the last successful read in `messages`, so a prompt that clears under it is real evidence, unlike a list that was never populated. Also locks three guards that killed no test: the sticky-status suppression of the transcript fallback (which is what makes the new paused gate hold in the post-answer window), the reset effect's identity bail-out, and showAsk's empty-prompt case. The transcript stand-in now derives `transcriptLoading` from `status` the way the real hook couples them, so these tests can only express states the session hook can reach. Refs STA-3333. * test(mobile): pin the ask dismissal's tab scope and ungated retirement input Both wirings were unpinned: swapping `scopeKey` to a constant or feeding the gated `ask` in as `detectedAsk` left the whole mobile suite green. * fix(mobile): require a landed read before an errored transcript retires a dismissal `status === 'error'` was treated as settled on the claim that an error keeps the last successful read in `messages`. That only holds for an error that lands on top of an earlier read. The host forwards an initial-drain failure as an error frame carrying an EMPTY list (transcript-watch-error.test.ts), the mobile frame applier checks `frame.error` before the messages array so those rows are discarded, and the session hook's error path never calls `setMessages` — so a first-read error leaves `messages` at the `[]` the identity-change effect wrote. That frame is also not terminal: the watcher keeps `initialDrain` true and a real snapshot follows once the read recovers. So a re-subscribe whose first read errors made the never-populated list read as "no ask", retired the live dismissal, and the recovered snapshot brought the answered card back over the composer — the exact resurfacing this guard exists to close, and most likely on remote/SSH transcript reads. Require rows for the error case. Rows can only be present once a read landed, so the predicate is never wrong in the resurfacing direction; it only declines to retire a dismissal when the transcript was never observed. Also drop the dismiss hook's `detectedAsk = ask` default and make both prompts required. That default silently fed the gated prompt in as the detected one, which is the pre-fix behavior: a paused-out card would read as "prompt gone" and retire the dismissal. tsc now enforces the ungated payload at every call site instead of leaving a trap for the next caller. * fix(mobile): scope the ask dismissal to the provider session, not the tab A restart, /clear, or resume swaps the provider session inside one tab. The next session's first question is often byte-identical, so a tab-keyed dismissal hid the live card and left the turn blocked with nothing to act on. * chore: restore upstream formatting







Summary
Split from #12373 (item 4 of that PR's list) so it can land and be reviewed independently. #12373 stays open and untouched.
A dismissed AskUserQuestion card came back on mobile. Two causes, both fixed here:
Dismissal lived in the unmounting subtree.
useMobileNativeChatAskDismisswas called insideMobileNativeChatView, which unmounts on a chat→terminal→chat toggle, so the dismissal was destroyed on the way out. Worse, the reset rule was "prompt went null ⇒ agent moved on ⇒ forget the dismissal" — and while the chat surface is hidden the prompt derives to null unconditionally, so toggling away actively erased it. Dismissal now lives in the controller (which stays mounted), keyed per session tab, and only resets while the chat surface can actually observe the prompt.Ask cards had no waiting/blocked gate. The prompt payload outlives its answer — the agent emits a post-tool event carrying the same prompt — so a sticky payload rendered as a live card while the agent was already working or done. Ask now sits in the same paused gate the permission/approval path has had since STA-3144.
Gating and dismissal interact, so the hook takes both the gated
ask(what to render) and the ungateddetectedAsk(what the host still reports). A dismissal is retired only when the detected prompt genuinely clears or changes — a working/done status hides the card but proves nothing about the prompt itself.Two ordering rules fall out and are locked by tests:
Scope is deliberately narrow: no PTY write serialization and no partial-send semantics from #12373 are included, and no interfaces from those were needed.
Screenshots
No visual change— no styling, copy, layout, or token changes. The only user-visible difference is which ask cards appear: a dismissed card stays gone across a view toggle, and a sticky prompt no longer renders as a live card while the agent is working or done.Testing
pnpm lint(root oxlint, mobile oxlint,oxlint --config config/oxlint-code-quality-native-plugins.json src config tests mobile --deny-warnings, max-lines ratchet,lint-react-doctor-changed.mjs,oxfmt --check— all clean; nomax-linesdisables and no per-file bump)pnpm typecheck(mobiletsc --noEmit)pnpm test(full mobile suite: 403 files, 3021 passed / 3 skipped)pnpm build— not run; no build-affecting changes (React Native UI/state only). CI covers it.Tests added (8 in
use-mobile-native-chat-ask-dismiss.test.ts, 2 inuse-mobile-native-chat-prompts.test.ts): dismissal survives a view toggle when taken on-chat and when the answer settles while off-chat; a working/done status hides the card without retiring the dismissal; an answer settling after its prompt cleared is ignored; an answer settling after a tab switch records against its originating tab; per-tab isolation; a genuinely different prompt still shows; the waiting/blocked gate on both the status-derived and transcript-derived ask.I mutation-tested each one rather than trusting a green run — reverting the
observingguard, the still-current guard, the tab scoping, and theblockedgate each turns the corresponding test red. That surfaced a real gap: #12373's own version of the toggle test only covered the off-chat dismissal ordering, so removing theobservingguard left its suite green. The addedkeeps a dismissal taken on-chat across a chat→terminal→chat togglecase closes it and is the one that reproduces the headline bug.AI Review Report
Self-reviewed with focus on:
ask != null; that is what keeps gating (working/done) from being read as "the prompt cleared". Theobservingguard is what keeps an off-chat null from erasing the dismissal.dismissAskcloses over theaskKey/scopeKeyof the render that showed the card, and validates against the ref's committed detected key. That is deliberate: an in-flight answer must be attributed to the prompt and tab it was given for, not to whatever is active when it resolves.Security Audit
No new input parsing, command execution, path handling, auth, secret handling, IPC, or RPC surface. No dependency changes (the
mobile/pnpm-lock.yamlreformat my local pnpm produced was reverted — it was unrelated libc-field churn). The only data handled is an already-parsedAskPrompt, serialized withJSON.stringifypurely as an in-memory identity key that is never rendered, logged, persisted, or sent anywhere.Notes
blockedgate means a host that never publishes agent status will not surface ask cards at all. This matches the pre-existing behavior of the permission and question cards (STA-3144), so it is a consistency fix rather than a new limitation — but it is a real narrowing, not a no-op.MobileNativeChatView.tsx,MobileNativeChatOverlay.tsx, and the controller, which fix(mobile): native chat QA sweep — reconnect history, stale status, prompt-card and paging fixes (STA-3333) #12373 also touches — textual conflicts are expected against it whichever lands second.Refs STA-3333.