Skip to content

feat(adapters): SQLite session store with the journal Store port - #61

Merged
margaux-faurie merged 11 commits into
mainfrom
feat/sqlite-store
Nov 29, 2026
Merged

margaux-faurie merged 11 commits into
mainfrom
feat/sqlite-store

Conversation

@margaux-faurie

@margaux-faurie margaux-faurie commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

What

The M2 SQLite session store in culla-adapters (culla_adapters::store), implementing the core's journal Store port and the session and decision-log persistence the core expects (ADR 0009, file-engine §2.2, §2.3).

  • SessionsDir: the injected sessions folder (%LOCALAPPDATA%\Culla\sessions in the app, a temp folder in tests), <key>.sqlite and <key>.lock named from the source key (serial + folded path, never the drive letter).
  • SessionDb::open_at: fail closed. An existing file must be a Culla database (application id CULL, or an empty database a crashed first open left), not newer than this build, and pass integrity_check and foreign_key_check before anything is written. Then WAL, synchronous=FULL, foreign_keys=ON, mmap_size=0, trusted_schema=OFF and a 5 s busy timeout are applied and read back. Migrations run in one BEGIN IMMEDIATE transaction. After that the open checks schema_migration against user_version, op_transition against the core's edges, that every trigger is there, and that the stored source is this one. A refused file is left byte for byte as it was, never recreated.
  • Schema v1 as in file-engine §2.3, with the differences listed there: a schema_migration table, nullable mtimes, fixed partial_rel checks, more guard triggers.
  • Sessions ("Start fresh" archives the active session in the same transaction, refused while a plan is open), scans, groups and members (insert only; reconcile comes next).
  • Decision log: record folds the log, reads the locks and appends in one transaction. A refused command appends nothing, and a corrupt log gets nothing more appended.
  • Plans: insert_plan (operation ids never reused), journal (replays the entries and checks the derived columns against them: fail closed), status changes under the source lock (confirm, supersede, start, pause, interrupt, close in one transaction with the core's close).
  • PlanStore: the core's Store. Each append is all or nothing and durable on return, and every entry is checked again by the journal_check trigger. stop records stopping.

Dependency: rusqlite 0.41 with bundled (SQLite 3.54: 0.40 bundles a SQLite hit by RUSTSEC-2026-0459) (MIT; libsqlite3-sys MIT; SQLite public domain; hashlink, fallible-iterator and the rest MIT/Apache, foldhash Zlib, all on the existing allowlist, so no deny.toml change). Margaux gave her OK in chat on 29 Nov 2026. Lockfile refreshed by the workflow.

Tests

crates/adapters/tests/store.rs (Linux and Windows):

  • create, settings and seeded edges
  • reopen is idempotent
  • same database under another drive letter
  • another source refused
  • garbage, foreign, newer, damaged-page and tampered files refused and left unchanged
  • a crash image taken during an uncommitted write
  • the decision log against the core fold
  • a corrupt log is never appended to
  • every journal state round-tripped, with the stored journal equal to the live one after every append
  • batch all or nothing, illegal or stale entries refused
  • the source lock is exclusive and required
  • concurrent writers serialized, with exactly one winner on a contested group
  • a held write lock makes an append fail busy, and the store carries on
  • the core's executor running and resuming through the store, with the volume lost at a different call each run and the database reopened each time
  • a cancel recorded and surviving a reopen

The core has no shared Store conformance suite. The executor test plays that role here against the real run and close.

Proposals for Margaux (SPEC §10, file-engine §2.2, §2.3, §13)

  • WAL with synchronous=FULL, as proposed in ADR 0009, asserted on every open.
  • The fail-closed rules and the schema differences.
  • The plan status edges.
  • The provisional FNV-1a 128 file key until BLAKE3 is a dependency. Switch before the first release.
  • No read-only open at launch yet.
  • Nested-source check and reconcile not in yet.

Touches dependencies (Cargo.toml, Cargo.lock): waits for Margaux's OK before merge.

https://claude.ai/code/session_012N2yvaknQJCM8yjc93h9jN


Generated by Claude Code

claude and others added 11 commits November 29, 2026 10:15
One database per source under an injected sessions folder (ADR 0009,
file-engine §2.2, §2.3): schema v1 with a schema_migration table, WAL
and synchronous=FULL read back on every open, integrity_check and
foreign_key_check before any write, fail closed on a damaged, foreign,
newer or tampered file. Sessions, groups, members, the decision log
(fold, locks and append in one transaction), plans and their status
changes, and PlanStore, the core's journal Store for one plan, under
the <key>.lock source lock. Adds rusqlite 0.40 with the bundled SQLite
(Margaux's OK, 29 Nov 2026). Choices recorded as proposals in SPEC §10.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012N2yvaknQJCM8yjc93h9jN
RUSTSEC-2026-0459 affects the SQLite that libsqlite3-sys 0.38 bundles;
rusqlite 0.41 bundles 3.54.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012N2yvaknQJCM8yjc93h9jN
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012N2yvaknQJCM8yjc93h9jN
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012N2yvaknQJCM8yjc93h9jN
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012N2yvaknQJCM8yjc93h9jN
…s, crash cuts

- PlanStore appends only while the plan is applying or stopping (INV-03).
- confirm requires the active session, the newest draft and the whole
  decision log, and supersedes the other drafts; Start fresh supersedes
  the archived session's drafts (INV-04).
- An existing file is checked through a read-only connection first;
  defensive mode, trusted_schema=OFF and mmap_size=0 before the first
  read; the whole schema, SQL text included, compared on open; stored
  paths validated as Windows names; an empty file with a leftover -wal
  refused; plans fixed by triggers; plans loaded in one read transaction.
- Tests: crash cuts at every disk call with crash images and the
  write-ahead check (INV-13, INV-14), a journal write failing mid-run,
  append-only and fixed rows (INV-16), the lock (INV-23), the live -wal
  refusal, the bundled SQLite version.
- Docs: file-engine §2.2, §9.7, §13; SPEC §10; threat model T5, T12,
  T14; nfr §8; testing §4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012N2yvaknQJCM8yjc93h9jN
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012N2yvaknQJCM8yjc93h9jN
@margaux-faurie
margaux-faurie merged commit 840d0b3 into main Nov 29, 2026
11 checks passed
@margaux-faurie
margaux-faurie deleted the feat/sqlite-store branch November 29, 2026 10:28
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.

2 participants