fix(worker): clean up orphaned zoekt .tmp shard files after every index attempt#1214
fix(worker): clean up orphaned zoekt .tmp shard files after every index attempt#1214brendan-kellam wants to merge 3 commits into
Conversation
…dex attempt Move the cleanupTempShards call from the catch block into a finally block so orphans left behind by a previously interrupted run are removed on the next successful indexing pass, not only after a failure. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
WalkthroughThe PR refactors indexing error handling to guarantee cleanup of temporary Zoekt shard files on every indexing attempt, not only on failure. The ChangesCleanup guarantee in repo indexing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 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 `@packages/backend/src/repoIndexManager.ts`:
- Around line 521-527: Tests are failing because the new call to
cleanupTempShards(repo) in repoIndexManager.ts expects an export from the
./zoekt.js mock that doesn't exist; update the vi.mock blocks that mock
"./zoekt.js" to provide a cleanupTempShards export (e.g., a no-op async function
or a jest/vi.fn spy) or convert those mocks to partial mocks using
importOriginal and then override only the symbols you need while preserving
cleanupTempShards (use importOriginal() and return { ...original,
cleanupTempShards: vi.fn(async () => {}) }). Locate vi.mock calls referencing
"./zoekt.js" in the test files and add the cleanupTempShards export consistently
so the finally block can call it during tests.
🪄 Autofix (Beta)
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
Run ID: 990d8d9a-374f-4dbf-902f-68f681dbacad
📒 Files selected for processing (2)
CHANGELOG.mdpackages/backend/src/repoIndexManager.ts
The success path of indexRepository now calls cleanupTempShards in a finally block, so the mock needs to export it or the previously-passing tests fail. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/backend/src/repoIndexManager.test.ts (1)
57-60: ⚡ Quick winAdd explicit assertions that
cleanupTempShardsruns on both success and failure paths.Great mock update, but this PR’s core contract is cleanup-on-every-attempt. Please add assertions in representative success and failure job-processing tests to verify
cleanupTempShards(repo)is called in both paths.🤖 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 `@packages/backend/src/repoIndexManager.test.ts` around lines 57 - 60, Add explicit assertions that the mocked cleanupTempShards is invoked regardless of indexGitRepository success or failure: in the representative success test (where indexGitRepository resolves) and in the failure test (where indexGitRepository rejects), assert vi.mocked(cleanupTempShards).toHaveBeenCalledWith(repo) (or equivalent) after the job processing call; ensure you set indexGitRepository to resolve/reject in those tests, reset/clear mocks between tests, and import/reference the same cleanupTempShards mock used in the vi.mock block so both test paths verify cleanupTempShards(repo) is called.
🤖 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.
Nitpick comments:
In `@packages/backend/src/repoIndexManager.test.ts`:
- Around line 57-60: Add explicit assertions that the mocked cleanupTempShards
is invoked regardless of indexGitRepository success or failure: in the
representative success test (where indexGitRepository resolves) and in the
failure test (where indexGitRepository rejects), assert
vi.mocked(cleanupTempShards).toHaveBeenCalledWith(repo) (or equivalent) after
the job processing call; ensure you set indexGitRepository to resolve/reject in
those tests, reset/clear mocks between tests, and import/reference the same
cleanupTempShards mock used in the vi.mock block so both test paths verify
cleanupTempShards(repo) is called.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 578d3cd9-4a77-401a-be78-b9259a5fcc92
📒 Files selected for processing (1)
packages/backend/src/repoIndexManager.test.ts
Summary
cleanupTempShardsfrom thecatchblock into afinallyblock inrepoIndexManager.tsso leftover.tmpshard files are cleaned up on every indexing attempt, not just on failure..tmpfirst and atomically renames them), the orphaned.tmpfiles would persist indefinitely — zoekt itself only tracks temp files from the current build, so a subsequent successful run would not remove them.Investigation
Test plan
.tmpshard files when orphans exist from a prior interrupted run.cleanupTempShardscall is best-effort and does not throw, so it cannot mask the error fromcatch).🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Documentation
Tests