fix(indexer): force build purges stale sessions instead of only clearing index_state
The skill's `--build` (always a force build) cleared `index_state` and re-indexed existing files, but never removed rows for transcripts that no longer exist on disk, so deleted sessions accumulated forever (the dogfood showed 328 indexed sessions vs 283 current files). A force build is meant to be a clean rebuild, matching what the app already does. Drop every derived table (messages, tool_calls, tool_results, sessions, summaries, subagents, workflows, workflow_agents) in the force path, then re-index from the current files. `memories` is the durable, human-approved layer and is never cleared; messages_fts is repopulated by the existing 'rebuild' command in finalize. Add a test that builds two sessions, deletes one transcript, force-rebuilds, and asserts the stale session is purged while a seeded memory survives. Verified the test is discriminating: without the fix it reports ['gone','keep'] instead of ['keep']. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
01a390fa10
commit
c964653362
@@ -148,6 +148,14 @@ function buildIndex({ force = false } = {}) {
|
||||
|
||||
if (force) {
|
||||
db.prepare("DELETE FROM index_state WHERE jsonl_path != '__last_build__'").run();
|
||||
// Clearing index_state alone re-indexes existing files but leaves rows for
|
||||
// files that no longer exist on disk (stale sessions accumulate). A force
|
||||
// build is a clean rebuild: drop every derived table, then re-index from the
|
||||
// current files. `memories` is the durable, human-approved layer and is never
|
||||
// cleared; messages_fts is repopulated by the 'rebuild' command in finalize.
|
||||
for (const table of ['messages', 'tool_calls', 'tool_results', 'sessions', 'summaries', 'subagents', 'workflows', 'workflow_agents']) {
|
||||
db.prepare(`DELETE FROM ${table}`).run();
|
||||
}
|
||||
}
|
||||
|
||||
const files = [
|
||||
|
||||
Reference in New Issue
Block a user