From 79c99ac93cc92e1797b698631801e63b3e3897f2 Mon Sep 17 00:00:00 2001 From: Tristan Simas Date: Sun, 15 Nov 2026 10:16:22 -0500 Subject: [PATCH] One applier for a WAL connection's policy: foreign_keys + synchronous, not restated per store The synchronous value became one declaration in the previous commit, but the mechanism that applies a WAL store connection's policy was still written twice: WalStore._configured_writer set foreign_keys + synchronous inline, and CoordinationStore.configure_connection set the same pair with its own literals. Two openers of a WAL store could therefore still disagree on what a connection's policy is. Extract the per-connection pair onto StoreWriter.apply_connection_policy (where synchronous already lives); WalStore and CoordinationStore both call it and restate neither PRAGMA. WAL-mode assertion stays where each store needs it (WalStore re-asserts per open; the coordinator sets it once on the private stage), since that timing is a real per-store difference, not a duplicated fact. Behavior-identical: same two PRAGMAs, same values. Coordination + cohort + WAL carry + response tests green (base's one test_registry_revision red is pre-existing, confirmed on 21ff3333d). Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01XbFMSnLEc51gw21bLFFRK1 --- src/agent_comms/coordination/database.py | 11 +++++------ src/agent_comms/storage/typed_table.py | 11 +++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/agent_comms/coordination/database.py b/src/agent_comms/coordination/database.py index b90570a5cd..c9c36d9d4b 100644 --- a/src/agent_comms/coordination/database.py +++ b/src/agent_comms/coordination/database.py @@ -137,12 +137,11 @@ def configure_connection(cls, connection: sqlite3.Connection) -> None: for row_type in CoordinatorTable.declarations(): row_type.configure_connection(connection) connection.row_factory = sqlite3.Row - connection.execute("PRAGMA foreign_keys = ON") - # WAL is set once, on the private stage before the file is published (or by the - # coordinator_wal carry with every owner stopped), and persists in the file header, so - # no opener switches the mode and fresh openers cannot race over it. The durability of - # a commit is the one StoreWriter policy every WAL writer shares, not a literal here. - connection.execute(f"PRAGMA synchronous = {cls.synchronous}") + # Referential integrity and commit durability are the one WAL-writer policy on + # StoreWriter, applied here, not restated. WAL itself is set once on the private stage + # before the file is published (or by the coordinator_wal carry with every owner + # stopped) and persists in the file header, so no opener switches the mode. + cls.apply_connection_policy(connection) def _prepare_private_file(self) -> None: self.path.parent.mkdir(parents=True, exist_ok=True) diff --git a/src/agent_comms/storage/typed_table.py b/src/agent_comms/storage/typed_table.py index e3b181c667..aedd1eeb22 100644 --- a/src/agent_comms/storage/typed_table.py +++ b/src/agent_comms/storage/typed_table.py @@ -3282,6 +3282,14 @@ class StoreWriter(PublishedSQLiteFile): # store that must survive power loss raises its own bar (goal stores declare EXTRA). synchronous: ClassVar[str] = "NORMAL" + @classmethod + def apply_connection_policy(cls, connection: sqlite3.Connection) -> None: + """The per-connection policy every WAL writer here applies: referential integrity on, + and the one synchronous durability this family shares. A store that opens a WAL + connection applies this and nothing of its own, so no two openers can disagree.""" + connection.execute("PRAGMA foreign_keys = ON") + connection.execute(f"PRAGMA synchronous = {cls.synchronous}") + @property @abstractmethod def store(self) -> WrittenFile: @@ -3576,8 +3584,7 @@ def _configured_writer( connection = self.writer( path, isolation_level=None, check_same_thread=check_same_thread) try: - connection.execute(f"PRAGMA synchronous={self.synchronous}") - connection.execute("PRAGMA foreign_keys=ON") + self.apply_connection_policy(connection) if not SQLiteJournalMode.write_ahead(connection.execute("PRAGMA journal_mode=WAL")): raise RelationViolationError(f"{self.filename} requires WAL") yield connection