Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Cleaned up orphaned zoekt `.tmp` shard files on every indexing attempt, not just on failure, so leftovers from previously interrupted runs are removed. [#1214](https://github.com/sourcebot-dev/sourcebot/pull/1214)

## [4.17.2] - 2026-05-16

### Added
Expand Down
12 changes: 8 additions & 4 deletions packages/backend/src/repoIndexManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,15 @@
const indexDuration_s = durationMs / 1000;
logger.debug(`Indexed ${repo.name} (id: ${repo.id}) in ${indexDuration_s}s`);
} catch (error) {
// Clean up any temporary shard files left behind by the failed indexing operation.
// Zoekt creates .tmp files during indexing which can accumulate if indexing fails repeatedly.
logger.warn(`Indexing failed for ${repo.name} (id: ${repo.id}), cleaning up temp shard files...`);
await cleanupTempShards(repo);
logger.warn(`Indexing failed for ${repo.name} (id: ${repo.id}).`);
throw error;
} finally {
// Zoekt writes shards to a .tmp file first, then atomically renames them to their final
// name. If the process is killed or interrupted during the rename loop, some .tmp files
// may be left behind that zoekt won't clean up on the next run (it only tracks temp
// files from the current build). Running cleanup here ensures orphans from previous
// interrupted runs are removed.
await cleanupTempShards(repo);

Check failure on line 527 in packages/backend/src/repoIndexManager.ts

View workflow job for this annotation

GitHub Actions / test

src/repoIndexManager.test.ts > RepoIndexManager > latestIndexingJobStatus Updates > sets latestIndexingJobStatus to IN_PROGRESS when job starts

Error: [vitest] No "cleanupTempShards" export is defined on the "./zoekt.js" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("./zoekt.js"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ RepoIndexManager.indexRepository src/repoIndexManager.ts:527:19 ❯ RepoIndexManager.runJob src/repoIndexManager.ts:333:31 ❯ src/repoIndexManager.ts:264:24

Check failure on line 527 in packages/backend/src/repoIndexManager.ts

View workflow job for this annotation

GitHub Actions / test

src/repoIndexManager.test.ts > RepoIndexManager > Job Processing - Success > de-duplicates the default branch before truncating matching branches

Error: [vitest] No "cleanupTempShards" export is defined on the "./zoekt.js" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("./zoekt.js"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ RepoIndexManager.indexRepository src/repoIndexManager.ts:527:19 ❯ RepoIndexManager.runJob src/repoIndexManager.ts:333:31 ❯ src/repoIndexManager.ts:264:24

Check failure on line 527 in packages/backend/src/repoIndexManager.ts

View workflow job for this annotation

GitHub Actions / test

src/repoIndexManager.test.ts > RepoIndexManager > Job Processing - Success > keeps default branch and truncates to the first 63 matching tags

Error: [vitest] No "cleanupTempShards" export is defined on the "./zoekt.js" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("./zoekt.js"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ RepoIndexManager.indexRepository src/repoIndexManager.ts:527:19 ❯ RepoIndexManager.runJob src/repoIndexManager.ts:333:31 ❯ src/repoIndexManager.ts:264:24

Check failure on line 527 in packages/backend/src/repoIndexManager.ts

View workflow job for this annotation

GitHub Actions / test

src/repoIndexManager.test.ts > RepoIndexManager > Job Processing - Success > invokes zoekt-git-index with correct arguments

Error: [vitest] No "cleanupTempShards" export is defined on the "./zoekt.js" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("./zoekt.js"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ RepoIndexManager.indexRepository src/repoIndexManager.ts:527:19 ❯ RepoIndexManager.runJob src/repoIndexManager.ts:333:31 ❯ src/repoIndexManager.ts:264:24

Check failure on line 527 in packages/backend/src/repoIndexManager.ts

View workflow job for this annotation

GitHub Actions / test

src/repoIndexManager.test.ts > RepoIndexManager > Job Processing - Success > fetches existing repository when directory exists

Error: [vitest] No "cleanupTempShards" export is defined on the "./zoekt.js" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("./zoekt.js"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ RepoIndexManager.indexRepository src/repoIndexManager.ts:527:19 ❯ RepoIndexManager.runJob src/repoIndexManager.ts:333:31 ❯ src/repoIndexManager.ts:264:24

Check failure on line 527 in packages/backend/src/repoIndexManager.ts

View workflow job for this annotation

GitHub Actions / test

src/repoIndexManager.test.ts > RepoIndexManager > Job Processing - Success > deletes directory and performs fresh clone when path exists but is not a valid git repo root

Error: [vitest] No "cleanupTempShards" export is defined on the "./zoekt.js" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("./zoekt.js"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ RepoIndexManager.indexRepository src/repoIndexManager.ts:527:19 ❯ RepoIndexManager.runJob src/repoIndexManager.ts:333:31 ❯ src/repoIndexManager.ts:264:24

Check failure on line 527 in packages/backend/src/repoIndexManager.ts

View workflow job for this annotation

GitHub Actions / test

src/repoIndexManager.test.ts > RepoIndexManager > Job Processing - Success > clones new repository when directory does not exist

Error: [vitest] No "cleanupTempShards" export is defined on the "./zoekt.js" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock(import("./zoekt.js"), async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ RepoIndexManager.indexRepository src/repoIndexManager.ts:527:19 ❯ RepoIndexManager.runJob src/repoIndexManager.ts:333:31 ❯ src/repoIndexManager.ts:264:24
Comment thread
brendan-kellam marked this conversation as resolved.
}

return revisions;
Expand Down
Loading