Skip to content

fix: avoid duplicate repository groups during catalog refresh - #19170

Merged
nwparker merged 2 commits into
stablyai:mainfrom
kiendle:kien-ship-it/Bug-Grouped-repos-disappear
Sep 8, 2026
Merged

nwparker merged 2 commits into
stablyai:mainfrom
kiendle:kien-ship-it/Bug-Grouped-repos-disappear

Conversation

@kiendle

@kiendle kiendle commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem and fix

A create response and an overlapping catalog refresh can each insert the same repository group into renderer state. Later catalog merges preserve those duplicate entries, and the sidebar gives them identical React/virtualizer keys. Expanding and scrolling unrelated repositories then exposes repeated empty group headers and missing or obscured member rows.

Make the create continuation insert only when the same normalized owning host + group ID is absent. Keep an already-fetched row intact, including newer metadata, and return the existing state without notifying subscribers. This prevents the duplicate at the insertion boundary; no extra fetch, rendering workaround, or persistence migration is needed.

Fixes #19168.

Root-cause evidence and its limit

The main handler emits repos:changed before returning, but its notification starts another IPC roundtrip. That fact alone does not establish that this particular refresh normally beats the create response.

An independent before/after run of the improved real-Electron regression found:

Implementation Ordinary timing Forced refresh before create response
Original unconditional append Passed Failed: 3 rendered headers for one group; members missing/obscured in the screenshot
Host-aware insertion guard Passed Passed: one header and both members visible

The response gate deliberately forces the adverse ordering. It proves the corruption mechanism and the fix, not the natural frequency or exclusive cause of every disappearing-sidebar report. Both original store race regressions also failed before the fix.

Takeover improvements

  • Expanded creation coverage from 2 to 10 cases: both orderings on local/runtime hosts, newer metadata, zero subscriber notifications on duplicate delivery, host switch during creation, response loss after a successful refresh, legacy unstamped local identity, and direct-SSH identity isolation.
  • Replaced the permissive remote mock with explicit RPC method handling and host assertions; removed the settings cast and cleaned up mocks/subscriptions.
  • Exercise both ordinary timing and forced ordering in the crowded-sidebar E2E. Each uses 30 real temporary Git repositories, expands 10 unrelated repositories, scrolls, refreshes, and collapses/reopens the group with DOM assertions.
  • Restore the original IPC handler on first use and release the response gate in finally.
  • Use the existing bounded, Windows-safe process runner for Git fixture commands; omit the extra fixture repository.
  • Retain the small production guard and correct its causal comment.

Validation

  • 70 unique focused/adjacent tests across 8 files passed. The 4 IPC-hook tests passed with --testTimeout=120000; imports/execution took about 56 seconds on this machine. Initial default 30-second timeout failures are acknowledged.
  • Hidden Electron: both fixed scenarios passed; original logic passed ordinary timing and failed the forced race. Before/after screenshots inspected.
  • pnpm tc, targeted Oxlint, formatting, and whitespace checks passed.
  • Changed-code quality gate passed with zero findings across all 3 files, using ORCA_CODE_QUALITY_BASE=2e8fa3fe9b5 (the actual PR parent; the current checkout's origin/main has no merge base).
  • Electron E2E builds passed for the fixed and original implementations.
  • Not green: repository-wide typecheck:e2e reports 190 diagnostics in 96 other files, none in this spec. The complete test suite was not rerun during takeover. The contributor's earlier full run also reported unrelated failures; this PR does not claim full-suite green.

All automated app launches use ORCA_BACKGROUND_LAUNCH=1; no test window was revealed or focused.

Readiness review

No remaining candidate findings in the final diff; findings-severity counsel skipped under the checklist's zero-candidate rule. Reviewed ownership/concurrency, failure and cleanup, bounded work, security/supply chain, persistence and wire compatibility, platform behavior, and module organization.

Production adds one short-circuit linear lookup per create, with no polling, listeners, timers, extra requests, or retained cache. No schema, dependency, binary, RPC, protocol, or UI style changes. No mobile-facing surface touched. Group insertion is independent of Git vs folder workspaces and GitHub vs GitLab.

Actual rendered validation was macOS only. Runtime ownership and response-loss cases use unit mocks; live SSH disconnect/reconnect, Windows/Linux, and mobile were not exercised. Host-scoped store identity tests do not claim full UI support for cloned catalogs with identical UUIDs. Existing in-memory corruption is not migrated; a fresh renderer reloads the persisted catalog.

Original contributor visual proof

These attachments are from the contributor's initial run; takeover verification independently reproduced the same failure class, with three rather than five rendered headers.

Before After
Before After

Attribution

Original implementation and reproduction by @kiendle, AI-assisted. Maintainer-requested takeover review, stronger tests, harness cleanup, and independent before/after verification were AI-assisted with Codex.

Checklist

  • Focused change with root-cause explanation and limitations
  • Automated state and rendered regressions
  • Cross-platform, SSH/runtime, folder-workspace, and provider impact reviewed
  • No upstream skill-sharing/installer source or artifacts copied
  • All repository-wide checks green (limitations recorded above)

@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The project group creation flow now compares group ID and owner host before inserting a group into state. Store tests cover refresh and creation races across local, remote, and SSH hosts. End-to-end tests cover ordinary and delayed creation timing, including group visibility, repository assignment, scrolling, refresh, collapse, and re-expansion.

Priority: ➖ Normal — Impact reflects medium issue severity.

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 8a812

The host-aware group insertion change addresses duplicate and disappearing sidebar groups, but the added race test has a TypeScript contract mismatch that can prevent validation from compiling until corrected.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation satisfies issue [#19168] by making group insertion idempotent using host ID and group ID, retaining refreshed metadata, preserving same IDs on different hosts, and adding local, rem…
Out of Scope Changes check ✅ Passed The production guard, unit tests, E2E coverage, mock cleanup, and test harness updates directly support the linked issue. No unrelated product, schema, persistence, UI styling, protocol, or dependency…
Title check ✅ Passed The title clearly identifies the primary change: preventing duplicate repository groups during catalog refresh.
Description check ✅ Passed The description is comprehensive and covers the problem, fix, linked issue, visual proof, testing, limitations, AI attribution, cross-platform considerations, and checklist status. It does not use eve…
  • Fix all pre-merge checks with AI

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.

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

✅ No new issues found.

Reviewed changes

  • Idempotent group insertion — createProjectGroup now skips the append when a group with the same id and owning host is already present, closing the refresh-before-create-response race that produced duplicate UUIDs.
  • Host-scoped identity — the dedup uses getProjectGroupHostId, so a different host's group with the same id is preserved.
  • Store regression tests — a new repos-project-group-create-race.test.ts covers local and remote ordering plus metadata and host preservation.
  • Electron regression spec — project-group-creation-visibility.spec.ts reproduces the virtualized-sidebar failure with 30 seeded repos and a deterministic IPC gate.

The fix targets the mutation boundary, matches the existing mergeFetchedProjectGroupsForHost identity ([host, id]), and keeps already-fetched metadata intact. Verified both new tests would fail against the pre-fix behavior (store: 3 vs 2 rows; E2E: 5 vs 1 group header).

ℹ️ E2E spec depends on Electron's private IPC registry

The deterministic response gate reaches into ipcMain._invokeHandlers plus removeHandler/handle to stall the create response. It's guarded with a loud runtime check, so nothing to change — just the brittlest seam in the new coverage if Electron's internal API shifts in a future upgrade.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker nwparker changed the title fix: prevent grouped repositories disappearing after sidebar expansion fix: avoid duplicate repository groups during catalog refresh Sep 8, 2026
@nwparker

nwparker commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

New visual proof — independent takeover validation

Fresh before/after captures from the review run, separate from the original contributor's screenshots. Both show the same sidebar area after adding 30 temporary Git repositories, grouping two, then expanding and scrolling through 10 unrelated repositories. Images are cropped identically; their content is otherwise unchanged.

Before: original unconditional append After: reviewed host-aware insertion guard
Before: three copies of Crowded group, with repo-00 obscured After: one Crowded group header, with repo-00 and repo-01 visible

Verified by DOM assertions: the original implementation failed with 3 group headers instead of 1. The fixed implementation passed the expansion, scrolling, catalog refresh, and collapse/reopen checks, with both member repositories visible.

The adverse-order test deliberately holds the create response until the real catalog refresh inserts the group. Ordinary timing passed on both implementations; this proves the failure mechanism under that ordering, not how frequently it happens naturally.

Captured in real hidden Electron on macOS with ORCA_BACKGROUND_LAUNCH=1; no windows were revealed or focused. The strengthened regression is included in 8a81273, in tests/e2e/project-group-creation-visibility.spec.ts.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 527adbc0-3947-4734-a530-12ce1a3e7140

📥 Commits

Reviewing files that changed from the base of the PR and between 3761304 and 8a81273.

📒 Files selected for processing (3)
  • src/renderer/src/store/project-groups/project-group-mutations.ts
  • src/renderer/src/store/slices/repos-project-group-create-race.test.ts
  • tests/e2e/project-group-creation-visibility.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/store/project-groups/project-group-mutations.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.

if (compatibility) {
return compatibility
}
expect(request).toMatchObject({ selector: runtimeEnvironmentId })

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,80p' src/renderer/src/runtime/runtime-compatibility-test-fixture.ts
sed -n '35,65p' src/renderer/src/store/slices/repos-project-group-create-race.test.ts
rg -n -C 3 'RuntimeEnvironmentCallRequest|runtimeEnvironments.*call|selector' \
  src/renderer/src/runtime src/renderer/src/store

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- fixture ---'
rg -n -C 8 'export (type|interface) RuntimeEnvironmentCallRequest|RuntimeEnvironmentCallRequest' \
  src/renderer/src/runtime/runtime-compatibility-test-fixture.ts

printf '%s\n' '--- reviewed test ---'
sed -n '1,75p' src/renderer/src/store/slices/repos-project-group-create-race.test.ts

printf '%s\n' '--- relevant call contract ---'
rg -n -C 6 'runtimeEnvironments.*call|RuntimeEnvironmentCallRequest' \
  src/renderer/src/runtime/runtime-rpc-client.ts \
  src/renderer/src/runtime/runtime-compatibility-test-fixture.ts \
  src/renderer/src/store/slices/repos-project-group-create-race.test.ts

Repository: stablyai/orca

Length of output: 11497


Add selector to RuntimeEnvironmentCallRequest.

The type declares only method and params, but the callback accesses request.selector. TypeScript reports an invalid property access at line 52.

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

✅ No new issues found.

Reviewed changes

  • Comment refined, no behavior change — the dedup branch now attributes the race to an overlapping catalog refresh rather than the change notification, matching the actual mechanism.
  • Store regression coverage expanded — repos-project-group-create-race.test.ts grew from 2 to 10 cases: zero subscriber notifications on duplicate delivery, original-owner retention across a host switch, no-rollback on a lost create response, and SSH-vs-local identity isolation, plus explicit RPC selector assertions and real getDefaultSettings.
  • Electron spec hardened — project-group-creation-visibility.spec.ts now drives both ordinary and forced-adverse ordering, restores the original projectGroups:create handler on first use, releases the response gate in finally, re-fetches groups mid-test, and uses the Windows-safe runProcess for git fixture commands.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit f0bfc94 into stablyai:main Sep 8, 2026
34 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.

[Bug]: Grouped repositories disappear after expanding other repos when creation races catalog refresh

2 participants