Repository navigation
perf(native-chat): suspend hidden transcript streams - #13622
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 views now receive renderer visibility and enable retained-session transcript I/O only while visible. The live-session hook retains committed messages while hidden, cancels streams and retries, rejects stale reads and pagination results, and resumes with a fresh source generation. Retry scheduling, stream teardown, and message assembly moved into dedicated helpers. Shared view prop types were added. Tests cover visibility, lifecycle, teardown, retries, transcript changes, and pagination races. 🚥 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: 1
🧹 Nitpick comments (2)
src/renderer/src/components/native-chat/use-native-chat-live-session-visibility.test.ts (2)
322-324: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the subscription limit after a source change.
The test verifies only
readSessionafter the source changes.subscribehas a separatelimitargument. Add an assertion fortransport.subscribe.mock.calls[2]?.[0]?.limitso the test detects a stale paged stream subscription.
341-342: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert that the public status recovers.
The test verifies
readPhaseand messages after the read resolves. It does not verify thatstatusleaves'error'. Add an assertion for the public status so this test detects an error UI that remains after the seeded read succeeds.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ccb200a7-ed6c-4688-87e7-d7fc26606957
📥 Commits
Reviewing files that changed from the base of the PR and between 459689b and c191ed64a3ba6d0b79f7ea8b5d36ba8dc2d31f77.
📒 Files selected for processing (6)
src/renderer/src/components/native-chat/use-native-chat-live-session-visibility.test.tssrc/renderer/src/components/native-chat/use-native-chat-live-session.tssrc/renderer/src/components/native-chat/use-native-chat-retained-session.test.tssrc/renderer/src/components/native-chat/use-native-chat-retained-session.tssrc/shared/native-chat-transcript-retention.test.tssrc/shared/native-chat-transcript-retention.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/components/native-chat/use-native-chat-live-session.ts
| if (messages === session.messages && readPhase === session.readPhase) { | ||
| return session | ||
| } | ||
| return { | ||
| ...session, | ||
| messages, | ||
| readPhase, | ||
| ...(sessionMatchesIdentity ? {} : { status: 'loading' as const, error: undefined }) | ||
| if (!sessionMatchesIdentity) { | ||
| return { ...session, messages, readPhase, status: 'loading', error: undefined } | ||
| } | ||
| // Retained history beats the full-pane error: a reveal-time read/stream failure is usually transient. | ||
| if (session.status === 'error' && messages.length > 0) { | ||
| return { ...session, messages, readPhase, status: 'ready', error: undefined } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Handle retained errors before the identity fast path.
If an error session reuses the captured message array, line 43 returns the original status: 'error' session. The error suppression at line 50 then does not run. Move the error branch before the reference-equality return. Add a test where the error session uses the captured message array.
Proposed fix
- if (messages === session.messages && readPhase === session.readPhase) {
- return session
- }
if (!sessionMatchesIdentity) {
return { ...session, messages, readPhase, status: 'loading', error: undefined }
}
- // Retained history beats the full-pane error: a reveal-time read/stream failure is usually transient.
if (session.status === 'error' && messages.length > 0) {
return { ...session, messages, readPhase, status: 'ready', error: undefined }
}
+ if (messages === session.messages && readPhase === session.readPhase) {
+ return session
+ }📝 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.
| if (messages === session.messages && readPhase === session.readPhase) { | |
| return session | |
| } | |
| return { | |
| ...session, | |
| messages, | |
| readPhase, | |
| ...(sessionMatchesIdentity ? {} : { status: 'loading' as const, error: undefined }) | |
| if (!sessionMatchesIdentity) { | |
| return { ...session, messages, readPhase, status: 'loading', error: undefined } | |
| } | |
| // Retained history beats the full-pane error: a reveal-time read/stream failure is usually transient. | |
| if (session.status === 'error' && messages.length > 0) { | |
| return { ...session, messages, readPhase, status: 'ready', error: undefined } | |
| if (!sessionMatchesIdentity) { | |
| return { ...session, messages, readPhase, status: 'loading', error: undefined } | |
| } | |
| if (session.status === 'error' && messages.length > 0) { | |
| return { ...session, messages, readPhase, status: 'ready', error: undefined } | |
| } | |
| if (messages === session.messages && readPhase === session.readPhase) { | |
| return session | |
| } |
63b1dc5 to
f54ac09
Compare
- An error snapshot frame no longer latches frameArrived, so the in-flight read can still seed the pane instead of leaving it on the error surface. - Retained history is shown over a full-pane read error for the same source. - The paged read window survives a hide/reveal; only a source change resets it. Co-authored-by: Orca <[email protected]>
The shared retention type no longer takes `loading`, so mobile's call was an excess-property error that broke the mobile typecheck job. Dropping it also lets mobile inherit the desktop behavior: a stream error or dropped client keeps the last transcript instead of swapping it for the error empty state. Co-authored-by: Orca <[email protected]>
f54ac09 to
1b0c588
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. |
The stream-gating hook (#13608) and the subscription parking installer (#13621) each reimplemented `isWindowVisible() || isDocumentVisibilityProvenStale()` plus its visibilitychange + stale-recovery subscription, and each carried its own 500ms park delay that agreed only by coincidence. Extract both into `lib/window-park-visibility.ts` and leave the two consumers as thin wrappers: `useWindowStreamVisible` feeds the snapshot and subscribe into `useSyncExternalStore`, the parking installer calls them imperatively. The subscribe now always uses the defensive `typeof document` guard the parking side already had, and registers stale recovery before the visibilitychange listener so the stale latch is cleared before the callback reads it. Both park delays now derive from one `WINDOW_HIDE_PARK_GRACE_MS`: they debounce the same signal against the same user behaviour (a quick app-switch round trip). The parking side's 8x reveal-side backoff stays where it is - that models its own resume cost, not the grace window. Renderer-authoritative gating (#13622 native chat, #13634 editor panels) is deliberately left alone; it keys off Zustand routing state, not OS visibility. Also switch the active-runtime ref writes in web-session-tabs-sync to `useLayoutEffect` so no resume event can land between paint and the passive flush, and correct the stale comment above them - the install effect reads neither ref (both readers are gated on `isVisibilityResume`).
* perf(native-chat): suspend hidden transcript streams * fix(native-chat): keep assembly renders pure * fix(native-chat): keep a transient error from stranding a revealed chat - An error snapshot frame no longer latches frameArrived, so the in-flight read can still seed the pane instead of leaving it on the error surface. - Retained history is shown over a full-pane read error for the same source. - The paged read window survives a hide/reveal; only a source change resets it. Co-authored-by: Orca <[email protected]> * fix(mobile): match the trimmed native-chat retention signature The shared retention type no longer takes `loading`, so mobile's call was an excess-property error that broke the mobile typecheck job. Dropping it also lets mobile inherit the desktop behavior: a stream error or dropped client keeps the last transcript instead of swapping it for the error empty state. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
…yai#13778) The stream-gating hook (stablyai#13608) and the subscription parking installer (stablyai#13621) each reimplemented `isWindowVisible() || isDocumentVisibilityProvenStale()` plus its visibilitychange + stale-recovery subscription, and each carried its own 500ms park delay that agreed only by coincidence. Extract both into `lib/window-park-visibility.ts` and leave the two consumers as thin wrappers: `useWindowStreamVisible` feeds the snapshot and subscribe into `useSyncExternalStore`, the parking installer calls them imperatively. The subscribe now always uses the defensive `typeof document` guard the parking side already had, and registers stale recovery before the visibilitychange listener so the stale latch is cleared before the callback reads it. Both park delays now derive from one `WINDOW_HIDE_PARK_GRACE_MS`: they debounce the same signal against the same user behaviour (a quick app-switch round trip). The parking side's 8x reveal-side backoff stays where it is - that models its own resume cost, not the grace window. Renderer-authoritative gating (stablyai#13622 native chat, stablyai#13634 editor panels) is deliberately left alone; it keys off Zustand routing state, not OS visibility. Also switch the active-runtime ref writes in web-session-tabs-sync to `useLayoutEffect` so no resume event can land between paint and the passive flush, and correct the stale comment above them - the install effect reads neither ref (both readers are gated on `isVisibilityResume`).
Summary
This is a focused performance follow-up to #13525.
ELI5
Each visible chat keeps a live call open to the transcript's host. Hiding the tab used to leave that call—and the host's file watcher and once-a-second safety check—running. Orca now hangs up while keeping the last conversation on screen, then makes one fresh call when the tab returns. Any old callers that finish late are ignored.
Lifecycle
flowchart LR V[Visible Native Chat] --> F[Fresh read + stream] F --> T{Transcript transport} T -->|Local or direct SSH| I[Desktop IPC subscription] T -->|Paired web| W[Paired-runtime child stream] T -->|Runtime-owned desktop| D[Dedicated environment stream] I --> L[Desktop-side watcher or resolve poll] W --> H[Runtime-host watcher or resolve poll] D --> H L --> R[fs.watch + 1 s reconciliation] H --> R Z[Hidden] --> X[Fence late reads, pages, and frames] X --> C[Cancel retry + close stream] C --> Q[Dispose watcher or abort resolve poll] Z --> K[Keep committed transcript and UI state] K -->|Reveal| F F --> A[Fresh authoritative snapshot]Direct SSH uses the desktop-local IPC path, so hiding releases the desktop-side watcher or resolve poll; this does not claim teardown of a watcher on the SSH host.
Quantitative proof
The 1,000-frame result measures transcript-frame-induced hook renders by directly invoking a stale callback; it is not a claim of zero renders or zero store subscriptions for the entire retained Native Chat tree.
Reliability contract
A controlled transport-spy/deferred harness counts reads, subscriptions, unsubscriptions, and Probe renders while resolving old reads, frames, deferred teardown handles, and pagination out of order. The focused regression fails on hidden I/O, a duplicate reveal stream, post-hide retry, stale overwrite, or transcript-frame-induced hidden render.
This is contract-level lifecycle/race coverage across transports, not a live SSH or paired-host end-to-end benchmark. The deterministic lifecycle suite is the focused oracle; no dedicated reliability-manifest entry was added.
Transport and compatibility
Validation
pnpm lintpassed; only pre-existingWorktreeJumpPalette.tsxwarningspnpm build:desktoppassed, including typecheck, relay targets, CLI, Electron/Vite, and web projectionExact-tip AI review at
459689b655bfef18fa21d043dcdb5360992662c9: clean, with no P0/P1/P2 findings.