Skip to content

fix(mobile): mute stale agent status and disable Stop while disconnected (STA-3333) - #12496

Closed
brennanb2025 wants to merge 12 commits into
mainfrom
brennanb2025/sta-3333-stale-agent-status
Closed

brennanb2025 wants to merge 12 commits into
mainfrom
brennanb2025/sta-3333-stale-agent-status

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When the mobile transport drops, the last agent status is cached and Stop cannot reach the terminal. This PR makes that state honest:

  • After a continuous 600 ms connection loss, Agent is working becomes Agent status stale; the dots are removed and their animation loops are stopped.
  • Stop disables immediately when the transport is not live and stays disabled until the controller's input lease is acknowledged.
  • Reconnect clears stale feedback synchronously. A later disconnect starts a fresh hold instead of inheriting the previous timer.
  • The status row is a polite live region so Android screen readers announce the label change.
  • Desktop and mobile share the pure Stop-availability policy in src/shared/native-chat-action-availability.ts. Mobile supplies canonical transport liveness and the controller's exact inputSendable write gate instead of inferring either from the composer lock.

The hold runs only on connection transitions; this adds no polling, stream-path work, or message-list re-render dependency.

Split from #12373. This is an independent, main-based PR with no Git dependency on that larger QA sweep.

Refs STA-3333.

Screenshots

Electron — live agent

Electron native chat with a live working agent and enabled Stop

Validated in the real Electron app through CDP: the working row animates and Stop is enabled while the target is writable.

iPhone — disconnected agent

iPhone native chat with stale agent status and disabled Stop

Validated on the real iOS development build with Orca's emulator tooling: after the mock WebSocket is stopped, the row reads Agent status stale, the dots are absent, and AX reports Stop the agent disabled.

Testing

Final reviewed head: 95edf5950d

  • 42 focused mobile tests across the View, Overlay, Indicator, and Controller
  • 16 focused desktop/shared policy tests
  • Root and mobile TypeScript checks
  • Oxlint and formatting
  • React changed-lines checks
  • Max-lines ratchet
  • Node 24 changed-code quality: 0 findings
  • Real Electron live-state QA and real iPhone live-to-disconnected QA

The focused tests cover the 600 ms hold, timer cancellation, synchronous recovery, re-disconnect hold restart, lease-wait Stop gating, animation cleanup/restart, and the real socket-loss case where composer lock state is not yet available.

Review

The same-model senior review loop was rerun after every finding until explicitly CLEAN. It also verified a clean synthetic merge with current main after the adjacent STA-3332 changes landed; both features are retained.

Review fixes included:

  1. Giving stale status its own connection-scoped hold instead of deriving it from the composer's latched reason.
  2. Clearing stale feedback during the reconnect render to prevent a one-frame flash.
  3. Sourcing liveness and Stop writability from canonical controller state, including the acknowledged input lease.

No security, dependency, IPC/RPC, platform, SSH, folder-workspace, or hot-path performance surface is added.

The working row kept animating "Agent is working" and Stop stayed live after
the transport dropped, so pre-disconnect status read as live activity and a
Stop tap could not reach the PTY. Derive staleness from the debounced composer
lock so connection blips don't flicker the row.

Refs STA-3333.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The change adds shared native-chat stop availability checks. The mobile controller exposes transport liveness and Stop-target writability. The mobile chat view delays disconnected status for 600 ms, passes stale state to the working indicator, and disables the Stop control when stopping is unavailable. The working indicator hides dots, stops animations, and displays “Agent status stale” while stale. Tests cover these behaviors and recovery transitions.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.33% 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
Title check ✅ Passed The title clearly describes the primary mobile changes: stale status feedback and disabled Stop behavior during transport disconnection.
Description check ✅ Passed The description covers user-visible behavior, screenshots, testing, review findings, security risks, and platform validation.
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
📝 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.

…bel readable

Two defects in the first cut of this fix, both found in review.

