Skip to content

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

Open
leorivastech wants to merge 2 commits into
pingdotgg:mainfrom
leorivastech:fix/repository-identity-toplevel-cache
Open

fix(server): memoise git top-level lookup in repository identity resolver#3166
leorivastech wants to merge 2 commits into
pingdotgg:mainfrom
leorivastech:fix/repository-identity-toplevel-cache

Conversation

@leorivastech

@leorivastech leorivastech commented Jun 19, 2026

Copy link
Copy Markdown

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

…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.
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Jun 19, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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.

Comment thread apps/server/src/project/Layers/RepositoryIdentityResolver.ts
@macroscopeapp

macroscopeapp Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

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.

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.
@leorivastech

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: "Some requests are slow" toast triggered by unbounded git subprocess calls in replayEvents enrichment path

1 participant