fix: catch IntegrityError on sessions.title UNIQUE index creation - #65628
fix: catch IntegrityError on sessions.title UNIQUE index creation#65628AlexFucuson9 wants to merge 1 commit into
Conversation
When duplicate titles exist in the sessions table, CREATE UNIQUE INDEX throws sqlite3.IntegrityError instead of OperationalError. The previous code only caught OperationalError, causing Dashboard API crashes. Fix: catch IntegrityError, deduplicate by keeping newest row, then retry index creation. This handles: - Session imports with non-unique titles - Context compression creating duplicate continuation titles - Race conditions in concurrent session creation Fixes NousResearch#65602
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment
Scope
- 1 file (hermes_state.py), +12 lines
- Handles IntegrityError when creating a UNIQUE index on sessions.title if duplicate titles already exist — deduplicates by keeping newest row before retrying the index creation.
Observations
- Correct error handling: Catches the specific IntegrityError, deduplicates with a clear strategy (keep newest), then retries the index creation.
- GROUP BY + MAX(rowid) is a standard SQLite deduplication pattern — appropriate here.
- Minor: the WHERE clause in the DELETE subquery is redundant since the index is already filtered on , but harmless.
Looks Good
- Focused, well-scoped fix for a real DB migration edge case
- No impact on other code paths
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment
Scope
- 1 file (hermes_state.py), +12 lines
- Handles IntegrityError when creating a UNIQUE index on sessions.title if duplicate titles exist — deduplicates by keeping newest row before retrying the index creation.
Quality
- GROUP BY + MAX(rowid) is a standard SQLite deduplication pattern.
- Clear, focused fix for a real DB migration edge case.
- No impact on other code paths.
Looks Good
- Well-scoped error handling in schema init.
Reviewed by Hermes Agent
|
Closing in favor of PR #65689 (salvaged from #65636). You were first on this bug and the IntegrityError diagnosis was spot-on — thank you for the report-quality root cause. The reason we went with the other implementation: the dedup DELETE here keeps only |
Summary
hermes_state.pyline 1783 creates a UNIQUE index onsessions.titlebut only catchessqlite3.OperationalError. When duplicate titles exist in the database, SQLite throwssqlite3.IntegrityErrorinstead — which is uncaught, crashing Dashboard API calls to/api/sessions/{id}/messages.Root Cause
Commit
60b6abefd(feat: session naming with unique titles) added the UNIQUE INDEX but only catchesOperationalError("index already exists"). It doesn't handle the case where the index doesn't exist yet but the table already has duplicate titles — which throwsIntegrityError.This can happen through:
Fix
Catch
sqlite3.IntegrityErrorbeforeOperationalError. When caught:Changes
hermes_state.py: AddIntegrityErrorhandler with deduplication logicTest Plan
Fixes #65602