fix: make lumen clean respect active index locks - #182
Conversation
📝 WalkthroughWalkthroughThe ChangesIndex cleanup
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/clean.go`:
- Around line 137-140: Update the lock-acquisition branch in the clean flow
around indexlock.TryAcquire: when err is non-nil, return a wrapped error; only
emit the existing progress.Info message and return false, nil when lock is nil
without an error. Preserve the successful lock path unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3a79df08-350a-49d0-b1f9-19a886254e58
📒 Files selected for processing (4)
README.mdcmd/clean.gocmd/clean_test.goskills/reindex/SKILL.md
| lock, err := indexlock.TryAcquire(indexlock.LockPathForDB(dbPath)) | ||
| if err != nil || lock == nil { | ||
| progress.Info(fmt.Sprintf("Keeping %s: an indexer is currently running.", name)) | ||
| return false, nil |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Return writer-lock acquisition errors.
indexlock.TryAcquire returns nil, nil only when another process holds the lock. This branch also handles non-nil errors as if an indexer holds the lock. Return a wrapped error when err != nil. Keep the current progress message only when lock == nil.
Proposed fix
lock, err := indexlock.TryAcquire(indexlock.LockPathForDB(dbPath))
- if err != nil || lock == nil {
+ if err != nil {
+ return false, fmt.Errorf("acquire writer lock for %s: %w", name, err)
+ }
+ if lock == nil {
progress.Info(fmt.Sprintf("Keeping %s: an indexer is currently running.", name))
return false, nil
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| lock, err := indexlock.TryAcquire(indexlock.LockPathForDB(dbPath)) | |
| if err != nil || lock == nil { | |
| progress.Info(fmt.Sprintf("Keeping %s: an indexer is currently running.", name)) | |
| return false, nil | |
| lock, err := indexlock.TryAcquire(indexlock.LockPathForDB(dbPath)) | |
| if err != nil { | |
| return false, fmt.Errorf("acquire writer lock for %s: %w", name, err) | |
| } | |
| if lock == nil { | |
| progress.Info(fmt.Sprintf("Keeping %s: an indexer is currently running.", name)) | |
| return false, nil |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cmd/clean.go` around lines 137 - 140, Update the lock-acquisition branch in
the clean flow around indexlock.TryAcquire: when err is non-nil, return a
wrapped error; only emit the existing progress.Info message and return false,
nil when lock is nil without an error. Preserve the successful lock path
unchanged.
This updates
lumen cleanso it acquires the index writer lock before removing a stale index, which prevents--days 0from deleting actively locked indexes while keeping the CLI and docs aligned with that behavior.It also rejects
--daysvalues above 106751 to avoid overflowing the Go max whole-day duration.The branch adds regression coverage for the max boundary, overflow rejection, and lock release after a removal failure, so cleanup stays safe during concurrent indexing and error paths.
Validation:
go test -tags=fts5 ./cmd -run TestClean_ -count=1;make testhung incmd.testand was aborted.Summary by CodeRabbit