Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/agent_comms/coordination/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions src/agent_comms/storage/typed_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Loading