Skip to content

fix: coalesce fetchReposForAllHosts so stale all-host loads can't resurrect removed projects (#7020)#7288

Closed
xianjianlf2 wants to merge 2 commits into
stablyai:mainfrom
xianjianlf2:fix/coalesce-all-hosts-repos-refetch
Closed

fix: coalesce fetchReposForAllHosts so stale all-host loads can't resurrect removed projects (#7020)#7288
xianjianlf2 wants to merge 2 commits into
stablyai:mainfrom
xianjianlf2:fix/coalesce-all-hosts-repos-refetch

Conversation

@xianjianlf2

@xianjianlf2 xianjianlf2 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #7024, closing the all-host gap it deliberately left open.

Deleting a Project Group with "Remove contained projects" could leave the removed projects as stale, unusable sidebar rows until restart (#7020). repos:changed is broadcast once per persisted mutation, so a group delete that also removes N contained projects emits an N+1 burst.

#7024 fixed the default path by scoping a monotonic generation guard to fetchRepos only — deliberately, because a shared counter let an unrelated fetchRepos bump the generation and abort an in-flight all-host load, dropping every host's repos. That left the runtime-active sidebar path, which refreshes via fetchReposForAllHosts, unguarded: an N+1 burst starts N+1 overlapping all-host loads, and an earlier one that read pre-removal state can resolve last and resurrect the removed projects.

Fix

Single-flight fetchReposForAllHosts:

  • Runs one load at a time; events arriving mid-load collapse into a single trailing reload.
  • The trailing reload's read happens at or after the final mutation, so the sidebar settles on the final persisted state.
  • Method-local (no shared counter, no cross-call interference), so it avoids the exact trap fix: drop stale repos fetches so deleted projects don't reappear (#7020) #7024 called out.
  • As a bonus, the burst's O(N²) per-host fetches collapse to ~1 trailing reload.

Scope: only the repos all-host path (the reported symptom is project ghost rows). The equivalent fetchProjectGroupsForAllHosts / fetchFolderWorkspacesForAllHosts out-of-order refresh is known but deferred.

Screenshots

No visual change.

Testing

  • pnpm lint (oxlint + react-doctor) on changed files
  • web tsgo typecheck (config/tsconfig.tc.web.json)
  • New repos-all-hosts-stale-fetch.test.ts — burst coalesces into one trailing reload that reads the final state; isolated event runs immediately
  • Existing repos-stale-fetch.test.ts (2) and repos.test.ts (22) pass unchanged
  • Full pnpm test / pnpm build — left to CI

AI Review Report

Reviewed with Claude Code. Checks:

  • Cross-platform: pure renderer store logic, no OS/path/shortcut/shell surface — identical on macOS/Linux/Windows.
  • SSH/remote/local: the all-host load already fans out to local + every runtime environment and fails soft per host; this change only serializes when those loads run, so remote/SSH hosts behave as before.
  • Provider/agent: no source-control or integration-specific code touched; provider-neutral.
  • Performance: strictly reduces work — an N+1 repos:changed burst goes from N+1 overlapping all-host loads (O(N²) host fetches) to ~2 loads. Single-flight state is plain booleans no component selects, so no extra renders.
  • Security: no input handling, command execution, path handling, auth, secrets, or IPC surface changed.

Notes

Method-local single-flight (chosen over extending #7024's generation guard to avoid the shared-counter cross-cancellation it documented). Supersedes the broader #7083 for the all-host slice; #7083 left open for now.

X: @mark86202384100

…urrect removed projects (stablyai#7020)

repos:changed fires once per persisted mutation, so deleting a project group
with contained projects emits an N+1 burst. In the runtime-active sidebar that
burst refreshes via fetchReposForAllHosts, which had no stale-fetch guard: stablyai#7024
scoped its monotonic generation guard to fetchRepos only (a shared counter let an
unrelated fetchRepos abort an in-flight all-host load and drop every host's
repos). So overlapping all-host loads could resolve out of order and an earlier
one that read pre-removal state could resolve last, resurrecting removed projects
as ghost sidebar rows until restart.

Single-flight fetchReposForAllHosts: run one load at a time and, when events
arrive mid-load, run exactly one trailing reload afterwards. The trailing reload
reads at or after the final mutation, so the sidebar settles on the final
persisted state; the burst's O(N^2) per-host fetches also collapse to ~1 trailing
reload. This is method-local (no shared counter, no cross-call interference),
closing the all-host gap stablyai#7024 left open.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds single-flight coordination to fetchReposForAllHosts in the repos store slice. RepoSlice now stores an in-flight cycle promise and a trailing reload flag, and the fetch logic reruns once when overlapping calls arrive during an active load. A new Vitest file covers the stale-fetch race scenario and an isolated single-call case.

Changes

Related issues: #7020

Related PRs: None identified.

Suggested labels: bug, tested

Suggested reviewers: None identified.

Sequence Diagram(s)

sequenceDiagram
  participant fetchReposForAllHosts
  participant loadReposForAllHosts

  fetchReposForAllHosts->>fetchReposForAllHosts: set reposAllHostsLoadCyclePromise
  fetchReposForAllHosts->>loadReposForAllHosts: load local repos, then runtime repos
  fetchReposForAllHosts->>fetchReposForAllHosts: set reposAllHostsReloadRequested on overlap
  fetchReposForAllHosts->>loadReposForAllHosts: rerun once if reload was requested
  fetchReposForAllHosts->>fetchReposForAllHosts: clear reposAllHostsLoadCyclePromise
Loading

Poem

A burst of calls, one path to keep,
A trailing reload, then sleep.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title accurately and concisely describes the main change: coalescing fetchReposForAllHosts to prevent stale reloads.
Description check ✅ Passed The description largely matches the template with Summary, Screenshots, Testing, AI Review Report, and Notes; only Security Audit is missing.

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 39ea396c-ed3a-4dc5-921b-7c8bb633ab0f

📥 Commits

Reviewing files that changed from the base of the PR and between f8591d6 and 066e32f.

📒 Files selected for processing (2)
  • src/renderer/src/store/slices/repos-all-hosts-stale-fetch.test.ts
  • src/renderer/src/store/slices/repos.ts

Comment thread src/renderer/src/store/slices/repos.ts Outdated
…ed cycle

Overlapping calls resolved as soon as the trailing reload was requested, so an
awaited caller (cold-start metrics, dependent fetches that read repos right after
awaiting) could continue before the refresh its event triggered landed. Hold the
in-flight cycle promise in the slice and return it to overlapping callers so every
caller waits for the same completed all-host refresh. Addresses CodeRabbit review
on stablyai#7288.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@xianjianlf2

Copy link
Copy Markdown
Contributor Author

Superseded by #8201 (building on #7024): the reposFetchGeneration guard now protects fetchReposForAllHosts, so a stale all-host load can no longer resurrect removed projects (#7020). Closing as already fixed on main.

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.

2 participants