Skip to content

fix(mobile): gate native chat approval card on a paused agent (STA-3144) - #12206

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/sta-3144-allow-deny-gate
Aug 3, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/sta-3144-allow-deny-gate

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

Fixes STA-3144 (#11928): on Orca Mobile's native chat, the tool-approval card (Allow Bash? with Allow/Deny) was derived purely from the presence of an approval envelope in agentStatus.interactivePrompt, with no check that the agent is actually paused. Because the host deliberately keeps a real permission wait sticky, the card stayed pinned above the composer while the agent kept working and after the turn was done — on a phone there is no terminal to compare against, so a stale card was indistinguishable from a live one.

The fix moves the envelope path (parseApprovalFromStatus) inside the same blocked && status gate the heuristic path (detectAgentPermission) already honours, which is the documented contract in mobile-native-chat-permission.ts ("only fire when the agent is actually paused"). The card now exists exactly while the agent is waiting/blocked and dismisses on its own when the state clears. Heuristic detection still takes precedence over the envelope inside the gate, unchanged.

Deliberately NOT included (per the adversarial review on the issue): client-side dismiss-on-answer. A content-keyed dismissal cannot distinguish "stale because answered" from "the same command is being asked again", and hiding a live prompt is strictly worse than showing a stale one. That needs a host-side request id and belongs in its own issue.

Screenshots

iOS Simulator (iPhone 17 Pro, dev client + mock native-chat host), driving agentStatus through the states from the report:

Before — card shown while the agent is working (note the working indicator + Stop button), and still shown after the turn is done:

bug: card while working
bug: card after done

After — a genuine approval (waiting + envelope) still shows the card, and flipping to working with the envelope still sticky dismisses it:

fixed: card while waiting
fixed: no card once working

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Ran inside mobile/ (the changed code is mobile-only; the root vitest config excludes mobile/**): pnpm typecheck, pnpm lint (oxlint), oxfmt --check src, and targeted vitest over use-mobile-native-chat-prompts.test.ts, mobile-native-chat-permission.test.ts, and use-mobile-native-chat-controller.test.ts — 36 tests pass. The new use-mobile-native-chat-prompts.test.ts locks the gate down: no card for working/done/missing status, card for waiting/blocked, and heuristic-over-envelope precedence while paused. Both failing cases reproduce on main before the fix. pnpm build not run: mobile has no build script (Expo dev client); desktop build is untouched.

AI Review Report

Reviewed the gate change for: (1) suppressing legitimate approvals — the envelope now renders for exactly the waiting/blocked states, verified live on the simulator and by test; (2) precedence regressions — detectAgentPermission still wins over the envelope when both fire, covered by a new test; (3) the phantom-card path from the issue (child-driven payload re-emitting a cached envelope with state: 'working') — now filtered by the gate; (4) the sibling question/ask cards — untouched, ask intentionally remains outside this gate because AskUserQuestion has its own dismissal protocol. Cross-platform: the change is pure TypeScript state derivation in the shared mobile app (iOS/Android identical); no shortcuts, labels, paths, shell, or Electron surfaces are touched, and desktop hosts on macOS/Linux/Windows only feed it the same serialized agentStatus.

Security Audit

No new input handling, command execution, path handling, auth, secrets, dependencies, or IPC. The change narrows when an existing UI affordance renders; it strictly reduces the states in which a tap can write approval bytes (1/Escape) into a pane — previously a stale card invited writes into a working agent's PTY, which is the riskier behavior. Parsing of interactivePrompt (untrusted host-provided JSON) is unchanged and already guarded.

Notes

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Updated useMobileNativeChatPrompts so permission parsing and approval-prompt fallback occur only for blocked or waiting agents. Added tests for agent statuses, approval-envelope parsing, parsed command details, and numbered-menu precedence during pauses.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the mobile fix and the key behavior change: showing the native approval card only when the agent is paused.
Description check ✅ Passed The description covers the user-visible change, screenshots, testing, review, security, platform compatibility, and deferred follow-up work.
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
📝 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.

@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 (2)
mobile/src/session/use-mobile-native-chat-prompts.ts (1)

22-24: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reduce this comment to one line.

The comment repeats the visible blocked condition across three lines. Keep only the non-obvious sticky-envelope rationale.

As per coding guidelines, “Comments must be concise, limited to non-obvious information, and preferably one line.”

Proposed change
-  // Both permission paths sit inside the paused gate: an approval envelope can
-  // outlive its answer (the host keeps it sticky), so only a waiting/blocked
-  // agent may surface it — never a working or done one (STA-3144).
+  // Approval envelopes are sticky, so surface them only while the agent is paused.

Source: Coding guidelines

mobile/src/session/use-mobile-native-chat-prompts.test.ts (1)

2-2: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace the deprecated test renderer.

React 19 deprecates react-test-renderer. Use the project-supported React Testing Library renderer for this hook test.

#!/usr/bin/env sh
# Locate supported hook-test utilities and existing renderer usage.
git grep -n -e 'react-test-renderer' -- mobile || true
git grep -n -e '`@testing-library/`' -- mobile || true
git grep -n -e 'renderHook' -- mobile || true

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 50acb949-4997-4ffc-be2c-b44cb294f8e2

📥 Commits

Reviewing files that changed from the base of the PR and between c9a37f5 and 5a5d65b.

📒 Files selected for processing (2)
  • mobile/src/session/use-mobile-native-chat-prompts.test.ts
  • mobile/src/session/use-mobile-native-chat-prompts.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Mobile emulator QA — iPhone 17 Pro

Waiting/blocked paused-agent state: the Bash approval card is shown with Allow/Deny.

waiting-approval.png

Working state with the same approval envelope: the card is gated out while the native Chat UI remains active.

working-no-approval.png

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