Repository navigation
fix(mobile): stop reporting delivered chat messages as "Message not sent" - #9792
Conversation
…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.
📝 WalkthroughWalkthroughRPC 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)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d934c604-6dcf-46f5-b537-23f1d88a3c2f
📒 Files selected for processing (8)
mobile/src/session/mobile-native-chat-send.test.tsmobile/src/session/mobile-native-chat-send.tsmobile/src/session/use-mobile-native-chat-controller.tsmobile/src/session/use-mobile-native-chat-drafts.test.tsmobile/src/session/use-mobile-native-chat-drafts.tsmobile/src/transport/rpc-client-delivery-ambiguity.test.tsmobile/src/transport/rpc-client.tsmobile/src/transport/rpc-delivery-ambiguity.ts
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 1580bf20-673c-4f2d-8b7d-34127c7ce575
📒 Files selected for processing (5)
mobile/src/session/use-mobile-native-chat-controller.tsmobile/src/session/use-mobile-native-chat-drafts.test.tsmobile/src/session/use-mobile-native-chat-drafts.tsmobile/src/transport/rpc-client-delivery-ambiguity.test.tsmobile/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
There was a problem hiding this comment.
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 liftUnconfirmed duplicate sends can be cleared by the wrong transcript echo.
findLandedUnconfirmedSendsonly 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 suppressonUnconfirmedeven if this send never landed. Tie echo claiming to a shared message-id claim, or have the held path ignore echoes already attributed topendingBySession.
🧹 Nitpick comments (1)
mobile/src/session/use-mobile-native-chat-drafts.ts (1)
119-123: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a "why" comment for the
mountedRefguard.
mountedRefguardsholdUnconfirmedSendagainst 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
📒 Files selected for processing (2)
mobile/src/session/use-mobile-native-chat-drafts.test.tsmobile/src/session/use-mobile-native-chat-drafts.ts
…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
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.sendis at-most-once with an ambiguous failure mode. Inrpc-client.ts, three distinct failures collapsed into one rejection:sendEncryptedfails) — definitely not sentrejectAllPending('Connection interrupted')) — possibly delivered; only the ack may be lostThe chat send path treated all three as definite failure: error toast + inline banner, draft kept, no
acceptSend.Fix
accepted | rejected | unknown. The boolean wrapper delegates, so keystroke surfaces (ask answers, permission responses, Escape) keep their existing behavior.No protocol change — this works against every desktop version and adds no mobile/desktop skew risk.
Reliability contract
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.terminal.sendreached desktop but its acknowledgement did not reach mobile.config/reliability-gates.jsonchas 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.[net]close/timeout logs retain request method, pending count, connection state, and reconnect attempt; focused failures distinguish never-written from delivery-unknown outcomes.Verification
Follow-up (out of scope)
Add a client-generated message id echoed through
terminal.sendwith host-side deduplication (likeclientMutationIdonworktree.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.