fix(desktop): reduce review tab GitHub polling#2873
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:
📝 WalkthroughWalkthroughCompare fetched vs cached GitHub status ignoring Changes
Sequence Diagram(s)sequenceDiagram
participant UI as Review Tab (UI)
participant Renderer as ChangesView / Hook
participant TRPC as tRPC getGitHubStatus
participant RepoUtil as getRepoContext
participant Store as Worktree Store
UI->>Renderer: tab activate/deactivate or surface visible
Renderer->>TRPC: request GitHub status (policy: enabled/refetch/staleTime)
TRPC->>RepoUtil: getRepoContext(worktreePath) (forceFresh computed from cached state + origin)
RepoUtil-->>TRPC: repoContext / freshStatus
TRPC->>Store: read cached githubStatus
TRPC->>TRPC: remove `lastRefreshed` from both statuses
alt statuses differ
TRPC->>Store: persist fresh githubStatus
else statuses equal
TRPC-->>Store: no write
end
TRPC-->>Renderer: return freshStatus
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx`:
- Around line 293-299: The comments query is being disabled when the Review tab
is inactive which makes reviewCommentCount render stale/zero; keep the query
enabled whenever we have a workspace and an activePullRequest but only gate
polling/focus behavior by isReviewTabActive. Concretely, change the query
options used in the component (symbols: enabled, refetchInterval,
refetchOnWindowFocus, GITHUB_PR_COMMENTS_REFETCH_INTERVAL_MS,
GITHUB_PR_COMMENTS_STALE_TIME_MS, workspaceId, activePullRequest,
isReviewTabActive) so that enabled is !!workspaceId && !!activePullRequest
(remove isReviewTabActive), refetchInterval remains isReviewTabActive &&
activePullRequest ? GITHUB_PR_COMMENTS_REFETCH_INTERVAL_MS : false, and
refetchOnWindowFocus is isReviewTabActive; leave staleTime as
GITHUB_PR_COMMENTS_STALE_TIME_MS.
- Around line 123-130: The getGitHubStatus query is left enabled on the Diffs
tab but configured with no interval or window-focus refetch, causing it to go
stale while ChangesHeader and CommitInput still read from it; update the query
options in ChangesView (the hook that sets
enabled/refetchInterval/refetchOnWindowFocus/staleTime) to either (A) enable a
low-touch off-tab refresh (e.g., set refetchOnWindowFocus: true and a small
refetchInterval when isReviewTabActive is false or reduce staleTime) or (B)
explicitly call the query's refetch when the active tab changes to Review; also
ensure the PR comments query (the query that was disabled off-tab) remains
enabled while the review badge is rendered (or make the badge read from a
separate always-enabled lightweight count query) so the badge count stays fresh
when not on the Review tab.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: aeb834f9-2c8d-4d69-b293-1834f91ee739
📒 Files selected for processing (3)
apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.tsapps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.tsapps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx
There was a problem hiding this comment.
♻️ Duplicate comments (1)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx (1)
123-130:⚠️ Potential issue | 🟠 MajorKeep the Diffs-visible PR metadata on a low-touch refresh path.
ChangesHeader,CommitInput, and the Review tab trigger still rendergithubStatus/githubCommentsoutside the Review tab, but these query options remove the steady-state refresh path there. After the initial fetch, the PR action state, checks icon, and comment badge can drift until the user manually refreshes or re-enters Review. Either keep a cheap off-tab refresh for the data surfaced outside Review, or stop reading these queries from off-tab UI.For TanStack Query v5, if a query stays mounted and enabled but both `refetchInterval` and `refetchOnWindowFocus` are `false`, what automatic refetch triggers remain while the component stays mounted?Also applies to: 293-299
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx` around lines 123 - 130, The githubStatus/githubComments queries are being disabled for steady refresh off the Review tab by setting refetchInterval/refetchOnWindowFocus to false (see refetchInterval/refetchOnWindowFocus/staleTime usage and constants GITHUB_STATUS_REFETCH_INTERVAL_MS, GITHUB_STATUS_STALE_TIME_MS, GITHUB_STATUS_IDLE_STALE_TIME_MS), which lets PR metadata shown in ChangesHeader and CommitInput drift; either re-enable a lightweight off-tab refresh (e.g., set refetchInterval to a low idle interval constant when isReviewTabActive is false) or stop reading those queries in off-tab UI (only mount/use them when isReviewTabActive); update the query options for githubStatus/githubComments accordingly and ensure any staleTime change matches the chosen idle behavior. Note: verify TanStack Query v5 behavior for mounted/enabled queries—without refetchInterval/refetchOnWindowFocus the remaining automatic refetch triggers are manual refetches, query invalidation, or mount/refetchOnMount semantics.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx`:
- Around line 123-130: The githubStatus/githubComments queries are being
disabled for steady refresh off the Review tab by setting
refetchInterval/refetchOnWindowFocus to false (see
refetchInterval/refetchOnWindowFocus/staleTime usage and constants
GITHUB_STATUS_REFETCH_INTERVAL_MS, GITHUB_STATUS_STALE_TIME_MS,
GITHUB_STATUS_IDLE_STALE_TIME_MS), which lets PR metadata shown in ChangesHeader
and CommitInput drift; either re-enable a lightweight off-tab refresh (e.g., set
refetchInterval to a low idle interval constant when isReviewTabActive is false)
or stop reading those queries in off-tab UI (only mount/use them when
isReviewTabActive); update the query options for githubStatus/githubComments
accordingly and ensure any staleTime change matches the chosen idle behavior.
Note: verify TanStack Query v5 behavior for mounted/enabled queries—without
refetchInterval/refetchOnWindowFocus the remaining automatic refetch triggers
are manual refetches, query invalidation, or mount/refetchOnMount semantics.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 967f64f5-91c6-4cd6-9f26-66c01ad7b145
📒 Files selected for processing (1)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx
There was a problem hiding this comment.
2 issues found across 3 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx">
<violation number="1" location="apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx:126">
P2: Non-Review tabs still refetch GitHub status on window focus because focus refetch is keyed to `isActive` and idle staleTime is `0`.</violation>
</file>
<file name="apps/desktop/src/lib/trpc/routers/workspaces/utils/github/repo-context.ts">
<violation number="1" location="apps/desktop/src/lib/trpc/routers/workspaces/utils/github/repo-context.ts:94">
P1: Prevent an infinite cache invalidation loop when `originUrl` is missing or has a different casing than the canonical GitHub URL.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.test.ts (1)
76-111: Add one mixed-format remote case.These assertions only cover already-normalized HTTPS URLs, so a regression in the SSH/
.gitnormalization path would still pass. One case mixinggit@github.com:owner/repo.gitandhttps://github.com/owner/repowould lock down the behavior this helper depends on.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.test.ts` around lines 76 - 111, Add a new test case to shouldRefreshCachedRepoContext that covers mixed-format remotes (SSH vs HTTPS/.git) to ensure normalization works: add a test where originUrl is an SSH form like "git@github.com:owner/repo.git" and cachedRepoContext.repoUrl/upstreamUrl are the HTTPS form "https://github.com/owner/repo" (or vice versa) and assert the function returns false when they are the same repo after normalization and true when they differ; update the test suite in github.test.ts near the other shouldRefreshCachedRepoContext cases to include this mixed-format scenario referencing the shouldRefreshCachedRepoContext helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx`:
- Around line 123-127: The GitHub status query in ChangesView.tsx currently uses
refetchOnWindowFocus: isActive and staleTime: 0 which causes refetches when
switching to Diffs; update the query options in ChangesView (the block setting
refetchInterval / refetchOnWindowFocus / staleTime) to use refetchOnWindowFocus:
isReviewTabActive and make staleTime conditional (e.g. isReviewTabActive ?
GITHUB_STATUS_STALE_TIME_MS : Infinity) so the query does not become immediately
stale when not on the Review tab.
---
Nitpick comments:
In `@apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.test.ts`:
- Around line 76-111: Add a new test case to shouldRefreshCachedRepoContext that
covers mixed-format remotes (SSH vs HTTPS/.git) to ensure normalization works:
add a test where originUrl is an SSH form like "git@github.com:owner/repo.git"
and cachedRepoContext.repoUrl/upstreamUrl are the HTTPS form
"https://github.com/owner/repo" (or vice versa) and assert the function returns
false when they are the same repo after normalization and true when they differ;
update the test suite in github.test.ts near the other
shouldRefreshCachedRepoContext cases to include this mixed-format scenario
referencing the shouldRefreshCachedRepoContext helper.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 72bc144a-48c5-450a-a476-e704c3447fb9
📒 Files selected for processing (3)
apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.test.tsapps/desktop/src/lib/trpc/routers/workspaces/utils/github/repo-context.tsapps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsx
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
apps/desktop/src/renderer/lib/githubQueryPolicy/githubQueryPolicy.test.ts (2)
96-143: PR comments policy tests cover the key scenarios well.The tests validate the important cases (review tab active/inactive, no active PR). For completeness, consider adding tests for:
hasWorkspaceId: false— verifies the query is disabled without a workspaceisActive: false— verifies behavior when the sidebar is not active💡 Suggested additional test cases
+ test("disables comments when the sidebar is inactive", () => { + expect( + getGitHubPRCommentsQueryPolicy({ + hasWorkspaceId: true, + hasActivePullRequest: true, + isActive: false, + isReviewTabActive: true, + }), + ).toEqual({ + enabled: false, + refetchInterval: false, + refetchOnWindowFocus: false, + staleTime: 30_000, + }); + }); + + test("disables comments when no workspace ID is present", () => { + expect( + getGitHubPRCommentsQueryPolicy({ + hasWorkspaceId: false, + hasActivePullRequest: true, + isActive: true, + isReviewTabActive: true, + }), + ).toEqual({ + enabled: false, + refetchInterval: false, + refetchOnWindowFocus: false, + staleTime: 30_000, + }); + });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/desktop/src/renderer/lib/githubQueryPolicy/githubQueryPolicy.test.ts` around lines 96 - 143, Add two unit tests for getGitHubPRCommentsQueryPolicy: one that passes hasWorkspaceId: false (with hasActivePullRequest: true, isActive: true, isReviewTabActive: true) and asserts the returned policy is { enabled: false, refetchInterval: false, refetchOnWindowFocus: false, staleTime: 30_000 }, and another that passes isActive: false (with hasWorkspaceId: true, hasActivePullRequest: true, isReviewTabActive: true) and asserts the same disabled policy; name the tests descriptively (e.g., "disables comments when there is no workspace" and "disables comments when sidebar is inactive") and place them alongside the existing tests for getGitHubPRCommentsQueryPolicy.
7-94: Good coverage of status policy surfaces and states.The tests comprehensively cover the different UI surfaces and their expected polling behaviors. Consider adding a test case for when
hasWorkspaceIdisfalseto verify the query is disabled in that scenario—this would improve edge case coverage.💡 Suggested additional test case
+ test("disables status query when no workspace ID is present", () => { + expect( + getGitHubStatusQueryPolicy("changes-sidebar", { + hasWorkspaceId: false, + isActive: true, + isReviewTabActive: true, + }), + ).toEqual({ + enabled: false, + refetchInterval: false, + refetchOnWindowFocus: false, + staleTime: 10_000, + }); + });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/desktop/src/renderer/lib/githubQueryPolicy/githubQueryPolicy.test.ts` around lines 7 - 94, Add a test to assert getGitHubStatusQueryPolicy returns a disabled policy when hasWorkspaceId is false: call getGitHubStatusQueryPolicy (same signature used in existing tests) for any relevant surface (e.g., "workspace-page" or "changes-sidebar") with hasWorkspaceId: false and appropriate isActive/isReviewTabActive values, and expect enabled: false, refetchInterval: false, refetchOnWindowFocus: false, and the correct staleTime for that surface; place the test alongside the other cases in githubQueryPolicy.test.ts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/desktop/src/renderer/lib/githubQueryPolicy/githubQueryPolicy.ts`:
- Around line 48-58: In the "changes-sidebar" case of the switch over surface,
update the refetchOnWindowFocus setting so it uses the same guard as comments:
change refetchOnWindowFocus from isEnabled to isEnabled && isReviewTabActive;
this ensures that when isReviewTabActive is false (Diffs tab) the query won't
refetch on window focus while staleTime may be 0. Locate the case
"changes-sidebar" block and modify the refetchOnWindowFocus expression
accordingly (the other symbols to reference: isEnabled, isReviewTabActive,
refetchOnWindowFocus, staleTime, and compare to getGitHubPRCommentsQueryPolicy
behavior).
---
Nitpick comments:
In `@apps/desktop/src/renderer/lib/githubQueryPolicy/githubQueryPolicy.test.ts`:
- Around line 96-143: Add two unit tests for getGitHubPRCommentsQueryPolicy: one
that passes hasWorkspaceId: false (with hasActivePullRequest: true, isActive:
true, isReviewTabActive: true) and asserts the returned policy is { enabled:
false, refetchInterval: false, refetchOnWindowFocus: false, staleTime: 30_000 },
and another that passes isActive: false (with hasWorkspaceId: true,
hasActivePullRequest: true, isReviewTabActive: true) and asserts the same
disabled policy; name the tests descriptively (e.g., "disables comments when
there is no workspace" and "disables comments when sidebar is inactive") and
place them alongside the existing tests for getGitHubPRCommentsQueryPolicy.
- Around line 7-94: Add a test to assert getGitHubStatusQueryPolicy returns a
disabled policy when hasWorkspaceId is false: call getGitHubStatusQueryPolicy
(same signature used in existing tests) for any relevant surface (e.g.,
"workspace-page" or "changes-sidebar") with hasWorkspaceId: false and
appropriate isActive/isReviewTabActive values, and expect enabled: false,
refetchInterval: false, refetchOnWindowFocus: false, and the correct staleTime
for that surface; place the test alongside the other cases in
githubQueryPolicy.test.ts.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d15bd9f6-7828-4855-be2c-8f1ce98416f9
📒 Files selected for processing (9)
apps/desktop/src/renderer/lib/githubQueryPolicy/githubQueryPolicy.test.tsapps/desktop/src/renderer/lib/githubQueryPolicy/githubQueryPolicy.tsapps/desktop/src/renderer/lib/githubQueryPolicy/index.tsapps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/page.tsxapps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceListItem.tsxapps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/components/WorkspaceHoverCard/WorkspaceHoverCard.tsxapps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/ChangesView.tsxapps/desktop/src/renderer/screens/main/components/WorkspacesListView/WorkspaceRow/WorkspaceRow.tsxapps/desktop/src/renderer/screens/main/hooks/usePRStatus/usePRStatus.ts
Summary
Testing
Summary by cubic
Scope GitHub PR status and comment polling to the Review tab and prefetch from Changes for faster switches, while restoring passive status behavior elsewhere to cut background traffic. Centralize query policies and avoid redundant repo-context fetches and DB writes.
Bug Fixes
Refactors
renderer/lib/githubQueryPolicyfor status and PR comments; applied across Changes sidebar, workspace page, hover card, list items, rows.usePRStatusaccepts asurfaceoption to tailor behavior; added unit tests for per-surface policies.Written for commit 3c798c5. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
New Features
Performance
Tests