Repository navigation
fix(native-chat): surface load-earlier failures and stop retry storms (STA-3333) - #12499
brennanb2025 wants to merge 10 commits into
Conversation
|
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:
📝 WalkthroughWalkthroughNative chat earlier-history loading now uses a shared controller and state model across mobile and renderer sessions. The controller handles concurrency, invalidation, stale results, unsuccessful responses, rejected requests, loading state, and errors. Chat views suppress automatic retries after failure and expose explicit retry controls. Mobile views add accessibility metadata and announcements. Renderer controls add translated loading and retry labels. Tests cover failures, retries, stale requests, transcript replacement, and UI states. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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 |
QA evidence — iOS Simulator + desktop no-regressionVerified at head The bug this fixes: the retry stormBefore, a failed page left the user near the top of the list with no feedback, so every subsequent Measured on the live rig with
One request per explicit user action. The near-top auto-trigger stays suppressed until the error clears. 1. Failure is now visible, with an explicit retry affordance2. Tapping the header retries and recovers (60 older messages prepended, header returns to normal)3. The cycle repeats — a second failure does not wedge the surfaceDesktop no-regression smoke checkThis PR touches only SSH / remote behaviorTraced against
Gates913/913 mobile tests · |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6c434d01-2218-46e4-abb5-e9e234a81d71
📒 Files selected for processing (6)
mobile/src/session/MobileNativeChatOverlay.tsxmobile/src/session/MobileNativeChatView.test.tsmobile/src/session/MobileNativeChatView.tsxmobile/src/session/mobile-native-chat-view-styles.tsmobile/src/session/use-mobile-native-chat-session.test.tsmobile/src/session/use-mobile-native-chat-session.ts
Review — CLEAN at
|
| Mutation | Before | After |
|---|---|---|
Delete requestIsCurrent() on the not-ok/{error} branch |
green (gap) | RED |
Delete requestIsCurrent() in the catch |
RED | RED |
| Invert the ternary so a stale error beats the spinner | green (gap) | RED |
Remove && !loadEarlierError from the near-top gate |
RED | RED |
Hypotheses tested and ruled out
- Orphaned retry (error set while the header stops rendering) — impossible.
hasMoreis only written by the effect reset andreplacement/snapshotframes (both clear the error in the same batch), the success paths (error already null), and thepageLimit <= 0cap — which is unreachable with an error set, sincelimitRefonly advances on success. loadingEarlierRefleaking true — every reset site also bumpsstreamGenerationRef, so a stale request can neither unlock nor write an error.- Failure-path coverage —
ok:false,{error}, and rejection are the only three; the wire contract confirms a success payload never carries anerrorkey, so'error' in resultis a sound discriminant. - SSH/remote — a drop mid-page rejects into the new
catch; reconnect re-sends live subscriptions and the resulting snapshot clears the error, so the sticky state cannot survive a reconnect. A drop before the request lands parks inwaitForConnectedand shows the spinner — identical to pre-fix behavior. - The gate blocking a legitimate page — the error is nulled at the top of every
loadEarlier()and by every authoritative frame, so a success never leaves it latched. - Perf — no new commit is introduced (
loadEarlierErroralways writes alongsidesetLoadingEarlier); theonScrolldep is a rarely-changing boolean, not per-frame cost.
Known gap, accepted (not fixed here)
VoiceOver does not re-announce a focused element's label change, so a blind user who taps the header and hits a failure hears nothing — the accessibilityLabel swap is the only signal. Impact is degraded-but-recoverable (the same tap is the retry), and this PR still improves a11y over main, which had neither accessibilityRole nor accessibilityLabel on this row. A correct cross-platform fix needs AccessibilityInfo.announceForAccessibility, which is more machinery than this scope warrants — flagging rather than smuggling it in.
Gates at 76bba00d81
403 files / 3021 mobile tests pass · tsc clean · oxlint clean · changed-code quality 0 new findings · React Doctor 0 · max-lines ratchet OK · 42/42 CI checks pass (e2e skipped — no changed specs).
A failed older-history page silently did nothing: the near-top scroll trigger kept re-firing the same doomed request, and a rejected transport request escaped as an unhandled rejection. Failures (RPC not-ok, error results, rejections) now set an inline "Couldn't load earlier messages / Tap to retry" header row, and the scroll trigger stands down until the user retries explicitly or an authoritative window supersedes the failed page. Refs STA-3333.
…recedence
Review found two coverage gaps, each proven by mutation:
- The `requestIsCurrent()` guard on the not-ok/`{error}` page path could be
deleted with all 913 tests still green — only the rejection twin was pinned.
The swapped-out-from-under test now runs over both failure shapes.
- `not.toContain('Tap to retry')` was asserted with no `loadEarlierError` set,
so it could not fail. It now renders both props, pinning that an in-flight
retry outranks the failure it is retrying.
Invalidate in-flight pages during full source changes, keep loading accessibility semantics aligned with the spinner, and announce retryable failures to assistive technology.
76bba00 to
3d5eccf
Compare
|
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. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
mobile/src/session/use-mobile-native-chat-session.test.ts (1)
235-314: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert pending and terminal pagination states.
At Line 264, the retry resolves immediately. The test can pass if
loadEarlierErrorclears only after success. Hold the second request pending, then assert that retry clearsloadEarlierErrorwhileloadingEarlieristrue.At Line 291, also assert that
loadingEarlierisfalse. Otherwise, an error-result branch can leave pagination stuck in loading state.Suggested test strengthening
+ let resolveRetry: (response: unknown) => void = () => {} const sendRequest = vi .fn() .mockResolvedValueOnce({ ok: false, error: 'offline' }) - .mockResolvedValueOnce({ - ok: true, - result: { messages: [message('older')], hasMore: false, beforeOffset: 0 } + .mockImplementationOnce( + () => + new Promise((resolve) => { + resolveRetry = resolve + }) + ) + + act(() => state?.loadEarlier()) + expect(state?.loadEarlierError).toBeNull() + expect(state?.loadingEarlier).toBe(true) + + await act(async () => { + resolveRetry({ + ok: true, + result: { messages: [message('older')], hasMore: false, beforeOffset: 0 } }) + await Promise.resolve() + }) expect(state?.messages.map((entry) => entry.id)[0]).toBe('older') expect(state?.loadEarlierError).toBe('Couldn’t load earlier messages') + expect(state?.loadingEarlier).toBe(false)
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 866708f6-1480-4cd0-96b0-a8162c931471
📒 Files selected for processing (6)
mobile/src/session/MobileNativeChatOverlay.tsxmobile/src/session/MobileNativeChatView.test.tsmobile/src/session/MobileNativeChatView.tsxmobile/src/session/mobile-native-chat-view-styles.tsmobile/src/session/use-mobile-native-chat-session.test.tsmobile/src/session/use-mobile-native-chat-session.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- mobile/src/session/mobile-native-chat-view-styles.ts
- mobile/src/session/MobileNativeChatOverlay.tsx
- mobile/src/session/MobileNativeChatView.test.ts
- mobile/src/session/use-mobile-native-chat-session.ts
- mobile/src/session/MobileNativeChatView.tsx
…-load-earlier-errors # Conflicts: # mobile/src/session/use-mobile-native-chat-session.test.ts # mobile/src/session/use-mobile-native-chat-session.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)
tests/e2e/setup-script-prompt-unreadable-orca-yaml.spec.ts (1)
115-125: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winMake worktree path matching platform-aware.
normalizeonly handles one macOS path alias. It does not handle Windows separators or drive-letter casing. The test can fail to findmainWorktreeorfeatureWorktreebefore it exercises the recovery flow.Move the comparison out of
page.evaluate. Use Node path utilities and a runtime check for Windows. Resolve path aliases when required.Source: Coding guidelines
🧹 Nitpick comments (2)
mobile/src/session/use-mobile-native-chat-session.test.ts (1)
383-385: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten the added test comments.
These comments repeat the setup and expected assertions. Keep only the non-obvious invariant in one concise line.
As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through how the code works.”
Also applies to: 407-415, 430-430, 490-490, 520-521, 555-557, 580-581
Source: Coding guidelines
tests/e2e/setup-script-prompt-unreadable-orca-yaml.spec.ts (1)
44-72: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winRestore the fault-injected handler after every test.
installUnreadableOrcaYamlFaultreplaces the process-widehooks:checkhandler.healOrcaYamlReadonly changes the flag. The test has nofinallyblock.If setup or an assertion fails before
healOrcaYamlReadruns at Line [178], later calls can receive the synthetic error. The wrapper also remains installed after a successful test. Return a cleanup function or retain the original handler in main-process test state, then run cleanup infinally. Confirm thatelectronAppis not shared across tests.Also applies to: 166-203
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 871cb52e-845b-4546-b2b9-ba391499aa08
📒 Files selected for processing (6)
mobile/src/session/MobileNativeChatOverlay.tsxmobile/src/session/MobileNativeChatView.tsxmobile/src/session/use-mobile-native-chat-session.test.tsmobile/src/session/use-mobile-native-chat-session.tssrc/main/runtime/orca-runtime.tstests/e2e/setup-script-prompt-unreadable-orca-yaml.spec.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- mobile/src/session/MobileNativeChatOverlay.tsx
- mobile/src/session/use-mobile-native-chat-session.ts
- mobile/src/session/MobileNativeChatView.tsx
Fresh review + QA evidence at 308a7b5Second-pass same-model review returned CLEAN after removing the two unrelated formatting-only files from the PR. The diff now contains exactly the six intended mobile files. iOS Simulator — STA-3333 QA (iOS 26.5)Paired to the repo mock host and exercised the real chat control on the loaded native-chat screen.
Electron no-regression smokeLaunched this worktree with an isolated user-data profile and attached through CDP. Orca rendered normally and the renderer console was empty. Verification
|
…-load-earlier-errors # Conflicts: # mobile/src/session/MobileNativeChatView.tsx
|
Final review at Focused shared/desktop tests (56) and mobile tests (31), both typechecks, changed-code quality/React Doctor, max-lines, the full Node 24/26 matrix, static analysis, Git compatibility, and macOS/Windows packaging all pass. Electron CDP and iOS failure/recovery evidence remain embedded in the PR description. |
|
Closing this old implementation and rebuilding the remaining phone history-loading fix on current main. Failed history loads should offer a retry and should not repeat automatically. |







Summary
Fixes native-chat history paging failures on both desktop and mobile without duplicating the behavior between clients.
The change remains scoped to load-earlier behavior; reconnect-history merging and broader viewport work are separate concerns.
Screenshots
Verification
Scope and compatibility
No dependencies, RPC methods, Git commands, shell behavior, or provider-specific behavior were added. The shared controller is transport-agnostic; desktop and mobile continue to use their existing local, remote, SSH, and folder-workspace transports.
Refs STA-3333.