Skip to content

fix(mobile): report a partly-sent ask answer honestly (STA-3333) - #12503

Closed
brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/sta-3333-partial-answer
Closed

brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/sta-3333-partial-answer

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

Split from #12373 (fix 7 of that PR's list) — this PR is independent and targets main; #12373 stays open and untouched.

A mobile ask-answer send for Claude/Codex is a paced sequence of keystroke groups, not one write. If the chain was aborted mid-sequence — chat session swap, acknowledged input lease loss, Stop, or a superseding answer — it returned silently, even when earlier groups had already been accepted by the host. The user saw the card end cleanly, while the remote selector actually sat half-stepped on a later question. Retrying then replayed a from-scratch key plan onto an advanced position and answered the wrong question.

Three abort paths bypassed the existing fail() reporter (return false instead of return fail()), and fail() itself only spoke while the chain was still the current generation — which an abort has by definition already invalidated. So the one case that most needed a warning was the one guaranteed to stay quiet.

Now:

  • The abort paths route through fail().
  • fail() speaks when the chain wrote something, not only when it is still current: an accepted group reports Answer partly sent — check chat before retrying, an ambiguous one Answer unconfirmed — check chat before retrying.
  • A chain that never got a keystroke onto the wire still stays silent, so an answer the user deliberately replaced does not raise a banner.
  • wait() returns immediately when the chain is already superseded, so the report is not delayed by a full pacing step.

The wording and the accepted/unknown precedence are the ones already used by this hook's budget-exhaustion path and by the Stop sender, so no new user-facing vocabulary is introduced.

