Skip to content

fix: backfill session row on out-of-order hooks, add busy_timeout#104

Open
rajkumarsakthivel wants to merge 1 commit into
mainfrom
fix/memory-hooks-session-fk-and-busy-timeout
Open

fix: backfill session row on out-of-order hooks, add busy_timeout#104
rajkumarsakthivel wants to merge 1 commit into
mainfrom
fix/memory-hooks-session-fk-and-busy-timeout

Conversation

@rajkumarsakthivel

Copy link
Copy Markdown
Member

Summary

  • Hook handlers (UserPromptSubmit, PostToolUse, Stop, SessionEnd) now call _ensure_session() before FK-dependent inserts, backfilling the sessions row if SessionStart was missed (cce serve started mid-session, dropped POST, or resumed session_id)
  • Added PRAGMA busy_timeout = 5000 to memory.db connections so concurrent writers (hooks + auto-prune) wait up to 5s instead of failing with "database is locked"

Previously, every hook after a missed SessionStart would crash with sqlite3.IntegrityError: FOREIGN KEY constraint failed, spamming the terminal with tracebacks.

Closes #49

Two fixes for #49:

1. FOREIGN KEY constraint failed: UserPromptSubmit and PostToolUse crash
   when SessionStart was missed (cce serve started mid-session, dropped
   POST, resumed session_id). All hook handlers now call _ensure_session()
   which does INSERT OR IGNORE to backfill the FK target before dependent
   inserts.

2. database is locked: auto-prune contends with the hot insert path.
   Added PRAGMA busy_timeout = 5000 so concurrent writers wait up to
   5 seconds instead of failing immediately.

Closes #49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite3.IntegrityError

1 participant