Skip to content

fix(mobile): stop reporting delivered chat messages as "Message not sent" - #9792

Merged
brennanb2025 merged 4 commits into
mainfrom
fix-mobile-chat-false-not-sent
Jul 22, 2026
Merged

brennanb2025 merged 4 commits into
mainfrom
fix-mobile-chat-false-not-sent

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On the mobile relay (seen on cellular), sending a native-chat message sometimes shows "Message not sent" and leaves the text in the composer — while the message actually reached the desktop and shows up in the transcript after resync. Tapping send again then delivers the message twice.

Root cause

terminal.send is at-most-once with an ambiguous failure mode. In rpc-client.ts, three distinct failures collapsed into one rejection:

  1. The frame never reached the wire (sendEncrypted fails) — definitely not sent
  2. The socket drops with the request in flight (rejectAllPending('Connection interrupted')) — possibly delivered; only the ack may be lost
  3. The response times out — the same ambiguity

The chat send path treated all three as definite failure: error toast + inline banner, draft kept, no acceptSend.

Fix

  • Transport: mark rejections that happen after the request frame was written (in-flight socket drop, explicit client close, or response timeout) as delivery-unknown. The never-written path stays unmarked.
  • Send helper: return accepted | rejected | unknown. The boolean wrapper delegates, so keystroke surfaces (ask answers, permission responses, Escape) keep their existing behavior.
  • Draft reconciliation: hold an ack-lost send instead of erroring. If its matching provider-session transcript echo already arrived before the RPC rejection, clear the draft synchronously and allocate no deadline timer. Otherwise, clear only when a new occurrence lands in the same transcript. Older identical turns, replacement-session turns, and newer composer edits cannot confirm or be erased by the held send.
  • Deadline semantics: after 20 seconds without an echo, keep the draft and report "Delivery unconfirmed — check chat before retrying". Elapsed time does not falsely convert an ambiguous outcome into "Message not sent".

No protocol change — this works against every desktop version and adds no mobile/desktop skew risk.

Reliability contract

  • Invariant (mobile-native-chat.delivery-ambiguity): a request frame written to the relay is never presented as definitely unsent without a host rejection; only a matching echo from the originating provider session may clear its unchanged draft.
  • Failure source: the reported cellular relay path where terminal.send reached desktop but its acknowledgement did not reach mobile.
  • Oracle: deterministic socket-drop, timeout, explicit-close, never-written, echo-before-rejection, echo-after-rejection, repeated-text, pagination-prepend, one-echo-per-send, replacement-session, deadline, edit-preservation, and post-unmount cleanup tests.
  • Gate: accepted manifest gap — config/reliability-gates.jsonc has no client RPC delivery-ambiguity gate yet. The focused mobile tests are the executable gate for this PR; the repository reliability manifest validator remains green.
  • Provider/platform coverage: mobile/relay behavior is covered in the shared TypeScript transport and hook tests. Local, daemon, SSH, WSL, and remote-runtime terminal providers are unaffected because the server protocol, routing, PTY ownership, and provider write paths did not change. iOS and Android share this code; no physical-device cellular run is claimed.
  • Performance budget: the normal transcript path adds only an O(1) empty-held-send check. An outstanding ambiguous send builds one index over the existing capped transcript (maximum 2,000 messages) only on transcript changes and expires after one 20-second timer. An already-landed echo allocates zero timers, asserted with a deterministic timer-count test. No polling, broad session scans, provider fanout, subprocesses, persistence growth, or output-path work was added.
  • Diagnostics: existing [net] close/timeout logs retain request method, pending count, connection state, and reconnect attempt; focused failures distinguish never-written from delivery-unknown outcomes.
  • Residual gaps: no live physical iOS/Android cellular fault-injection artifact. A client-generated message id echoed by the host remains the durable way to prove delivery and make retries idempotent.

Verification

  • Mobile suite: 304 files / 2,187 passed / 2 skipped
  • Focused delivery/draft tests: 25 passed
  • Terminal/mobile RPC reliability slice: 85 passed
  • Mobile TypeScript, oxlint, and format checks: passed
  • Max-lines ratchet and reliability-gate manifest validators: passed

Follow-up (out of scope)

Add a client-generated message id echoed through terminal.send with host-side deduplication (like clientMutationId on worktree.create). That would make retries safe and allow automatic resend, but requires desktop and protocol changes. Keystroke surfaces still treat ack-lost as failure because they have no transcript echo to reconcile against and need that id-based approach.

…ent"

