Repository navigation
fix(mobile): native chat QA sweep — reconnect history, stale status, prompt-card and paging fixes (STA-3333) - #12373
brennanb2025 wants to merge 11 commits into
Conversation
…prompt-card and paging fixes (STA-3333) Fixes the confirmed defect list from the STA-3333 QA sweep: - reconnect replay snapshots merge into paged-in history instead of truncating to the initial window; disjoint replays replace it - manual-retry client swaps keep rendering the cached transcript while the fresh read is in flight - agent-working row mutes and Stop disables while disconnected - ask-card dismissal lifted to the controller so it survives view toggles; ask prompts gated on waiting/blocked like permission - loadEarlier failures surface an inline tap-to-retry row; FlatList anchors the viewport across prepends - answer-send abort paths report partly-sent instead of ending silent - per-terminal write lock shared across composer/answer/permission/ question sends so PTY writes cannot interleave - streaming bubble no longer swallows a genuine repeated-prefix reply - tool rows label with the file path / primary arg instead of raw JSON
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe mobile native chat now preserves compatible replay history, replaces incompatible windows, and reports retryable earlier-message failures. Streaming bubbles use scoped gating. Ask prompts use agent status and scoped dismissal state. Terminal writes share per-terminal serialization across message, permission, answer, and image sends. The UI marks disconnected status as stale, disables Stop, adds pagination retry states, and improves tool input previews. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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: 3
🧹 Nitpick comments (1)
src/shared/native-chat-tool-summary.ts (1)
19-21: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten or remove the new explanatory comments.
src/shared/native-chat-tool-summary.ts#L19-L21: Replace the implementation summary with one concise non-obvious rationale, or remove it.mobile/src/session/MobileNativeChatMessage.tsx#L92-L98: Remove comments that restate the adjacent preview and diff logic.mobile/src/session/MobileNativeChatMessage.tsx#L137-L138: Remove the comment that restates the conditional render.As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3d3ac546-0fa3-4ea9-8fa7-e1107faa47ce
📒 Files selected for processing (32)
mobile/src/session/MobileAgentWorkingIndicator.tsxmobile/src/session/MobileNativeChatLoadEarlierHeader.tsxmobile/src/session/MobileNativeChatMessage.tsxmobile/src/session/MobileNativeChatOverlay.tsxmobile/src/session/MobileNativeChatView.test.tsmobile/src/session/MobileNativeChatView.tsxmobile/src/session/mobile-native-chat-permission-send.test.tsmobile/src/session/mobile-native-chat-permission-send.tsmobile/src/session/mobile-native-chat-render-data.tsmobile/src/session/mobile-native-chat-stream-frame.test.tsmobile/src/session/mobile-native-chat-stream-frame.tsmobile/src/session/mobile-native-chat-streaming-gate.test.tsmobile/src/session/mobile-native-chat-streaming-gate.tsmobile/src/session/mobile-native-chat-terminal-write-lock.tsmobile/src/session/mobile-native-chat-tool-summary.tsmobile/src/session/mobile-native-chat-view-styles.tsmobile/src/session/use-mobile-native-chat-answer-send.test.tsmobile/src/session/use-mobile-native-chat-answer-send.tsmobile/src/session/use-mobile-native-chat-ask-dismiss.test.tsmobile/src/session/use-mobile-native-chat-ask-dismiss.tsmobile/src/session/use-mobile-native-chat-controller.tsmobile/src/session/use-mobile-native-chat-image-attachments.test.tsmobile/src/session/use-mobile-native-chat-image-attachments.tsmobile/src/session/use-mobile-native-chat-message-send.test.tsmobile/src/session/use-mobile-native-chat-message-send.tsmobile/src/session/use-mobile-native-chat-prompts.test.tsmobile/src/session/use-mobile-native-chat-prompts.tsmobile/src/session/use-mobile-native-chat-session.test.tsmobile/src/session/use-mobile-native-chat-session.tsmobile/src/session/use-mobile-native-chat-streaming-bubble.tssrc/shared/native-chat-tool-summary.test.tssrc/shared/native-chat-tool-summary.ts
| const requestIsCurrent = (): boolean => | ||
| sessionIdRef.current === requestSessionId && streamGenerationRef.current === requestGeneration |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Validate the complete request identity before applying an older page.
requestIsCurrent checks only sessionId and streamGenerationRef. A host, workspace, client, agent, or transcript-path change can retain the same session ID. If the old request resolves before the passive effect increments streamGenerationRef, it can call setList with messages from the previous source.
Capture the request identity and client. Compare them with refs updated during render before mutating session state. Add a deferred-page test that changes sourceIdentity with the same session ID.
| const primary = | ||
| value.command ?? value.cmd ?? value.query ?? value.pattern ?? value.description ?? value.url | ||
| if (typeof primary === 'string' && primary.trim()) { | ||
| return summarizeToolInput(primary) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Select the first non-empty primary field.
An empty command prevents later valid fields from being selected. For example, { command: '', query: 'foo' } falls back to JSON instead of showing foo.
Proposed fix
- const primary =
- value.command ?? value.cmd ?? value.query ?? value.pattern ?? value.description ?? value.url
- if (typeof primary === 'string' && primary.trim()) {
+ const primary = [
+ value.command,
+ value.cmd,
+ value.query,
+ value.pattern,
+ value.description,
+ value.url
+ ].find((candidate): candidate is string => typeof candidate === 'string' && candidate.trim())
+ if (primary) {
return summarizeToolInput(primary)
}Add a regression test with an empty earlier field and a non-empty later field.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const primary = | |
| value.command ?? value.cmd ?? value.query ?? value.pattern ?? value.description ?? value.url | |
| if (typeof primary === 'string' && primary.trim()) { | |
| return summarizeToolInput(primary) | |
| const primary = [ | |
| value.command, | |
| value.cmd, | |
| value.query, | |
| value.pattern, | |
| value.description, | |
| value.url | |
| ].find((candidate): candidate is string => typeof candidate === 'string' && candidate.trim()) | |
| if (primary) { | |
| return summarizeToolInput(primary) |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
mobile/src/session/use-mobile-native-chat-session.test.ts (1)
226-248: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winMake the history assertion independent and content-sensitive.
toHaveLength(100)does not verify that the 60paged-*messages were retained or ordered correctly. The samewindowarray is also passed into the session and reused as the expected value. If the implementation mutates an input array, the final assertion can pass incorrectly. Store the paged fixture separately, pass copies to both snapshots, and assert the exact merged sequence.Suggested test hardening
+ const pagedMessages = Array.from({ length: 60 }, (_unused, index) => message(`paged-${index}`)) const sendRequest = vi.fn().mockResolvedValue({ ok: true, result: { - messages: Array.from({ length: 60 }, (_unused, index) => message(`paged-${index}`)), + messages: [...pagedMessages], hasMore: false, beforeOffset: 40 } }) ... - onData({ type: 'snapshot', messages: window, hasMore: true, beforeOffset: 100 }) + onData({ type: 'snapshot', messages: [...window], hasMore: true, beforeOffset: 100 }) ... - expect(state?.messages).toHaveLength(100) + expect(state?.messages).toEqual([...pagedMessages, ...window]) ... - emit({ type: 'snapshot', messages: window, hasMore: false, beforeOffset: 0 }) + emit({ type: 'snapshot', messages: [...window], hasMore: false, beforeOffset: 0 })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9d56bcb7-a309-41f6-97f4-0fbb6b175abb
📒 Files selected for processing (5)
mobile/src/session/mobile-native-chat-stream-frame.test.tsmobile/src/session/mobile-native-chat-stream-frame.tsmobile/src/session/use-mobile-native-chat-ask-dismiss.test.tsmobile/src/session/use-mobile-native-chat-ask-dismiss.tsmobile/src/session/use-mobile-native-chat-session.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- mobile/src/session/mobile-native-chat-stream-frame.test.ts
- mobile/src/session/mobile-native-chat-stream-frame.ts
- mobile/src/session/use-mobile-native-chat-ask-dismiss.ts
- mobile/src/session/use-mobile-native-chat-ask-dismiss.test.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
mobile/src/session/MobileNativeChatView.test.ts (1)
169-192: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winExercise the rendered retry row.
The test calls
ListHeaderComponent.props.onLoadEarlier()directly. It does not verify the error branch or thePressableonPresspath inMobileNativeChatLoadEarlierHeader. Assert the rendered error and retry text, invoke the rendered press handler, and then assertonLoadEarlierwas called.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 270acf08-d39b-4ab9-b69b-2aba58d88de9
📒 Files selected for processing (2)
mobile/src/session/MobileNativeChatView.test.tsmobile/src/session/MobileNativeChatView.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- mobile/src/session/MobileNativeChatView.tsx
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6099bccb-ac76-4edb-b17a-f719f751b5d9
📒 Files selected for processing (8)
mobile/src/session/MobileNativeChatView.test.tsmobile/src/session/MobileNativeChatView.tsxmobile/src/session/use-mobile-native-chat-answer-send.test.tsmobile/src/session/use-mobile-native-chat-answer-send.tsmobile/src/session/use-mobile-native-chat-session.test.tsmobile/src/session/use-mobile-native-chat-session.tssrc/shared/native-chat-tool-summary.test.tssrc/shared/native-chat-tool-summary.ts
🚧 Files skipped from review as they are similar to previous changes (6)
- src/shared/native-chat-tool-summary.test.ts
- mobile/src/session/use-mobile-native-chat-session.test.ts
- mobile/src/session/use-mobile-native-chat-answer-send.test.ts
- mobile/src/session/MobileNativeChatView.tsx
- mobile/src/session/use-mobile-native-chat-answer-send.ts
- mobile/src/session/use-mobile-native-chat-session.ts
Final UI QA evidence —
|
|
This omnibus PR has been split into one independent main-based PR per fix:
Each replacement PR is open and unmerged against main, has a clean independent child worktree, matches its pushed head, has green CI, and includes its review/QA evidence without committing screenshots to the diff. Each also completed the requested fresh Opus review loop through a substantive CLEAN pass; meaningful findings were fixed and re-reviewed. Closing #12373 as superseded. Please review and merge the focused replacements independently. |



Summary
Fixes the confirmed defect list from the STA-3333 mobile native chat QA sweep (live QA + code-audit findings on the ticket):
nativeChat.subscribewith its original params after an in-place reconnect, and the session hook treated everysnapshotas replace-list. The hook now honors the snapshot-vs-replay distinction: a replay snapshot that overlaps retained history merges in by id (paged-in history survives the blip); a disjoint replay (long outage / compaction while away) falls back to replacing with the fresh authoritative window, since stitching would leave a silent gap.forceReconnectswaps to a new client identity; the hook now holds the last settled list for the same agent/session identity and keeps rendering it while the swapped client's read is in flight, instead of collapsing to a full-screen spinner.transcriptLoadingstill gates consumers (launch-draft seed) until the fresh read settles.maintainVisibleContentPositionso a successful loadEarlier grows the list upward under a stable viewport.{"file_path":…}JSON; the expanded detail shows the fully formatted input (desktop parity).MobileNativeChatView.tsxcrossed the 400-line cap with these changes, so the load-earlier header and the streaming-bubble wiring were extracted intoMobileNativeChatLoadEarlierHeader.tsxanduse-mobile-native-chat-streaming-bubble.ts(nomax-linesdisables).Coordination: written to compose with #12364 (STA-3331) and #12366 (STA-3332), which touch
MobileNativeChatView.tsx,MobileNativeChatOverlay.tsx, and the controller and are expected to merge first. Their fixes (keyboardShouldPersistTaps, send classification, open-file flow) are not duplicated here. One small textual conflict is possible in the FlatList prop block ofMobileNativeChatView.tsxagainst #12364 (adjacent added props); my side is a singlemaintainVisibleContentPositionline plus comment.Refs STA-3333.
Screenshots
No visual change beyond the states described above (muted status row, error/retry header row, tool-row labels); not run on a simulator — see Notes.
Testing
pnpm lint(oxlint root + mobile, code-quality native/type-aware audits, max-lines ratchet, react-doctor changed-lines gate — all clean)pnpm typecheck(root three-project tsc + mobile tsc)pnpm test(mobile suite: 391 files, 2913 passed / 3 skipped; affected shared desktop tests pass)pnpm build(not run — no build-affecting changes; CI covers it)describeToolInputlabels.AI Review Report
Self-reviewed with focus on: (1) reconnect-replay window semantics — verified the disjoint-replay fallback preserves the existing "authoritative snapshot resets a maxed-out window" behavior via the pre-existing tests; (2) write-lock deadlock/leak risks — a superseding answer inherits the hold via a per-hook refcount, only the last chain out releases, and Stop/cancel deliberately bypass the lock so interrupts can't deadlock; a hung holder is bounded by the send budget; (3) render purity — the streaming gate advances via the sanctioned render-time state-adjustment pattern (idempotent, settles in one pass) and the transcript cache is captured post-commit in an effect, both verified against the react-doctor changed-lines gate; (4) stale-list safety — the held list is keyed by the full agent/session/transcript identity, so it can never serve another tab's messages (locked by test). Cross-platform: no keyboard shortcuts, path handling, or shell behavior touched; changes are React Native UI/transport logic identical across iOS/Android clients and agnostic of the desktop host OS (native/WSL/SSH); the shared tool-summary change is pure string formatting with Windows-path-safe helpers already in place.
Security Audit
No new input parsing from untrusted sources, no command execution, no auth or secret handling. The write-lock module holds only terminal handles in memory.
describeToolInputrenders agent-provided strings through the existing bounded-preview truncation (length caps, depth caps, circular-safe) — no new injection surface since output is plainText. The loadEarlier error string is a fixed literal, not server-echoed content. IPC/RPC surface unchanged (no new methods; the fix reuses existing subscribe/read RPCs).Notes
blockedgate on ask prompts means hosts that never publish agent status will not surface ask cards — this matches the pre-existing behavior of the permission and question cards.