Skip to content

fix(mobile): keep native chat ask dismissals tab-scoped and gated (STA-3333) - #12497

Merged
brennanb2025 merged 9 commits into
mainfrom
brennanb2025/sta-3333-ask-dismissal
Aug 5, 2026
Merged

brennanb2025 merged 9 commits into
mainfrom
brennanb2025/sta-3333-ask-dismissal

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

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:

  1. Dismissal lived in the unmounting subtree. useMobileNativeChatAskDismiss was called inside MobileNativeChatView, 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.

  2. 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 ungated detectedAsk (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:

  • Tab scope. Dismissals are keyed by session tab, so dismissing on tab 1 can't hide a structurally identical question on tab 2.
  • Delayed answer settlement. An answer can resolve after its prompt cleared, was replaced, or after the user switched tabs. Only a still-current prompt installs a lasting dismissal, and it records against the tab it originated on — not whichever tab happens to be active when the send resolves.

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; no max-lines disables and no per-file bump)
  • pnpm typecheck (mobile tsc --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.
  • Added or updated high-quality tests that would catch regressions

Tests added (8 in use-mobile-native-chat-ask-dismiss.test.ts, 2 in use-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 observing guard, the still-current guard, the tab scoping, and the blocked gate 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 the observing guard left its suite green. The added keeps a dismissal taken on-chat across a chat→terminal→chat toggle case closes it and is the one that reproduces the headline bug.

AI Review Report

Self-reviewed with focus on:

  • Render purity. Both writes (the detected-key ref and the dismissal reset) are in effects, not the render body — the earlier draft of this fix set the ref during render. Verified against the react-doctor changed-lines gate, which runs over the whole effect, not just changed lines.
  • Reset correctness. The reset is keyed on the detected prompt rather than on ask != null; that is what keeps gating (working/done) from being read as "the prompt cleared". The observing guard is what keeps an off-chat null from erasing the dismissal.
  • Stale-closure safety. dismissAsk closes over the askKey/scopeKey of 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.
  • Cross-platform (macOS/Linux/Windows). No keyboard shortcuts, shortcut labels, path handling, shell invocation, Git commands, or Electron-specific code are touched. This is React Native renderer state on the mobile client, identical on iOS and Android and agnostic of the desktop host OS. It is equally agnostic of native vs WSL vs SSH hosts and of git-worktree vs folder workspaces — no code path here reads workspace kind, host kind, or the filesystem.
  • Bounded growth. Both maps are keyed by session tab id, scoped to the controller instance, and hold short strings; tab counts are small and bounded per session.

Security Audit

No new input parsing, command execution, path handling, auth, secret handling, IPC, or RPC surface. No dependency changes (the mobile/pnpm-lock.yaml reformat my local pnpm produced was reverted — it was unrelated libc-field churn). The only data handled is an already-parsed AskPrompt, serialized with JSON.stringify purely as an in-memory identity key that is never rendered, logged, persisted, or sent anywhere.

Notes

  • Behavior change worth a reviewer's attention: the blocked gate 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.
  • No simulator pass was run; the fix is state logic covered at its pure seams by unit tests. A device check of the chat→terminal→chat toggle would be a reasonable belt-and-braces follow-up.
  • Touches 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.

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

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@brennanb2025, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fecfa959-9463-41f7-ac6e-d65d994187aa

📥 Commits

Reviewing files that changed from the base of the PR and between 39c3c58 and bea2de2.

📒 Files selected for processing (12)
  • mobile/src/session/MobileNativeChatOverlay.tsx
  • mobile/src/session/MobileNativeChatView.tsx
  • mobile/src/session/use-mobile-native-chat-ask-dismiss.test.ts
  • mobile/src/session/use-mobile-native-chat-ask-dismiss.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-prompts.test.ts
  • mobile/src/session/use-mobile-native-chat-prompts.ts
  • src/renderer/src/components/native-chat/native-chat-dismiss-key.test.ts
  • src/renderer/src/components/native-chat/native-chat-dismiss-key.ts
  • src/shared/native-chat-ask.test.ts
  • src/shared/native-chat-ask.ts
📝 Walkthrough

Walkthrough

Native 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)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the mobile fix for tab-scoped and gated native chat ask dismissals.
Description check ✅ Passed The description covers the required sections, explains the user-visible change, documents testing and skipped build work, and includes AI review and security details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 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.

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

Copy link
Copy Markdown
Contributor Author

Review + QA evidence — head 6b9d5e18b8

Reviewed the complete effective diff against main in a fresh same-model/same-thinking subagent loop until it returned clean. Two real defects were found and fixed on this branch; everything else the passes proposed was rejected as scope expansion or style churn. Scope held: 8 files, all under mobile/src/session/ — no PTY serialization, no partial-send semantics, no other STA-3333 work.

Defects found and fixed during review

1. A never-read transcript that errors retired the dismissal on no evidence (9aef3b2d1a)

nativeChatTranscriptSettled originally accepted status === 'error' unconditionally. But the host's initial-drain error frame carries an empty message list (src/main/native-chat/transcript-watch-error.test.ts:120 asserts onInitialSnapshot([], false, 0, 'Transcript unavailable')), mobile-native-chat-stream-frame.ts:39 checks frame.error before the messages array so the frame applies as kind:'error' and its rows are discarded, and use-mobile-native-chat-session.ts:154 does setRead({status:'error'}) with no setMessages while the identity-change effect already cleared the list. The error is not terminal — a real snapshot follows once the read recovers.

Failure: re-subscribe → initial drain throws → settled-but-empty → dismissal retired → recovered snapshot lands with the ask still pending → the answered card returns over the composer. Fixed by requiring rows to be present:

nativeChatSession.status === 'ready' ||
  (nativeChatSession.status === 'error' && nativeChatSession.messages.length > 0)

2. A restarted session's identical first question was permanently hidden (6b9d5e18b8, found via an OSS reference survey)

Keyed by tab alone, a dismissal taken in session S1 survived a restart / /clear / resume into S2 in the same tab. Because the new session's first question is often byte-identical (same repo, same prompt, same template), detectedAskKey === dismissedKey and the retirement effect short-circuits at use-mobile-native-chat-ask-dismiss.ts:47 — so the live card never rendered and the turn sat blocked with no visible prompt. Fixed by scoping to tab and provider session (mobile-native-chat-eligibility.ts:57 proves the session id changes within one tab on restart), using the same \0 shape as streamIdentity:

const nativeChatAskScopeKey = `${activeSessionTabId ?? ''}\0${activeChatSessionId ?? ''}`

Both guards were mutation-killed independently in mktemp -d scratch space: reverting the scopeKey to tab-only reds exactly shows a restarted session's identical first question on the same tab (1 failed / 24 passed); dropping messages.length > 0 reds exactly keeps the dismissal when the first read of a transcript errors (1 failed / 24 passed).

Deliberately not done (agreed with the survey, each is its own ticket): strengthening the ask key with a request id (promptInteractionKey is desktop-only; extractPendingAsk drops tool_use_id at decode, so a content hash is forced, not chosen); host-side request terminators; TTL/expiry; stale-request rejection (that is #12503's territory). The dismissal Map is deliberately unbounded — FIFO eviction in this codebase evicts the active scope and reintroduces the very bug; growth is tabs × session-restarts per mounted controller, a handful of ~100-byte entries.

Gates at this 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)

S1 — stale done status, ask still visible

S2b — answered, card dismissed

S4 — restarted session re-shows the identical question

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)

E1 — Electron smoke, 0 console errors

Screenshots are published as a parentless commit on evidence/pr-12497-screenshots (4005f25), not committed to this branch.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

QA evidence for bea2de2817 (senior-review result: CLEAN)

  • Electron: current head launched through CDP; title Orca; no renderer errors or console output.
  • iOS: the Ask prompt rendered, Keep the fix was selected, and the mock accepted the terminal response. The dismissal/remount path is covered by the focused mobile regression tests.
  • Conflicts with main are resolved; the pushed branch is clean.

Electron smoke

Electron smoke

iOS Ask flow

Prompt Selection
Ask prompt Ask selection

@brennanb2025
brennanb2025 merged commit c3ddc0d into main Aug 5, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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
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