elastic / elastic/semantic-code-search-indexer

bug: SQLite queue sequence not reset with --clean flag

Open Beginner friendly
#119 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
19
Forks
10
PR merge metrics
No merged PRs in 30d

Description

## Problem

When using the `--clean` flag to do a full reindex, the SQLite autoincrement sequence is not reset. This causes document IDs to continue from the previous run rather than starting from 1.

## Impact

- **Functional**: None - the indexer works correctly
- **Observability**: Makes progress tracking via ID ranges confusing/misleading
- **Example**: After a previous run indexed 5M docs, a new `--clean` run starts IDs at 5,000,001 instead of 1

## Root Cause

The `clear()` method in `src/utils/sqlite_queue.ts` only deletes rows but doesn't reset the sequence:

```typescript
async clear(): Promise {
this.logger.info('Clearing queue (removing all items including failed)');
const result = this.db.prepare('DELETE FROM queue').run();
this.logger.info(`Cleared ${result.changes} items from queue`);

// Also clear the enqueue_completed flag
this.db.prepare("DELETE FROM queue_metadata WHERE key = 'enqueue_completed'").run();

// MISSING: Reset sqlite_sequence
}
```

SQLite behavior:
- `DELETE FROM table` removes all rows but preserves the AUTOINCREMENT sequence
- The sequence is stored in `sqlite_sequence` table

## Fix

Add one line to reset the sequence:

```typescript
async clear(): Promise {
this.logger.info('Clearing queue (removing all items including failed)');
const result = this.db.prepare('DELETE FROM queue').run();
this.logger.info(`Cleared ${result.changes} items from queue`);

// Reset autoincrement sequence so IDs start from 1 again
this.db.prepare("DELETE FROM sqlite_sequence WHERE name = 'queue'").run();

// Also clear the enqueue_completed flag
this.db.prepare("DELETE FROM queue_metadata WHERE key = 'enqueue_completed'").run();
}
```

## Severity

Low - cosmetic/observability issue only, not a functional bug.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/utils/sqlite_queue.ts and inspect the clear() method and its existing queue cleanup statements. Verify the SQLite queue schema and run the project's available checks, then confirm that using --clean removes the prior sequence state so the next indexed document receives ID 1.

Written by the indexing model from the issue text.

Assessment

Tech stack
sqlite, typescript
Domain
backend, databases
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.