Files
ChatLab/packages/node-runtime
diguaandClaude Sonnet 4.6 5a9f44fac5 fix(ai): overhaul semantic index session lifecycle and retrieval accuracy
Session management:
- buildAllPending: recheck completed sessions against live message count
  to enqueue rebuild when new messages arrived since last index run
- runner: detect non-append-only backfills and force full re-index instead
  of resuming from a stale cursor that would skip the backfilled messages
- service/session-state-store: add reactivate() and use it when re-enabling
  a stale session so the old model identity is preserved in the state row;
  on restart buildAllPending() can still detect isStale() and enqueue rebuild
- chunker-config: use sessionId (not absolute path) as the stable key for
  db_path_hash so migrating userDataDir does not orphan existing indexes
- cleanupUnused: cross-check state rows against listSessionIds() to detect
  sessions whose DB was deleted and mark them pending cleanup

Retrieval accuracy:
- hasApiKey: guard against missing authProfile to avoid false positives
- FtsSearcher interface: return {id, ts} pairs; fts-searcher fetches ts from
  message table so chunk mapping has the correct millisecond timestamp
- store.mapMessageToChunk: use (start_ts, start_message_id) composite ordering
  and end-boundary check to break same-second ties deterministically
- message-range-reader: use (ts, id) composite bounds on both sides so
  same-second messages at chunk boundaries are not attributed to wrong parents
- evidence.ts: add startTs/endTs to EvidenceHit; locate core evidence
  boundaries by hit message IDs to avoid same-second ambiguity
- hybrid-search: expand ANN candidate pool to 10× when time filter is active
  to reduce chance of missing in-range chunks in long conversations

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 16:18:39 +08:00
..