Skip to content

Refresh upstream before git status and tune query polling intervals#67

Merged
juliusmarminge merged 1 commit intomainfrom
codething/92a48535
Feb 18, 2026
Merged

Refresh upstream before git status and tune query polling intervals#67
juliusmarminge merged 1 commit intomainfrom
codething/92a48535

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Feb 18, 2026

Summary

  • Refreshes branch upstream before computing statusDetails so behindCount reflects remote updates.
  • Adds a throttled upstream refresh path for status checks (15s interval, 5s timeout) to avoid fetch spikes during frequent polling.
  • Refactors upstream resolution/fetch logic into reusable helpers used by both status refresh and checkout flows.
  • Adds an integration test covering the stale-remote scenario to verify behindCount updates after a remote commit.
  • Tunes web React Query behavior for git status/branches with explicit stale times and periodic/background refetch settings.

Testing

  • Added integration test: apps/server/src/git.test.ts (refreshes upstream before statusDetails so behind count reflects remote updates).
  • Not run: full project lint script.
  • Not run: full test suite.

Open with Devin

Note

Medium Risk
Introduces additional git fetch calls during status polling (albeit throttled/timeout-limited), which could affect responsiveness or network load and has behavior implications for branch status accuracy.

Overview
GitCoreService.statusDetails() now proactively fetches the current branch’s upstream (with a 15s throttle and 5s timeout) so behindCount reflects remote updates, and refactors upstream parsing/fetching into reusable helpers shared with the checkout background refresh.

Adds an integration test covering the stale-remote behindCount scenario, and tunes the web React Query configuration to use explicit staleTime plus periodic/background refetch intervals for git status (15s) and branches (60s).

Written by Cursor Bugbot for commit 1595909. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

Release Notes

  • Improvements
    • Git status now accurately reflects upstream changes with intelligent refresh mechanisms
    • Enhanced automatic refetch behavior for branch information—refreshes when the app regains focus, reconnects to the network, or on configured intervals
    • Better real-time upstream tracking to keep commit ahead/behind counts current

- Fetch tracked upstream (throttled + timeout) before `statusDetails` so ahead/behind reflects remote updates
- Add integration coverage for behind-count updates after remote commits
- Configure React Query stale/refetch intervals for git status and branch lists
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 18, 2026

Walkthrough

The changes introduce background upstream refresh handling in the Git service to keep status details current. A new test validates that statusDetails correctly reflects remote updates after fetch operations. Query timing configurations are added to optimize client-side synchronization of git status and branches with configurable stale times and refetch intervals.

Changes

Cohort / File(s) Summary
Backend upstream refresh feature
apps/server/src/git.ts, apps/server/src/git.test.ts
Introduces upstream status refresh with throttling via new constants, per-cwd cache timestamps, and helper functions (resolveCurrentUpstream, fetchUpstreamRefForStatus, refreshStatusUpstreamIfStale). statusDetails now triggers background upstream refresh. Existing flows (refreshCheckedOutBranchUpstream, checkoutBranch) updated to use new upstream resolution. New test validates that statusDetails reflects remote updates after fetch.
Frontend query configuration
apps/web/src/lib/gitReactQuery.ts
Adds timing constants for status and branches queries. Extends gitStatusQueryOptions and gitBranchesQueryOptions with staleTime, refetchOnWindowFocus, refetchOnReconnect, and refetchInterval. Introduces new gitQueryKeys.branches key for query identification.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main change: refreshing upstream before git status and tuning query polling intervals, which aligns with all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codething/92a48535

Comment @coderabbitai help to get the list of available commands and usage tips.

@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Feb 18, 2026

Refresh upstream before computing ahead/behind in git.GitCoreService.statusDetails and set 15,000 ms throttle with 5,000 ms fetch timeout, while polling UI queries at 15,000 ms for status and 60,000 ms for branches

Add throttled upstream fetch in git.GitCoreService.statusDetails with helpers for resolving and fetching upstream, introduce 15s/5s constants, and adjust React Query polling intervals for status and branches. Include an integration test validating behindCount after remote updates in git.test.ts.

📍Where to Start

Start with git.GitCoreService.statusDetails and refreshStatusUpstreamIfStale in git.ts.


Macroscope summarized 1595909.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Feb 18, 2026

Greptile Summary

