Skip to content

The agent that grows with you

fix(delegation): restore ledger durability barriers

fangliquanflq6548177eb187
diff --git a/tests/tools/test_async_delegation.py b/tests/tools/test_async_delegation.py
index 4bc5af595e5..5a15608a826 100644
--- a/tests/tools/test_async_delegation.py
+++ b/tests/tools/test_async_delegation.py
@@ -86,6 +86,27 @@ def test_schema_init_preserves_shared_state_db_journal_mode(tmp_path, monkeypatc
conn.close()
+def test_connect_preserves_wal_and_applies_macos_durability_barriers(
+ tmp_path, monkeypatch
+):
+ """Each ledger connection must carry the macOS write barriers."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ seed = sqlite3.connect(tmp_path / "state.db")
+ try:
+ assert seed.execute("PRAGMA journal_mode=WAL").fetchone()[0] == "wal"
+ finally:
+ seed.close()
+
+ conn = ad._connect()
+ try:
+ assert conn.execute("PRAGMA journal_mode").fetchone()[0] == "wal"
+ assert conn.execute("PRAGMA synchronous").fetchone()[0] == 2
+ assert conn.execute("PRAGMA checkpoint_fullfsync").fetchone()[0] == 1
+ finally:
+ conn.close()
+
+
def test_active_for_session_counts_every_live_delegation_state():
with ad._records_lock:
ad._records.update(
diff --git a/tools/async_delegation.py b/tools/async_delegation.py
index 5025a0a2715..aa787804c8f 100644
--- a/tools/async_delegation.py
+++ b/tools/async_delegation.py
@@ -140,11 +140,14 @@ def _connect() -> sqlite3.Connection:
def _initialize_schema(conn: sqlite3.Connection) -> None:
+ from hermes_state import _reapply_durability_barriers
+
# state.db's owning SessionDB connection establishes the configured journal
# mode. This secondary durability ledger must preserve that mode: applying
# WAL here on every short-lived connection requires an exclusive lock when
# the file is not already WAL and can collide with live transcript/FTS
# writers. The ledger works in either WAL or DELETE mode.
+ _reapply_durability_barriers(conn)
conn.execute(
"""CREATE TABLE IF NOT EXISTS async_delegations (
delegation_id TEXT PRIMARY KEY,