The composer lock latches on the first non-null reason and never unlatches
between reasons, so once a lease wait had held its 600ms, a later drop to
'disconnected' flipped the row instantly with no hold at all. Reconnect always
lands on 'waiting' first — the lease clears its ready handles on disconnect —
so a flapping link strobed the label, tore down and rebuilt the dot animation,
and toggled Stop at flap rate. Staleness now runs its own 600ms hold on
'disconnected'; `lockReason` and the composer are untouched, and recovery stays
immediate.

Dimming the row to 0.55 opacity dropped the label from 5.62:1 to 2.53:1 against
bgBase, under AA and even under the large-text floor, on the one element left
carrying the state once the dots go. The existing 0.55 uses are all inactive
controls, which WCAG exempts; informational text is not. The label swap and the
removed dots already read as "not live", so the dim is gone.

Also drops a vacuous assertion: `onStop` was asserted un-called without any
press being attempted, under a Pressable mocked as a bare host string, so it
passed with the guard deleted.

Refs STA-3333.

@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/MobileAgentWorkingIndicator.test.ts (1)

1-3: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Do not extend deprecated react-test-renderer coverage.

React 19 deprecates react-test-renderer. The new suite suppresses its warning, and the new chat-view cases extend the same test path. Port these additions to the repository’s React Native Testing Library setup if it exists.

  • mobile/src/session/MobileAgentWorkingIndicator.test.ts#L1-L3: replace the new deprecated renderer import.
  • mobile/src/session/MobileAgentWorkingIndicator.test.ts#L25-L34: remove warning suppression after migration.
  • mobile/src/session/MobileAgentWorkingIndicator.test.ts#L50-L58: render through the supported test utility.
  • mobile/src/session/MobileNativeChatView.test.ts#L168-L268: move the new stale-status cases to the supported test utility.

Based on library documentation, React 19 deprecates react-test-renderer and recommends React Testing Library.

#!/usr/bin/env sh
set -eu

# Verify whether React Native Testing Library is already configured and locate
# all current React Test Renderer usage before selecting the migration scope.
git grep -n -I -C 2 \
  -e 'react-test-renderer' \
  -e '`@testing-library/react-native`' \
  -- package.json ':(glob)**/package.json' || true

git grep -n -I -C 2 \
  -e 'react-test-renderer' \
  -e '`@testing-library/react-native`' \
  -- \
  ':(glob)**/*.test.ts' \
  ':(glob)**/*.test.tsx' \
  ':(glob)**/*.spec.ts' \
  ':(glob)**/*.spec.tsx' || true

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2b52c68e-55ed-475e-a01c-cc8c4cbf2b5b

📥 Commits

Reviewing files that changed from the base of the PR and between e9cf106 and 585b24b.

📒 Files selected for processing (5)
  • mobile/src/session/MobileAgentWorkingIndicator.test.ts
  • mobile/src/session/MobileAgentWorkingIndicator.tsx
  • mobile/src/session/MobileNativeChatView.test.ts
  • mobile/src/session/MobileNativeChatView.tsx
  • mobile/src/session/mobile-native-chat-view-styles.ts

… path

The row rewrites itself from "Agent is working" to "Agent status stale"
with no live region, so screen-reader users got no cue for the exact
state this change exists to communicate (WCAG 2.1 SC 4.1.3). Matches the
send-error banner's existing pattern in this view.

Also covers the anti-flicker guarantee itself: a link that recovers
inside the 600ms hold must cancel the armed timer, not merely lose the
race with it.
Deleting the prop, or the plausible-looking `stale ? 'polite' : 'none'`,
both left every case green. The contract is that the mode is constant —
Android drops the announcement if it is switched on in the same commit
as the content change — so it has to be asserted in both renders.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Visual + behavioral evidence

Captured by rendering the real MobileAgentWorkingIndicator and the real mobile-native-chat-view-styles chrome row under react-native-web in Chromium, driven with playwright-cli. No simulator was booted — see the note at the bottom.

