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