Skip to content
Source
Sign inSign up
pingdotgg/t3code

[codex] Reduce Git status polling churn #3037

Mergedjuliusmarmingemerged 2 commits intomain fromrefs/pull/3037/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Summary

Reduce background Git status disk and process churn by separating remote metadata refreshes from local working-tree inspection.

Problem

The VCS remote status poller ran every 30 seconds and called the full Git status path after fetching. That path executed git status --porcelain=2 --branch plus staged and unstaged git diff --numstat, even though the poller only needed upstream divergence and pull request metadata.

Trace data from the affected environment showed the remote poll repeatedly scanning the working tree. During the reported failure burst:

  • the background fetch hit its 5,003 ms timeout
  • git status took 5,072 ms
  • staged and unstaged numstat scans each took about 7,728 ms
  • unrelated process diagnostics and provider subprocesses also timed out

The failing agent-tools repository itself has one worktree and a roughly 904 KB .git directory, so repository size was not the direct cause. The broader machine does have hundreds of registered worktrees and was under significant child-process pressure. The existing polling behavior amplified that pressure by repeatedly performing unnecessary local scans and by immediately restarting remote refreshes on reconnect.

Changes

  • Add a metadata-only Git remote status operation that:
    • refreshes the upstream when stale
    • reads the current branch and upstream
    • computes ahead/behind commit counts
    • computes divergence from the default branch
    • does not inspect working-tree files or run numstat scans
  • Use the metadata-only operation for GitManager.remoteStatus.
  • Preserve cached remote status across stream reconnects.
  • When a cached remote snapshot exists, wait until the configured interval before starting another automatic refresh instead of refreshing immediately.

Explicit refreshes and initial uncached subscriptions continue to refresh immediately.

Verification

  • vp test apps/server/src/vcs/GitVcsDriverCore.test.ts
  • vp test apps/server/src/vcs/VcsStatusBroadcaster.test.ts
  • vp run typecheck
  • vp check

The two focused backend suites pass with 24 tests.

The complete vp test run produced 372 passing files and 34 unrelated failures. Most failures are existing web test alias-resolution errors for ~/... imports; several orchestration tests also timed out while the machine was experiencing the same process pressure investigated here.

Note

Reduce Git status polling churn by skipping remote refresh when cached snapshot exists

  • Adds statusDetailsRemote to GitVcsDriver (GitVcsDriverCore.ts), a new remote-only status path that reads branch, upstream, ahead/behind, and default-branch counts without inspecting the working tree.
  • GitManager.readRemoteStatus now calls statusDetailsRemote instead of statusDetails, avoiding unnecessary working-tree work during remote polling.
  • VcsStatusBroadcaster.streamStatus delays the first background remote refresh by the configured interval when a cached remote snapshot is already present, rather than always refreshing immediately.
  • Behavioral Change: clients that subscribe to streamStatus while a remote cache entry exists will now wait up to one full polling interval before receiving an updated remote status.
Macroscope summarized 5cac56a.

Note

Medium Risk Changes remote status semantics and polling timing for stream subscribers; behavior is well-tested but affects VCS status freshness on reconnect.

Overview Reduces background Git status churn by splitting remote-only metadata from full local working-tree inspection.

Adds statusDetailsRemote on the Git VCS driver: it still refreshes stale upstreams and computes branch, upstream, ahead/behind, and default-branch divergence via lightweight rev-parse / rev-list calls, without git status --porcelain or staged/unstaged numstat scans. GitManager.readRemoteStatus now uses this path instead of full statusDetails.

VcsStatusBroadcaster defers the first automatic remote poll when a cached remote snapshot already exists: subscribers get the cache immediately and the background loop sleeps one full polling interval before the next refresh. Uncached subscriptions and explicit refreshes still run immediately.

Tests cover remote divergence without working-tree fields, origin-based default-branch detection when upstream is not origin, and delayed refresh timing with TestClock.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5cac56a2e4fbe5d6d064cedc994fcd9120ba221d. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: acf40595-ae08-415c-b738-846039cac2e9

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `codex/investigate-git-disk-churn`

      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      🚀 Expo continuous deployment is ready!

      • Project → t3-code
      • Platforms → android, ios
      • Scheme → t3code-preview
       🤖 Android🍎 iOS
      Fingerprintae17d94b35f91f9c608a63dadbc3ddd9f4ba056e313e506a7f15a9c3f15b01d787d68a12382432bf
      Build DetailsBuild Permalink
      DetailsDistribution: INTERNAL
      Build profile: preview:dev
      Runtime version: ae17d94b35f91f9c608a63dadbc3ddd9f4ba056e
      App version: 0.1.0
      Git commit: e027bdf4df3b402b0484bf28b5decf5b8f916b09
      Build Permalink
      DetailsDistribution: INTERNAL
      Build profile: preview:dev
      Runtime version: 313e506a7f15a9c3f15b01d787d68a12382432bf
      App version: 0.1.0
      Git commit: e027bdf4df3b402b0484bf28b5decf5b8f916b09
      Update DetailsUpdate Permalink
      DetailsBranch: pr-3037
      Runtime version: ae17d94b35f91f9c608a63dadbc3ddd9f4ba056e
      Git commit: e027bdf4df3b402b0484bf28b5decf5b8f916b09
      Update Permalink
      DetailsBranch: pr-3037
      Runtime version: 313e506a7f15a9c3f15b01d787d68a12382432bf
      Git commit: e027bdf4df3b402b0484bf28b5decf5b8f916b09
      Update QR
    4. Cursor Bugbot has reviewed your changes and found 1 potential issue.

      Fix All in Cursor

      Bugbot Autofix prepared a fix for the issue found in the latest run.

      • ✅ Fixed: Default branch detection diverges
        • Changed statusDetailsRemote to always use resolvePrimaryRemoteName (which prefers origin) for default branch detection instead of the upstream tracking remote name, aligning it with the local status path that always uses refs/remotes/origin/HEAD.

      Create PR

      Or push these changes by commenting:

      @cursor push 688d090fc9
      Preview (pingdotgg/t3code@688d090fc9)
      diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts
      --- a/apps/server/src/vcs/GitVcsDriverCore.ts
      +++ b/apps/server/src/vcs/GitVcsDriverCore.ts
      @@ -1212,9 +1212,9 @@
             );
           }
       
      -    const primaryRemoteName =
      -      upstream?.remoteName ??
      -      (yield* resolvePrimaryRemoteName(cwd).pipe(Effect.orElseSucceed(() => null)));
      +    const primaryRemoteName = yield* resolvePrimaryRemoteName(cwd).pipe(
      +      Effect.orElseSucceed(() => null),
      +    );
           const defaultBranch =
             primaryRemoteName === null ? null : yield* resolveDefaultBranchName(cwd, primaryRemoteName);
           const isDefaultBranch =
      You can send follow-ups to the cloud agent here. Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit dd66a438270660b4a953eaa211b66afd477c7ac3. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved

      Performance optimization that introduces a lighter-weight Git status method (skipping working tree computation) and adds refresh delay when cached data exists. The new interface provides all fields used by consumers, and tests cover the new behavior.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. juliusmarminge merged this0baf198

    7. juliusmarminge closed this

Sign in to join this conversation.