Implements throttled upstream refresh for git status to ensure behindCount reflects remote updates without overwhelming the network.

  • Refactored upstream resolution and fetch logic into reusable resolveCurrentUpstream(), fetchUpstreamRef(), and fetchUpstreamRefForStatus() helpers
  • Added throttled refresh mechanism in statusDetails() that fetches upstream every 15 seconds with a 5-second timeout
  • Aligned client-side React Query refetch intervals (15s for status, 60s for branches) with server-side throttle window
  • Added integration test verifying that stale remote scenarios correctly reflect behindCount after remote commits

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The refactoring extracts logic into well-named helpers, adds proper throttling to prevent network spikes, includes comprehensive integration test coverage for the new behavior, and aligns client/server polling intervals correctly. Error handling appropriately swallows upstream refresh failures to avoid blocking status checks. The implementation follows project priorities of performance and reliability.
  • No files require special attention

Important Files Changed

Filename Overview
apps/server/src/git.ts Refactored upstream resolution/fetch logic into reusable helpers with throttled status refresh mechanism (15s interval, 5s timeout)
apps/server/src/git.test.ts Added integration test verifying that statusDetails refreshes upstream to reflect remote behindCount updates
apps/web/src/lib/gitReactQuery.ts Added explicit stale times and refetch intervals for git status (5s/15s) and branches (15s/60s) queries

Sequence Diagram

sequenceDiagram
    participant Client as React Query (Web)
    participant WS as WebSocket Server
    participant Git as GitCoreService
    participant Remote as Git Remote

    Note over Client: Every 15s refetch interval
    Client->>WS: git.status({ cwd })
    WS->>Git: statusDetails(cwd)
    
    Git->>Git: Check lastUpstreamRefreshAt cache
    alt Cache stale (>15s)
        Git->>Git: Update cache timestamp (prevent spikes)
        Git->>Remote: fetch upstream (5s timeout)
        Note over Git,Remote: fetchUpstreamRefForStatus()
        Remote-->>Git: Updated refs
    else Cache fresh (<15s)
        Note over Git: Skip fetch, use cached upstream
    end
    
    Git->>Git: Parse status --porcelain=2
    Git-->>WS: { behindCount, aheadCount, ... }
    WS-->>Client: Status with fresh behindCount
    
    Note over Client: Alternative: checkout flow
    Client->>WS: git.checkout({ branch })
    WS->>Git: checkoutBranch(input)
    Git->>Git: Perform checkout
    Git->>Remote: refreshCheckedOutBranchUpstream()
    Note over Git,Remote: Background fetch, no throttle
Loading

Last reviewed commit: 1595909

@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Feb 18, 2026

Refresh upstream before computing ahead/behind in git.GitCoreService.statusDetails and set 15,000 ms throttle with 5,000 ms fetch timeout, while polling UI queries at 15,000 ms for status and 60,000 ms for branches

Add throttled upstream fetch in git.GitCoreService.statusDetails with helpers for resolving and fetching upstream, introduce 15s/5s constants, and adjust React Query polling intervals for status and branches. Include an integration test validating behindCount after remote updates in git.test.ts.

📍Where to Start

Start with git.GitCoreService.statusDetails and refreshStatusUpstreamIfStale in git.ts.


Macroscope summarized 1595909.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/server/src/git.ts (1)

221-221: Consider bounded cache to prevent unbounded memory growth.

The lastUpstreamRefreshAt map grows unbounded as users work across different repositories and branches. In a long-running server scenario, this could accumulate stale entries over time.

This is low-priority since the memory overhead per entry is minimal (string key + number value), but worth noting for future consideration.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/server/src/git.ts` at line 221, The Map field lastUpstreamRefreshAt can
grow unbounded; change it to a bounded cache or add pruning: replace the raw
Map<string, number> with a capped LRU/size-limited cache (or wrap it to evict
oldest entries when a max size is exceeded) or implement periodic TTL-based
cleanup that removes entries older than a configured threshold; update usages of
lastUpstreamRefreshAt in this class (look for reads/writes to
lastUpstreamRefreshAt) to use the new cache API so the server won't accumulate
stale repo/branch keys indefinitely.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/server/src/git.ts`:
- Line 221: The Map field lastUpstreamRefreshAt can grow unbounded; change it to
a bounded cache or add pruning: replace the raw Map<string, number> with a
capped LRU/size-limited cache (or wrap it to evict oldest entries when a max
size is exceeded) or implement periodic TTL-based cleanup that removes entries
older than a configured threshold; update usages of lastUpstreamRefreshAt in
this class (look for reads/writes to lastUpstreamRefreshAt) to use the new cache
API so the server won't accumulate stale repo/branch keys indefinitely.

@juliusmarminge juliusmarminge merged commit a1532d5 into main Feb 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant