fix(server): memoise git top-level lookup in repository identity resolver#3166
fix(server): memoise git top-level lookup in repository identity resolver#3166leorivastech wants to merge 2 commits into
Conversation
…lver resolve() ran `git rev-parse --show-toplevel` on every call, outside the existing identity cache, so it spawned a git subprocess each time even for the same workspace. During replayEvents enrichment that means one git process per project event on every reconnect, a big contributor to the "Some requests are slow" toast. Memoise the cwd -> top-level mapping in its own cache. A resolved top-level uses the positive TTL; an unresolved cwd (not a repo / git timed out) uses the negative TTL so a directory that later becomes a repo is still picked up. Adds a regression test counting process invocations. Part of pingdotgg#2037.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ 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.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
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 for commit 2ef76ff. Configure here.
ApprovabilityVerdict: 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. |
A failed or timed-out `git rev-parse --show-toplevel` previously cached the cwd fallback for the negative TTL. Because `git remote -v` still resolves from a nested workspace, that pinned the repository identity rootPath to the nested directory until the entry expired. Cache only resolved top-levels and retry on the next resolve otherwise, matching the pre-cache behaviour.
|
Pushed a follow-up commit (a911c15) that addresses the Cursor Bugbot comment above. Failed or timed-out |

What Changed
RepositoryIdentityResolver.resolverangit rev-parse --show-toplevelon 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.
replayEventsenriches everyproject.*event on each reconnect, and that enrichment callsRepositoryIdentityResolver.resolveonce 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 pushedreplayEventspast the 15sSLOW_RPC_ACK_THRESHOLD_MSand 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 runsgit rev-parse --show-toplevelonce instead of twice, and a transient first-call timeout still retries on the next resolve and reports the top-level root.Checklist