One wrong SQL constraint caused an AI audit tool to mix Claude and Cursor session logs
Chron, an MCP server that logs AI coding sessions to a local SQLite database, was incorrectly merging messages from separate tools — Claude and Cursor — into a single session record. The root cause was a UNIQUE constraint on the session title column alone, which meant two tools working on the same task with the same auto-generated title would share one session row. An attempt to fix this with a composite unique index on title and ai_tool initially failed because SQL treats NULL values as unequal, allowing duplicate rows when the tool field was empty. The developer resolved this by indexing an expression using COALESCE to substitute NULL with an empty string, ensuring each tool gets a distinct session. The session-lookup query also had to be updated to filter by both title and tool, since changing only the constraint without updating the query would have perpetuated the merging behavior.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in