A relay drop or response timeout while terminal.send is in flight rejects
the RPC even though the request usually already reached the desktop — only
the ack was lost. The chat composer treated every failure as definite,
showing "Message not sent" and keeping the draft for a message that is
visibly in the transcript after resync (and baiting a duplicate send).

Mark transport failures that happen after the request frame hit the wire
as delivery-unknown, and hold those sends instead of erroring: when the
transcript echo lands the draft clears silently; only if no echo arrives
within 20s is the failure surfaced. Failures before the frame was written
(and host rejections) still error immediately.
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

RPC delivery errors are classified as unknown when socket interruption or timeout may occur after a request is sent. Native chat sending exposes accepted, rejected, and unknown outcomes while preserving the boolean wrapper. The chat controller holds drafts for unknown sends, and the drafts hook reconciles them against transcript echoes or reports loss after a timeout. Tests cover RPC classification, send outcomes, and draft reconciliation behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is informative but does not follow the required template or include the Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes sections. Reformat the PR description to the repository template and add each required section, including checklist items, screenshots or 'No visual change', AI review, security audit, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the mobile chat change and its user-visible impact.
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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d934c604-6dcf-46f5-b537-23f1d88a3c2f

📥 Commits

Reviewing files that changed from the base of the PR and between 21e26de and 322a1eb.

📒 Files selected for processing (8)
  • mobile/src/session/mobile-native-chat-send.test.ts
  • mobile/src/session/mobile-native-chat-send.ts
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • mobile/src/session/use-mobile-native-chat-drafts.test.ts
  • mobile/src/session/use-mobile-native-chat-drafts.ts
  • mobile/src/transport/rpc-client-delivery-ambiguity.test.ts
  • mobile/src/transport/rpc-client.ts
  • mobile/src/transport/rpc-delivery-ambiguity.ts

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1580bf20-673c-4f2d-8b7d-34127c7ce575

📥 Commits

Reviewing files that changed from the base of the PR and between 322a1eb and 1552c49.

📒 Files selected for processing (5)
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • mobile/src/session/use-mobile-native-chat-drafts.test.ts
  • mobile/src/session/use-mobile-native-chat-drafts.ts
  • mobile/src/transport/rpc-client-delivery-ambiguity.test.ts
  • mobile/src/transport/rpc-client.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • mobile/src/transport/rpc-client.ts
  • mobile/src/session/use-mobile-native-chat-drafts.ts

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
mobile/src/session/use-mobile-native-chat-drafts.ts (1)

188-228: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Unconfirmed duplicate sends can be cleared by the wrong transcript echo. findLandedUnconfirmedSends only tracks held entries, so an earlier accepted send with the same text can satisfy the held path too; in the duplicate-text case that can clear the draft and suppress onUnconfirmed even if this send never landed. Tie echo claiming to a shared message-id claim, or have the held path ignore echoes already attributed to pendingBySession.

🧹 Nitpick comments (1)
mobile/src/session/use-mobile-native-chat-drafts.ts (1)

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

Add a "why" comment for the mountedRef guard.

mountedRef guards holdUnconfirmedSend against ambiguous RPCs that settle after the component unmounts (verified by the "settles after unmount" test), but that rationale isn't captured in a comment near the ref or its usage at L195-197.

+  // Why: an ambiguous RPC can resolve after this hook unmounts (e.g. tab
+  // closed); holdUnconfirmedSend must no-op instead of scheduling a leaked timer.
   const mountedRef = useRef(false)

Based on coding guidelines, "For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works."

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6b7c0fb9-9f08-41d7-99be-74edbe71561a

📥 Commits

Reviewing files that changed from the base of the PR and between 1552c49 and 92af493.

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

@brennanb2025
brennanb2025 merged commit ac909c8 into main Jul 22, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ent" (stablyai#9792)

* fix(mobile): stop reporting delivered chat messages as "Message not sent"

A relay drop or response timeout while terminal.send is in flight rejects
the RPC even though the request usually already reached the desktop — only
the ack was lost. The chat composer treated every failure as definite,
showing "Message not sent" and keeping the draft for a message that is
visibly in the transcript after resync (and baiting a duplicate send).

Mark transport failures that happen after the request frame hit the wire
as delivery-unknown, and hold those sends instead of erroring: when the
transcript echo lands the draft clears silently; only if no echo arrives
within 20s is the failure surfaced. Failures before the frame was written
(and host rejections) still error immediately.

* fix(mobile): close delivery ambiguity races

* fix(mobile): harden ambiguous send reconciliation

* test(mobile): assert ambiguity deadline boundary
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