Skip to content

fix: make lumen clean respect active index locks - #182

Merged
aeneasr merged 1 commit into
mainfrom
aeneasr/fix-clean-review-feedback
Aug 6, 2026
Merged

fix: make lumen clean respect active index locks#182
aeneasr merged 1 commit into
mainfrom
aeneasr/fix-clean-review-feedback

Conversation

@aeneasr

@aeneasr aeneasr commented Aug 6, 2026

Copy link
Copy Markdown
Member

This updates lumen clean so it acquires the index writer lock before removing a stale index, which prevents --days 0 from deleting actively locked indexes while keeping the CLI and docs aligned with that behavior.

It also rejects --days values 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 test hung in cmd.test and was aborted.

Summary by CodeRabbit

  • New Features
    • Added a maximum supported value for the cleanup period; larger values are rejected without deleting indexes.
    • Cleanup now displays progress while processing indexes.
  • Bug Fixes
    • Actively locked indexes are preserved during zero-day cleanup and full-wipe rebuilds.
    • Cleanup safely handles removal failures, continues processing, and reports the encountered error.
  • Documentation
    • Updated cleanup documentation to clarify that actively locked indexes are preserved.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The clean command now rejects unsupported durations, reports progress through the TUI, and removes only eligible indexes. Active locks remain respected during cleanup. Tests cover duration limits and removal failures. Documentation reflects lock-preserving behavior.

Changes

Index cleanup

Layer / File(s) Summary
Cleanup command contract
cmd/clean.go
The command limits --days values, updates its help text, and reports missing directories through the TUI.
Lock-safe index removal
cmd/clean.go
Cleanup acquires each writer lock before checking staleness or removing an index. Removal failures are reported while processing continues.
Validation and documentation
cmd/clean_test.go, README.md, skills/reindex/SKILL.md
Tests cover duration boundaries, lock release, and removal failures. Documentation states that active locks preserve indexes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • ory/lumen#135: Related cached-index cleanup behavior with protected data.
  • ory/lumen#180: Related clean command changes for validation, lock-safe deletion, progress reporting, tests, and documentation.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: lumen clean now respects active index locks.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch aeneasr/fix-clean-review-feedback

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.

@aeneasr
aeneasr marked this pull request as ready for review August 6, 2026 16:46

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f62bf57 and 3cde714.

📒 Files selected for processing (4)
  • README.md
  • cmd/clean.go
  • cmd/clean_test.go
  • skills/reindex/SKILL.md

Comment thread cmd/clean.go
Comment on lines +137 to +140
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Suggested change
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.

@aeneasr
aeneasr merged commit cce6305 into main Aug 6, 2026
16 of 18 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.

1 participant