Both states side by side

chrome-row-both-states.png

Top row (live): Agent is working + three animating dots, Stop at full strength.
Bottom row (stale): Agent status stale, dots gone, Stop dimmed to 0.4.

The stale label is not dimmed — that is deliberate. textMuted on bgBase is 5.62:1; at the 0.55 opacity an earlier revision applied, it fell to 2.52:1, under AA and under even the 3:1 large-text floor, on the one element left carrying the state once the dots go.

Stop is genuinely inert while stale, not just dimmed

stop-disabled-proof.png

One real mouse press on the live row's Stop, then three real press/release cycles on the stale row's Stop:

onStop fired — live row: 1   stale row: 0

The accessibility tree agrees — the stale Stop is not exposed as an interactive target at all:

- generic [ref=e5]:
  - generic: Agent is working
  - generic "Stop the agent" [ref=e13] [cursor=pointer]: Stop   <- live: clickable
- generic [ref=e18]:
  - generic: Agent status stale
  - generic "Stop the agent": Stop                              <- stale: no ref, no pointer

Honest scope of this evidence

  • What is real: the MobileAgentWorkingIndicator component, mobile-native-chat-view-styles, the theme tokens, the Stop Pressable's exact style array and disabled={statusStale} binding, and the resulting rendered pixels and press behavior.
  • What is substituted: the Stop glyph. lucide-react-native pulls the native react-native-svg stack, which does not bundle for web, so the harness draws the same 13px filled statusRed square directly. The dim applies to the whole Pressable, so this does not affect what the screenshots demonstrate.
  • What is not covered: the 600 ms hold and the waiting → disconnected transitions are driven by transport state, so they are covered by the unit tests rather than these captures.
  • Simulator/emulator QA was withheld. Five simulators are currently booted on this machine and none are owned by this session; standing policy here is that no agent boots or attaches to a simulator without an explicit owner designation, because unowned emulators have previously outlived their agents and wedged the machine. TalkBack verification of the new accessibilityLiveRegion announcement is the one item that genuinely needs a device and is therefore not claimed as verified.

Harness was throwaway (built in a scratch dir, never committed); the screenshots are on a side commit and are not part of this PR's diff.

Merge current main, preserve its native-chat streaming changes, and keep Stop action safety aligned across desktop and mobile. Mobile now disables an unreachable Stop immediately while retaining the short visual hold for stale status feedback.\n\nRefs STA-3333.
@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

Senior review follow-up

Found and fixed two scoped issues after integrating current main:

  • Stop availability was delayed with the stale-status label, leaving an unreachable action enabled for the first 600 ms of a disconnect. Stop now disables immediately; only the visible stale label keeps the flicker guard.
  • Desktop and mobile encoded the same Stop-target policy separately. Both now use one framework-neutral shared predicate, with focused integration coverage on each surface.

The sole current-main conflict retained both the new streaming regression case and the stale-status cases. Focused tests passed (16 desktop/shared, 14 mobile), both typechecks passed, and changed-code quality, React Doctor, formatting, oxlint, and max-lines checks are clean. Pushed in 766a473 and 77092a9.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final UI QA on 95edf5950d:

  • Electron/CDP: the live native-chat row shows Agent is working with Stop enabled once the target is writable.
  • iPhone/Orca emulator: after a live session acquired its input lease, stopping only the mock WebSocket produced Agent status stale with no dots; AX reported Stop the agent disabled.

Electron live state

iPhone disconnected state

The final same-model review is CLEAN, including a clean synthetic merge with current main.

…-stale-agent-status

# Conflicts:
#	mobile/src/session/MobileNativeChatView.tsx
#	mobile/src/session/use-mobile-native-chat-controller.ts
@coderabbitai

coderabbitai Bot commented Aug 6, 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

This older disconnected-chat patch can be closed as part of rebuilding phone chat on current main. Preserve the remaining work to show accurate activity and Stop availability when the connection drops.

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