Skip to content

fix(memory): preserve existing DB when sqlite3_open fails - #63

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-f181
Draft

fix(memory): preserve existing DB when sqlite3_open fails#63
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-f181

Conversation

@cursor

@cursor cursor Bot commented Aug 8, 2026

Copy link
Copy Markdown

Summary

Prevents silent data loss when memory_init cannot open an existing SQLite database.

Bug and impact

On sqlite3_open failure, memory_init called remove(path) before retrying. If the DB file already existed (permissions blip, transient I/O), the on-disk memory store was deleted and replaced with an empty database on retry — losing sessions, long-term memories, and cron jobs.

Root cause

Open-failure recovery treated existing and missing files the same: unlink then recreate.

Fix and validation

  • Skip remove() when the path already existed; return error instead.
  • Added test_existing_db_preserved_on_open_failure (chmod 000 → init fails → data intact after restore).
  • ./build/test_memory — all tests pass.
Open in Web View Automation 

Do not unlink an existing memory.db on transient open failures (permissions,
I/O). Deleting the file caused silent data loss when init was retried after
the underlying issue cleared.

Adds test_existing_db_preserved_on_open_failure.

Co-authored-by: esadrianno <[email protected]>
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.

1 participant