| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
onJobCompleted marked the index job COMPLETED in one write, then ran several git reads (isRepoEmpty, getCommitHashForRefName, getLatestCommitTimestamp, getLocalDefaultBranch), then updated repo.indexedAt in a separate write. During the git-read window the job was already COMPLETED but indexedAt was still stale, so the scheduler (scheduleIndexJobs) saw no active job and an out-of-date indexedAt and scheduled a duplicate index job. On large repos the window is long enough to be hit routinely by the 1s scheduler poll. Run the git reads first, then write status=COMPLETED and indexedAt together in a single repoIndexingJob.update (nested repo update). Now the job stays IN_PROGRESS until the moment indexedAt becomes fresh, so the scheduler's two guards can never both pass at once. Fixes SOU-1150 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: abfc2ef9-a580-474b-bc64-a04d791fa5ef 📥 CommitsReviewing files that changed from the base of the PR and between e668c3f and 6b2b9ea. 📒 Files selected for processing (3)
WalkthroughRefactored RepoIndexManager.onJobCompleted to consolidate Prisma updates: job completion and repo metadata changes now execute in a single nested call instead of sequential operations. First-index detection is precomputed before repo updates modify state. Tests and changelog updated accordingly. ChangesNested Prisma Update Pattern
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches 📝 Generate docstrings
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. ❤️ ShareComment @coderabbitai help to get the list of available commands and usage tips. |
Sorry, something went wrong.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| Back | FazBrowse Home | New Git URL |
Fixes SOU-1150
Problem
Large repositories could be indexed twice within a single reindex interval due to a race in RepoIndexManager.onJobCompleted (packages/backend/src/repoIndexManager.ts).
The handler did three things in order:
Between steps 1 and 3 there is a window — the duration of the git reads in step 2 — where the job is already COMPLETED but indexedAt is still stale. The scheduler (scheduleIndexJobs) polls every reindexRepoPollingIntervalMs (default 1s) and creates a new index job when both:
So a poll landing in that window schedules a duplicate index job. On large repos the git reads take long enough that the 1s poll hits the window routinely; the Redlock doesn't help because onJobCompleted runs as a BullMQ completed event handler, after the lock from processJob has already been released (and the duplicate job row is created regardless of execution serialization).
Fix
Run the git reads first, then write status = COMPLETED and indexedAt (plus indexedCommitHash, pushedAt, metadata, defaultBranch) together in a single repoIndexingJob.update with a nested repo update.
Now the job remains IN_PROGRESS for the entire git-read window and only flips to COMPLETED at the same instant indexedAt becomes fresh. The scheduler's two guards can never both pass simultaneously: before the write, the active-job guard blocks; after it, the fresh indexedAt guards.
Verification
Reproduced the original bug locally by injecting a 5s sleep between the COMPLETED write and the indexedAt update — a single repo cascaded into 4 index jobs within ~11s. After the fix, with the sleep moved to before the combined write (so the job stays IN_PROGRESS), no duplicate is scheduled.
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes