Skip to content

fix(storage): make SQLite message writes atomic - #172

Merged
BunsDev merged 1 commit into
mainfrom
fix/sqlite-message-atomicity
Jul 30, 2026
Merged

fix(storage): make SQLite message writes atomic#172
BunsDev merged 1 commit into
mainfrom
fix/sqlite-message-atomicity

Conversation

@BunsDev

@BunsDev BunsDev commented Jul 30, 2026

Copy link
Copy Markdown
Member

Summary

  • wrap SQLite message insertion and session metadata updates in one transaction
  • preserve UUID idempotency by updating session count and recency only for newly inserted messages
  • add real SQLite regressions for rollback, retry, and duplicate message IDs

Verification

  • cargo test -p claurst-core sqlite_storage::tests
  • cargo test -p claurst-core
  • cargo check --workspace
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo fmt --all --check

Fixes #171

Fixes #171.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Val Alexander <bunsthedev@gmail.com>
Copilot AI review requested due to automatic review settings July 30, 2026 17:13
@vercel

vercel Bot commented Jul 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview Jul 30, 2026 5:13pm

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses SQLite storage consistency by making SqliteSessionStore::save_message atomic: the message insert and the session metadata update happen in a single transaction, preserving idempotency for duplicate message UUIDs and adding regression tests for rollback/retry behavior.

Changes:

  • Wrap messages insertion and conditional sessions metadata updates in a single SQLite transaction.
  • Preserve idempotency by only updating sessions.updated_at/message_count when a message row is newly inserted.
  • Add SQLite regression tests covering rollback on failure and duplicate message IDs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 88 to 92
if inserted > 0 {
self.conn.execute(
transaction.execute(
"UPDATE sessions
SET updated_at = ?1,
message_count = message_count + 1
@BunsDev
BunsDev merged commit 4521333 into main Jul 30, 2026
5 checks passed
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.

Make SQLite message indexing atomic

2 participants