Skip to content

fix(projects): register a folder once when two adds race on a server - #34303

Merged
nwparker merged 3 commits into
mainfrom
fix/repo-add-race-12331
Oct 27, 2026
Merged

nwparker merged 3 commits into
mainfrom
fix/repo-add-race-12331

Conversation

@nwparker

@nwparker nwparker commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​14 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​14
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​30 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13

ELI5

If you added the same new folder to a paired Orca server twice at the same moment, the server could save it twice. It now checks again right before saving.

What Changed

  • Before: the server's repo.add looked for an existing project at the path, then waited on the realpath lookup and icon/upstream detection, then saved. Two adds of the same new folder could both pass the first check, so the folder was saved twice. This is easy to hit with WSL distro servers, where adding a project takes several requests.
  • After: right before saving, the server looks for the project again. If a concurrent add already saved it, that project is returned, with the same runtime-host adoption as the first check.
  • Mechanism: the desktop's local add (local-repo-registration.ts) already re-checks for a "race winner" after its awaits. The server's RuntimeRepositoryRegistrationController.add now does the same. The shared adopt-or-return logic moved into reuseExisting().

Why

This is the smallest fix that removes the duplicate save, and it reuses the pattern the desktop path already relies on. It covers every paired server, not just WSL.

What this doesn't cover: the other half of STA-12331, where a lost reply during nested import, or a retry of it, creates a second group. That needs an operation identity the server records with its result, gated on a capability so older servers keep today's behavior. It is a separate design change and isn't in this PR.

Linked Issue

Refs STA-12331 (concurrent add half only; the lost-reply / projectGroup.importNested retry half stays open).

Visual Proof

N/A. The server-side registration is deduplicated, and there is no UI change.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • New case in runtime-repository-registration-host-dedupe.test.ts: two concurrent add() calls for the same new folder produce one project, and both return the same id. It fails on main, where two rows are saved.

  • The existing registration controller tests pass.

Review

Codex review and an independent review against the pinned base.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Folder workspaces: covered, since it's the same code path.
  • SSH rows: still never match local rows (unchanged filter).
  • Mixed versions: no wire change.
  • Mobile: not affected.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

A paired server's repo.add looked for an existing project, then awaited icon
and upstream detection before saving. Two adds of the same new folder both
passed the check and saved it twice. Re-check right before saving, as the
desktop's local add already does.

Part of STA-12331.
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8103bb11-2b78-44c6-b03f-236cc2285b19
Commits

Reviewing files that changed from the base of the PR and between c77b837 and 3ab90d0.

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
Walkthrough

The registration controller now checks for a matching repository both before and after repository detection. When it finds one, it reuses that repository and preserves runtime-host adoption behavior. A concurrency test verifies that simultaneous adds for the same folder return the same repository and register it only once.

Priority: Low

Severity of issue fixed: Low

Merge Risk: Minimal · previous review c77b8

The intended same-path deduplication is in place. The remaining symlink-alias case can be tracked separately and does not block this merge.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the main change: a folder is registered once when two concurrent adds race on a server. It matches the raw summary, the PR objectives, and the description. It is specific and concise, …
Description check Passed The description follows the template and covers the key parts. It includes the ELI5, a before/after account with the mechanism, the reasoning for the approach and its limits, the linked issue (Refs ST…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a folder is registered once when two concurrent adds race on a server. It matches the raw summary, the PR objectives, and the description. It is specific and concise, and it has no file lists or vague terms.

Full details: Description check

Explanation

The description follows the template and covers the key parts. It includes the ELI5, a before/after account with the mechanism, the reasoning for the approach and its limits, the linked issue (Refs STA-12331, with the open half called out), N/A visual proof with reason, testing with a new regression test, and a completed checklist. The 'Fixes #' line in the template is replaced by a 'Refs' link, which is a deviation. The 'Testing' manual checkbox is unchecked, and the AI Disclosure section is absent. These are minor gaps, so the description is mostly complete.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

Finishing Touches: 💡 1
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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

Nitpick comments: 1
src/main/runtime/runtime-repository-registration-controller.ts: 1

69-69: Trivial · Data Integrity & Integration · Heavy lift

Close the remaining real-path race or track it separately.

normalizeRuntimePathForComparison normalizes path syntax but does not resolve symlinks. Concurrent folder registrations through a symlink and its target can therefore pass the initial real-path lookup and miss the final findAtPath() check, allowing two records.

This window existed before the PR. The new check correctly closes the race for identical path strings, so this is not a major regression. If alias deduplication is part of this PR’s scope, retain the real-path identity from the async phase and use it in the synchronous check immediately before store.addRepo().


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f45969a8-008f-4673-a8e0-dc5080cd1098
Commits

Reviewing files that changed from the base of the PR and between cbbaa2d and c77b837.

Files selected for processing: 2
  • src/main/runtime/runtime-repository-registration-controller.ts
  • src/main/runtime/runtime-repository-registration-host-dedupe.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@nwparker
nwparker merged commit 325ab0d into main Oct 27, 2026
62 of 64 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