Repository navigation
Refresh AI Vault session list on window refocus - #7075
Conversation
Sessions started after the panel mounted never appeared until a manual refresh, since the hook only scanned on mount and scope changes. Listen for window focus and visibilitychange (to visible) while the panel is mounted and trigger a non-force re-scan, letting the main process's 15s scan cache rate-limit rapid focus flips. The manual refresh button keeps its force (cache-bypassing) behavior. Co-authored-by: Orca <help@stably.ai>
Refocus refreshes now run as background: the loading flag stays down (no spinner flash on every alt-tab back), and when the main process replays the cached snapshot (same scope key + scannedAt) the state updates are skipped entirely so nothing re-renders. Fresh scans and the manual force refresh apply results exactly as before. Co-authored-by: Orca <help@stably.ai>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThe AI Vault refresh hook now supports background refresh calls, forced-rescan throttling, and cache short-circuiting for repeated scans in the same scope. A new IPC path sends 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/components/right-sidebar/ai-vault-session-refresh.ts (1)
30-68: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winPrevent stale scoped results from applying after
scopePathschanges.A scope change during an in-flight scan only queues another refresh; it does not invalidate the active
refreshId. The old scan can still callsetScanResult/setSessions, briefly showing sessions for the previous scope before the queued scan finishes.Proposed fix
- const scopeKey = scopePathsRef.current.join('\n') + const requestScopePaths = [...scopePathsRef.current] + const scopeKey = requestScopePaths.join('\n') try { const result = await window.api.aiVault.listSessions({ limit: SESSION_LIMIT, - scopePaths: scopePathsRef.current, + scopePaths: requestScopePaths, force: args.force }) if (!mountedRef.current || refreshIdRef.current !== refreshId) { return } + if (scopePathsRef.current.join('\n') !== scopeKey) { + pendingRefreshRef.current = true + pendingBackgroundRef.current = false + return + } // A cache hit returns the snapshot already on screen; skip the state
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: b2d3a02d-ea9e-4d46-a89b-71cd73e53598
📒 Files selected for processing (2)
src/renderer/src/components/right-sidebar/ai-vault-session-refresh.test.tssrc/renderer/src/components/right-sidebar/ai-vault-session-refresh.ts
Non-force refreshes were served the 15s-old cached snapshot, so a session started right before re-entering the panel or refocusing the window still didn't appear — only the manual force refresh showed it. Panel entry and refocus now request a force scan, throttled in module scope to one forced scan per 5s (surviving panel remounts), so rapid tab/focus flips still resolve from the main-process cache. Manual force refreshes count against the throttle to avoid back-to-back full scans. Co-authored-by: Orca <help@stably.ai>
Renderer DOM focus/visibility events never fire on macOS app activation (verified live: document.hasFocus() stays true and no focus/blur event lands when the window loses/gains OS focus), so the refocus refresh was inert. Main now broadcasts browser-window-focus to the renderer as aiVault:windowFocused and the hook subscribes to that instead. Sessions started inside Orca (window never blurs) get their own trigger from agent hooks: re-scan only when an unseen provider session id appears in agent status. State transitions and message pings on known sessions are deliberately ignored — keying on them made the panel churn on every AI message. Event-driven rescans that land inside the 5s throttle window defer to one trailing scan instead of being dropped. Verified end-to-end against a dev instance: a headless claude session appeared in the panel on OS-level refocus and another on panel re-entry, without the manual refresh button. Co-authored-by: Orca <help@stably.ai>
* Refresh AI Vault session list when the window regains focus Sessions started after the panel mounted never appeared until a manual refresh, since the hook only scanned on mount and scope changes. Listen for window focus and visibilitychange (to visible) while the panel is mounted and trigger a non-force re-scan, letting the main process's 15s scan cache rate-limit rapid focus flips. The manual refresh button keeps its force (cache-bypassing) behavior. Co-authored-by: Orca <help@stably.ai> * Keep AI Vault refocus refresh render-free on cache hits Refocus refreshes now run as background: the loading flag stays down (no spinner flash on every alt-tab back), and when the main process replays the cached snapshot (same scope key + scannedAt) the state updates are skipped entirely so nothing re-renders. Fresh scans and the manual force refresh apply results exactly as before. Co-authored-by: Orca <help@stably.ai> * Bypass AI Vault scan cache on panel entry and refocus, throttled Non-force refreshes were served the 15s-old cached snapshot, so a session started right before re-entering the panel or refocusing the window still didn't appear — only the manual force refresh showed it. Panel entry and refocus now request a force scan, throttled in module scope to one forced scan per 5s (surviving panel remounts), so rapid tab/focus flips still resolve from the main-process cache. Manual force refreshes count against the throttle to avoid back-to-back full scans. Co-authored-by: Orca <help@stably.ai> * Deliver AI Vault refocus via main-process signal; calm in-app triggers Renderer DOM focus/visibility events never fire on macOS app activation (verified live: document.hasFocus() stays true and no focus/blur event lands when the window loses/gains OS focus), so the refocus refresh was inert. Main now broadcasts browser-window-focus to the renderer as aiVault:windowFocused and the hook subscribes to that instead. Sessions started inside Orca (window never blurs) get their own trigger from agent hooks: re-scan only when an unseen provider session id appears in agent status. State transitions and message pings on known sessions are deliberately ignored — keying on them made the panel churn on every AI message. Event-driven rescans that land inside the 5s throttle window defer to one trailing scan instead of being dropped. Verified end-to-end against a dev instance: a headless claude session appeared in the panel on OS-level refocus and another on panel re-entry, without the manual refresh button. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
Summary
Refreshes the AI Vault session list when the application window regains focus or the document becomes visible again. This ensures sessions started while the app was backgrounded are visible when returning.
To keep the experience smooth:
scannedAttimestamp.Screenshots
No visual change
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildAdded unit tests in
ai-vault-session-refresh.test.tsto test window/document listeners, tab visibility change, unmount cleanup, and cache hit state-skipping.AI Review Report
Reviewed focus behavior. Addressed the risk of redundant React renders during rapid window focus toggles by tracking
lastAppliedScanRef(scope paths andscannedAttimestamp) to drop state updates on cache hits. Cleaned up listeners on unmount. Standard browser/DOM APIs are compatible across macOS, Windows, and Linux.Security Audit
No security impact. Simply invokes the existing
window.api.aiVault.listSessionsIPC channel. No inputs are collected, and no shell commands or path operations are performed.Notes
None.