fix(indexer): preserve session metadata during incremental reindex

Previously the session metadata accumulator started from zero on every
  reindex pass, so an incremental update would overwrite started_at and
  message_count with values derived only from the new lines.

  Now reads the existing session row first and merges new data on top.
This commit is contained in:
tommy0103
2026-05-30 03:53:16 +08:00
parent 1d45c91a8a
commit 2b02a7b6c8
2 changed files with 13 additions and 4 deletions
+9 -1
View File
@@ -135,7 +135,15 @@ function indexJsonl(db, fi) {
idx: db.prepare('INSERT OR REPLACE INTO index_state (jsonl_path,mtime,lines_processed) VALUES (?,?,?)'),
};
const sm = { started_at: null, ended_at: null, git_branch: null, version: null, title: null, n: 0 };
const existing = !fi.isSubagent ? db.prepare('SELECT * FROM sessions WHERE id = ?').get(fi.sessionId) : null;
const sm = {
started_at: existing?.started_at || null,
ended_at: existing?.ended_at || null,
git_branch: existing?.git_branch || null,
version: existing?.version || null,
title: existing?.title || null,
n: existing?.message_count || 0,
};
for (let i = skip; i < lines.length; i++) {
let obj;