Skip to content

fix: Prevent stale worktree refreshes hiding new worktrees - #5266

Closed
nexusjuniorai wants to merge 1 commit into
stablyai:mainfrom
nexusjuniorai:fix/worktree-refresh-agent-created
Closed

nexusjuniorai wants to merge 1 commit into
stablyai:mainfrom
nexusjuniorai:fix/worktree-refresh-agent-created

Conversation

@nexusjuniorai

Copy link
Copy Markdown
Contributor

Summary

Prevent overlapping worktree refreshes from letting an older detected-list response overwrite newer renderer state. This keeps agent-created worktrees visible as soon as the latest refresh sees them, instead of disappearing until another worktree event such as deletion refreshes the list again.

Screenshots

No visual change

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Scoped checks run:

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/store/slices/worktrees.test.ts
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/store/slices/worktrees.test.ts -t "keeps a newer worktree refresh"
  • pnpm exec oxlint src/renderer/src/store/slices/worktrees.ts src/renderer/src/store/slices/worktrees.test.ts
  • pnpm run typecheck:web
  • pnpm exec oxfmt --check src/renderer/src/store/slices/worktrees.ts src/renderer/src/store/slices/worktrees.test.ts
  • git diff --check

AI Review Report

Codex diagnosed and reviewed the refresh path around fetchWorktrees, watcher/runtime refresh events, and the existing create-worktree race comments. The main risk checked was whether stale out-of-order scans could clobber a newer scan that already included the agent-created worktree; the added regression reproduced that failure before the fix. The review also checked that the change is renderer store state only and does not touch shortcuts, shortcut labels, path separators, shell behavior, or Electron platform APIs, so the behavior is cross-platform for macOS, Linux, and Windows.

Security Audit

No new input handling, command execution, filesystem path handling, authentication, secrets, dependencies, or IPC channels were added. The change only ignores stale renderer refresh responses when a newer refresh for the same repo exists. Existing IPC/RPC worktree detection payloads keep the same shape and trust boundary. No security follow-up needed.

Notes

The branch had zero commits ahead of origin/main before the fix commit. Direct push to stablyai/orca was denied for the authenticated GitHub account, so the PR head branch is nexusjuniorai:fix/worktree-refresh-agent-created targeting stablyai/orca:main.

@nexusjuniorai
nexusjuniorai marked this pull request as ready for review June 12, 2026 12:29
@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request prevents race conditions in overlapping worktree refresh operations. It introduces per-repository refresh request tracking via module-level state and helper functions, updates fetchWorktrees to create a request ID and short-circuit if a newer refresh has already superseded it, and ensures cleanup via a finally block. A test case validates that stale scans do not overwrite newer results when multiple fetchWorktrees calls are in flight.

🚥 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description covers all required sections with comprehensive details: summary explains the problem, screenshots confirms no visual change, testing section shows tests were added and scoped checks were run, AI review confirms cross-platform analysis and security audit confirms no new security risks.
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 'Prevent stale worktree refreshes hiding new worktrees' directly and clearly summarizes the main change: blocking older refresh responses from overwriting newer worktree state.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@nexusjuniorai nexusjuniorai changed the title Prevent stale worktree refreshes hiding new worktrees fix: Prevent stale worktree refreshes hiding new worktrees Jun 12, 2026
@nexusjuniorai

Copy link
Copy Markdown
Contributor Author

Sorry, it is working properly now, please close this if not useful

@nwparker

nwparker commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Hi @nexusjuniorai — thanks for this, and for the follow-up note that it looks resolved on your end. The out-of-order worktree-refresh race (an older overlapping scan resolving last and clobbering a newer agent-created worktree) is now handled on main by the coalesced scan path — listDetectedWorktreesForRepoCoalesced shares a single in-flight scan keyed by repo/host, with additive mergeDetectedWorktreesForHost merging, so overlapping refreshes can't resolve out of order. I confirmed it's in place at current HEAD.

Closing as resolved — thank you for the contribution and the careful writeup. 🙏

@nwparker nwparker closed this Jul 4, 2026
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.

3 participants