Bug
The README states:
Sessions appearing in multiple files (e.g. both .json and .jsonl) are de-duplicated by session id; the newest copy wins.
But the implementation does not guarantee this. iter_chat_files yields files in os.scandir order, and upsert_session uses ON CONFLICT(id) so the last file processed wins — not the newest by mtime. A stale .json can overwrite a freshly-written .jsonl for the same session id within a single run.
Expected
When the same session_id appears in multiple files, the copy with the newest mtime should win deterministically.
Suggested fix
Sort files by mtime before upserting, or collect candidates per session id and upsert only the newest.
Affected
engram.py → iter_chat_files, cmd_index, upsert_session
Bug
The README states:
But the implementation does not guarantee this.
iter_chat_filesyields files inos.scandirorder, andupsert_sessionusesON CONFLICT(id)so the last file processed wins — not the newest bymtime. A stale.jsoncan overwrite a freshly-written.jsonlfor the same session id within a single run.Expected
When the same
session_idappears in multiple files, the copy with the newestmtimeshould win deterministically.Suggested fix
Sort files by
mtimebefore upserting, or collect candidates per session id and upsert only the newest.Affected
engram.py→iter_chat_files,cmd_index,upsert_session