Deliberately not in this PR: the shared PTY write lock / send serialization (fix 8 of #12373). That is a separate concern and is being split separately — this change only identifies and reports a partial send.

Screenshots

No visual change — the existing composer send-error banner is reused verbatim; only the conditions under which it is raised changed.

Testing

  • pnpm lint — root oxlint and mobile oxlint clean on the changed files; audit:code-quality:native clean; check:max-lines-ratchet OK (352 grandfathered, no new bypasses); lint:react-doctor:changed clean. No max-lines disable added or bumped (source file is 248 lines against a 300 cap).
  • pnpm typecheck — mobile tsc --noEmit clean.
  • pnpm test — full mobile src/session suite: 114 files, 908 passed. Focused file: 21 passed.
  • pnpm build — not run; no build-affecting change (pure hook logic, no new module, no dependency change). CI covers it.
  • Added or updated high-quality tests that would catch regressions

Tests added to use-mobile-native-chat-answer-send.test.ts, one per abort trigger plus a negative guard:

  • input-lease loss mid-answer (extends the existing test, which previously asserted only the cancellation) → partly sent
  • Stop mid-answer after a group landed → partly sent
  • superseding answer after the first group moved the selector → partly sent
  • abort after an ambiguous in-flight write → unconfirmed (not downgraded to a definite failure)
  • abort with nothing on the wire → silent (guards against over-reporting)

Each of the four positive tests was confirmed to fail against the unmodified source and pass with it, so none is vacuous. The negative test passes both ways by design — it exists to pin the no-false-banner boundary.

AI Review Report

Reviewed with focus on:

  1. Over-reporting. The new condition is generation === generation || sawAcceptedGroup || sawUnknownOutcome, so an aborted chain that wrote nothing is still silent. Locked by the negative test. This matters because a deliberate answer change is a common, non-error interaction.
  2. Wrong-tab / stale-scope banners. An aborted chain reports after the session may have swapped. Verified against use-mobile-native-chat-send-error.ts: show() compares the scope the callback was built for against the live scope and falls back to a toast when they differ or the banner is unmounted, so a late report cannot paint or wipe another tab's banner. This pre-existing guard is exactly what makes reporting from an aborted chain safe; no change was needed there.
  3. Double-banner on supersede. The superseded chain raises the banner, then a successful replacement calls onSendResolved via useNativeChatAcceptedAction and retires it — the end state matches today's behavior, with the warning visible only if the replacement also fails or is slow.
  4. Message precedence. accepted outranks unknown: a definitely-half-stepped selector is the more actionable warning, and an ambiguous write is never presented as a definite failure (double-send hazard).
  5. Return value. answerAsk still resolves false on every abort, so the accepted-action wrapper does not retire the banner just raised. No caller contract changed.
  6. Cross-platform. Explicitly checked: no keyboard shortcuts, accelerators, shortcut labels, file paths, or shell invocation are touched. This is React Native client logic, identical on iOS and Android, and agnostic of the desktop host OS — it behaves the same for native, WSL, and SSH-hosted panes and for both git-worktree and folder workspaces, since it only interprets the outcome of an existing terminal.send RPC. No Electron-specific surface involved.

Security Audit

No new input parsing, command execution, path handling, auth, or secret handling. No IPC/RPC surface change — the same terminal.send request is made under the same conditions; only the client-side interpretation of an already-received outcome changed. The two new banner strings are fixed literals, never server-echoed content, so there is no injection or data-leak path. No dependency changes. Byte-for-byte, this PR writes nothing to the PTY that it did not write before — it only stops staying quiet about what it already wrote. No follow-up needed.

Notes

An ask-answer chain that was aborted mid-sequence (session swap, input
lease loss, Stop, a superseding answer) returned silently even when
earlier keystroke groups had already been accepted by the host. The card
was left looking cleanly sent while the remote selector sat half-stepped,
so a retry replayed a from-scratch key plan onto an advanced position.

Route the abort paths through the existing fail() reporter and let it
speak when the chain wrote something, not only when it is still the
current generation: an accepted group reports "Answer partly sent", an
ambiguous one "Answer unconfirmed". A chain that never got a keystroke
onto the wire stays silent, so a superseded answer the user replaced on
purpose does not raise a banner.

Refs STA-3333.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

Next review available in: 31 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: 3440bc60-60e1-419a-b46b-aa84e9c4f4b3

📥 Commits

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

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

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

QA evidence — live A/B on iOS Simulator + Electron smoke

Scope check first: the effective diff vs main is exactly two files —
mobile/src/session/use-mobile-native-chat-answer-send.ts and its test. No PTY write-lock,
no ask-dismissal, no desktop/shared changes (git diff --name-only origin/main...HEAD -- src/ is empty).

The behavioral delta this PR actually fixes

A mid-sequence send rejection already reported "Answer partly sent" on main. The real gap is the
aborted / superseded chain — session swap, lease loss, Stop, or a newer answer — where the generation
bumps after a keystroke group has already landed on the PTY. On main that path returns silently.

Repro used for both runs: a 2-question AskUserQuestion selector (3 keystroke groups, paced 1000 ms apart).
The first group is accepted on the wire, then the connection is torn down 350 ms later — safely inside the
pacing window, so exactly one group has landed when the chain is cancelled.

Branch (fixed) origin/main (bug)
12503-abort-2.png 12503-ab-shot-2.png
Red banner: "Answer partly sent — check chat before retrying" No banner. Card reads as cleanly sent — both question tabs check-marked, 2/2.

Same scenario, same single accepted group, same disconnect. On main all six captured frames spanning
~0.8 s → 4.8 s are byte-identical (md5 fdf4a4f8fc02d8958cd79b49d9d4d890), i.e. no transient message was
missed — nothing is ever shown. On the branch the banner appears and then retires on schedule at the 4000 ms
hold (md5s: pre-banner 6966e38…, banner b5ad8b6f…, retired 18094eb8…), so the report is
self-clearing rather than sticky.

Live Ask card driving the repro:

12503-qa-11.png

Electron smoke

12503-electron-02.png

Desktop app on this branch: workspace opens, live terminal, file tree, 0 / 0 diagnostics.
0 console errors (4 warnings, all pre-existing: React DevTools notice, React Grab version, Radix tooltip
controlled/uncontrolled, xterm task-queue deadline). Consistent with the desktop tree being untouched.

Verification

  • mobile tsc --noEmit — exit 0
  • oxlint — exit 0 · oxfmt --check — clean · no max-lines disable added
  • full mobile suite — 403 files, 3015 passed, 3 skipped
  • Test non-vacuity proven by mutation: reverting the production file makes exactly 4 of the 5 new tests fail.
    The 5th (nothing-on-wire → stays silent) is a boundary guard that passes both ways by design — it pins the
    no-false-positive edge, not the new behavior.

Method note: mobile QA used the sanctioned simulator path (xcrun simctl + orca emulator attach/tap);
Electron QA used playwright-cli over CDP. No Computer Use, AppleScript, or OS-level input injection.

@OrcaWin

OrcaWin commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Moving this PR to draft because it has been untouched for more than 80 days (latest recorded PR activity or commit timestamp: 2026-08-04T09:59:20Z; checked on 2026-10-27). This keeps the review queue focused on active work while preserving the proposal. Please mark it ready for review when work resumes.

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.

2 participants