Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): memoise git top-level lookup in repository identity resolver #3166

Closedleorivastech(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/3166/headopened View on GitHub

What Changed

RepositoryIdentityResolver.resolve ran git rev-parse --show-toplevel on every call. That top-level lookup sat outside the existing identity cache, so it spawned a git subprocess every time, even for the same workspace. This memoises the cwd to top-level mapping in its own cache keyed by cwd, so repeated resolves reuse the result.

Only a resolved top-level is cached (positive TTL). A failed or timed-out lookup is not cached, so the next resolve retries rev-parse and recovers the real root instead of pinning the identity rootPath to a nested path; this keeps the pre-change behaviour for the failure path. Behaviour is otherwise unchanged.

Why

This is the Fix 1 quick win from #2037. replayEvents enriches every project.* event on each reconnect, and that enrichment calls RepositoryIdentityResolver.resolve once per project. With the top-level lookup uncached, a replay burst spawned one git process per project event every time, which is a big part of what pushed replayEvents past the 15s SLOW_RPC_ACK_THRESHOLD_MS and triggered the persistent "Some requests are slow" toast.

#2083 already landed Fix 2 (the negative cache TTL) from the same issue; this takes the next small, self-contained slice. It does not close #2037, which still tracks the remaining proposed fixes.

Regression tests use a counting ProcessRunner: resolving the same workspace twice runs git rev-parse --show-toplevel once instead of twice, and a transient first-call timeout still retries on the next resolve and reports the top-level root.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes
    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: ede62f2c-76e1-4275-9a54-8a6974e0afb5

      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

      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.

      ❤️ Share
      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:unvouched

    3. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).

      Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 2ef76ffd23b78ca30b9f4b3187fcc79f4bfa51b1. Configure [here](https://www.cursor.com/dashboard/bugbot).
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved

      Performance optimization that adds memoization for git subprocess lookups to reduce repeated calls during replay events. Changes are self-contained, well-tested, and don't modify user-facing behavior beyond performance improvement.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. Pushed a follow-up commit (a911c15) that addresses the Cursor Bugbot comment above.

      Failed or timed-out git rev-parse --show-toplevel lookups are no longer cached. Only a resolved top-level gets the positive TTL; otherwise the next resolve re-runs rev-parse and recovers the real root, which keeps the behaviour from before this PR. I also added a regression test that times out the first lookup and asserts the second resolve retries and reports the top-level rootPath instead of the nested path.

    6. Closing this since #2037 has already been resolved in main. Thanks!

Sign in to join this conversation.