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
5 changes: 3 additions & 2 deletions src/pinky_daemon/activity_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import time
from pathlib import Path

from pinky_daemon.sqlite_journal import configure_rollback_journal


class ActivityStore:
"""SQLite-backed activity log."""
Expand All @@ -29,8 +31,7 @@ def _db(self) -> sqlite3.Connection:
connection = getattr(self._thread_local, "connection", None)
if connection is None:
connection = sqlite3.connect(self._db_path)
connection.execute("PRAGMA journal_mode=WAL")
connection.execute("PRAGMA busy_timeout=30000")
configure_rollback_journal(connection, db_label="activity.db")
self._thread_local.connection = connection
return connection

Expand Down
5 changes: 3 additions & 2 deletions src/pinky_daemon/agent_comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from dataclasses import dataclass, field
from pathlib import Path

from pinky_daemon.sqlite_journal import configure_rollback_journal


@dataclass
class AgentMessage:
Expand Down Expand Up @@ -83,8 +85,7 @@ def _conn(self) -> sqlite3.Connection:
if connection is None:
connection = sqlite3.connect(self._db_path)
connection.row_factory = sqlite3.Row
connection.execute("PRAGMA journal_mode=WAL")
connection.execute("PRAGMA busy_timeout=30000")
configure_rollback_journal(connection, db_label="agent_comms.db")
self._thread_local.connection = connection
return connection

Expand Down
8 changes: 6 additions & 2 deletions src/pinky_daemon/analytics_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from contextlib import contextmanager
from datetime import UTC, datetime, timedelta

from pinky_daemon.sqlite_journal import configure_rollback_journal

# Providers to include in analytics dashboards.
# Only Anthropic/Claude usage — excludes Codex CLI (OpenAI) and other non-Anthropic providers.
_ANTHROPIC_PROVIDERS = {"firstParty", "default", "anthropic", "bedrock", "vertex"}
Expand Down Expand Up @@ -77,10 +79,12 @@ def _connect(self):

def _init_db(self) -> None:
with self._connect() as conn:
# Runs once per store construction, before any other connection is
# handed out. TRUNCATE is persisted in the database header, so the
# short-lived connections from _connect() inherit it.
configure_rollback_journal(conn, db_label="analytics.db")
conn.executescript(
"""
PRAGMA journal_mode=WAL;

CREATE TABLE IF NOT EXISTS analytics_session_facts (
session_id TEXT PRIMARY KEY,
agent_name TEXT NOT NULL,
Expand Down
4 changes: 3 additions & 1 deletion src/pinky_daemon/app_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from dataclasses import dataclass
from pathlib import Path

from pinky_daemon.sqlite_journal import configure_rollback_journal


def _log(msg: str) -> None:
print(msg, file=sys.stderr, flush=True)
Expand Down Expand Up @@ -78,7 +80,7 @@ def __init__(self, db_path: str = "data/apps.db") -> None:
Path(db_path).parent.mkdir(parents=True, exist_ok=True)
self._db_path = db_path
self._db = sqlite3.connect(db_path, check_same_thread=False)
self._db.execute("PRAGMA journal_mode=WAL")
configure_rollback_journal(self._db, db_label="apps.db")
self._db.execute("PRAGMA foreign_keys=ON")
self._init_tables()

Expand Down
5 changes: 3 additions & 2 deletions src/pinky_daemon/conversation_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from dataclasses import dataclass, field
from pathlib import Path

from pinky_daemon.sqlite_journal import configure_rollback_journal


def _fts5_phrase(query: str) -> str:
"""Escape a user query as quoted FTS5 phrase tokens (no operator syntax)."""
Expand Down Expand Up @@ -94,8 +96,7 @@ def _conn(self) -> sqlite3.Connection:
if connection is None:
connection = sqlite3.connect(self._db_path)
connection.row_factory = sqlite3.Row
connection.execute("PRAGMA journal_mode=WAL")
connection.execute("PRAGMA busy_timeout=30000")
configure_rollback_journal(connection, db_label="conversations.db")
self._thread_local.connection = connection
return connection

Expand Down
4 changes: 2 additions & 2 deletions src/pinky_daemon/dream_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
)
from pinky_daemon.dream_prompt import DREAM_SYSTEM_PROMPT
from pinky_daemon.sdk_runner import SDKRunner, SDKRunnerConfig
from pinky_daemon.sqlite_journal import configure_rollback_journal
from pinky_daemon.tmux_dream_runner import TmuxDreamConfig, TmuxDreamRunner


Expand Down Expand Up @@ -114,8 +115,7 @@ def _db(self) -> sqlite3.Connection:
connection = getattr(self._thread_local, "connection", None)
if connection is None:
connection = sqlite3.connect(self._db_path)
connection.execute("PRAGMA journal_mode=WAL")
connection.execute("PRAGMA busy_timeout=30000")
configure_rollback_journal(connection, db_label="dreams.db")
self._thread_local.connection = connection
return connection

Expand Down
5 changes: 3 additions & 2 deletions src/pinky_daemon/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from enum import Enum
from pathlib import Path

from pinky_daemon.sqlite_journal import configure_rollback_journal


def _log(msg: str) -> None:
print(msg, file=sys.stderr, flush=True)
Expand Down Expand Up @@ -133,8 +135,7 @@ def _db(self) -> sqlite3.Connection:
connection = getattr(self._thread_local, "connection", None)
if connection is None:
connection = sqlite3.connect(self._db_path)
connection.execute("PRAGMA journal_mode=WAL")
connection.execute("PRAGMA busy_timeout=30000")
configure_rollback_journal(connection, db_label="audit.db")
self._thread_local.connection = connection
return connection

Expand Down
4 changes: 3 additions & 1 deletion src/pinky_daemon/kb_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

import yaml

from pinky_daemon.sqlite_journal import configure_rollback_journal


def _log(msg: str) -> None:
print(msg, file=sys.stderr, flush=True)
Expand Down Expand Up @@ -177,7 +179,7 @@ def __init__(self, data_dir: str | Path) -> None:

def _conn(self) -> sqlite3.Connection:
conn = sqlite3.connect(str(self.db_path))
conn.execute("PRAGMA journal_mode=WAL")
configure_rollback_journal(conn, db_label="kb.db")
conn.execute("PRAGMA foreign_keys=ON")
conn.row_factory = sqlite3.Row
return conn
Expand Down
3 changes: 2 additions & 1 deletion src/pinky_daemon/librarian_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from pinky_daemon.kb_store import _FRONTMATTER_RE, KBStore, _content_hash
from pinky_daemon.librarian_prompt import LIBRARIAN_SYSTEM_PROMPT
from pinky_daemon.sdk_runner import SDKRunner, SDKRunnerConfig
from pinky_daemon.sqlite_journal import configure_rollback_journal


def _log(msg: str) -> None:
Expand Down Expand Up @@ -66,7 +67,7 @@ def __init__(

def _conn(self) -> sqlite3.Connection:
conn = sqlite3.connect(str(self._db_path))
conn.execute("PRAGMA journal_mode=WAL")
configure_rollback_journal(conn, db_label="librarian_state.db")
conn.row_factory = sqlite3.Row
return conn

Expand Down
4 changes: 3 additions & 1 deletion src/pinky_daemon/mesh_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from pathlib import Path
from typing import Any, Literal

from pinky_daemon.sqlite_journal import configure_rollback_journal

# -- Records -------------------------------------------------------------------


Expand Down Expand Up @@ -102,7 +104,7 @@ class MeshStore:
def __init__(self, db_path: str = "data/mesh.db") -> None:
Path(db_path).parent.mkdir(parents=True, exist_ok=True)
self._db = sqlite3.connect(db_path, check_same_thread=False)
self._db.execute("PRAGMA journal_mode=WAL")
configure_rollback_journal(self._db, db_label="mesh.db")
self._db.execute("PRAGMA foreign_keys=ON")
self._lock = threading.RLock()
self._init_tables()
Expand Down
8 changes: 6 additions & 2 deletions src/pinky_daemon/message_context_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from pathlib import Path
from typing import Any

from pinky_daemon.sqlite_journal import configure_rollback_journal

DEFAULT_RETENTION_DAYS = 30
DEFAULT_MAX_PER_AGENT = 1000

Expand All @@ -30,8 +32,10 @@ def __init__(
Path(db_path).parent.mkdir(parents=True, exist_ok=True)
self._db = sqlite3.connect(db_path, check_same_thread=False)
self._db.row_factory = sqlite3.Row
self._db.execute("PRAGMA journal_mode=WAL")
self._db.execute("PRAGMA busy_timeout=5000")
# configure_rollback_journal also installs a 30s busy_timeout, which
# replaces the 5s this store used to set: rollback journalling
# serialises readers against the writer, so waiting longer is right.
configure_rollback_journal(self._db, db_label="message_context.db")
self._create_schema()
self._ensure_columns()
self._ensure_identity_key()
Expand Down
4 changes: 3 additions & 1 deletion src/pinky_daemon/outreach_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from dataclasses import dataclass, field
from pathlib import Path

from pinky_daemon.sqlite_journal import configure_rollback_journal


def _log(msg: str) -> None:
print(msg, file=sys.stderr, flush=True)
Expand Down Expand Up @@ -53,7 +55,7 @@ class OutreachConfigStore:
def __init__(self, db_path: str = "data/outreach_config.db") -> None:
Path(db_path).parent.mkdir(parents=True, exist_ok=True)
self._db = sqlite3.connect(db_path, check_same_thread=False)
self._db.execute("PRAGMA journal_mode=WAL")
configure_rollback_journal(self._db, db_label="outreach_config.db")
self._init_tables()

def _init_tables(self) -> None:
Expand Down
6 changes: 4 additions & 2 deletions src/pinky_daemon/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

import yaml

from pinky_daemon.sqlite_journal import configure_rollback_journal


def _log(msg: str) -> None:
print(msg, file=sys.stderr, flush=True)
Expand Down Expand Up @@ -139,7 +141,7 @@ def db(self) -> sqlite3.Connection:
data_dir.mkdir(parents=True, exist_ok=True)
self._db_path = str(data_dir / "plugins.db")
self._db = sqlite3.connect(self._db_path, check_same_thread=False)
self._db.execute("PRAGMA journal_mode=WAL")
configure_rollback_journal(self._db, db_label="plugins.db")
return self._db

def create_table(self, table_name: str, schema: str) -> None:
Expand Down Expand Up @@ -296,7 +298,7 @@ def _init_state_db(self) -> None:
"""Initialize the plugin state tracking table."""
Path(self._state_db_path).parent.mkdir(parents=True, exist_ok=True)
db = sqlite3.connect(self._state_db_path, check_same_thread=False)
db.execute("PRAGMA journal_mode=WAL")
configure_rollback_journal(db, db_label="plugins.db")
db.execute("""
CREATE TABLE IF NOT EXISTS plugin_state (
name TEXT PRIMARY KEY,
Expand Down
5 changes: 3 additions & 2 deletions src/pinky_daemon/presentation_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from dataclasses import dataclass
from pathlib import Path

from pinky_daemon.sqlite_journal import configure_rollback_journal


def _log(msg: str) -> None:
print(msg, file=sys.stderr, flush=True)
Expand Down Expand Up @@ -137,8 +139,7 @@ def _db(self) -> sqlite3.Connection:
connection = getattr(self._thread_local, "connection", None)
if connection is None:
connection = sqlite3.connect(self._db_path)
connection.execute("PRAGMA journal_mode=WAL")
connection.execute("PRAGMA busy_timeout=30000")
configure_rollback_journal(connection, db_label="presentations.db")
connection.execute("PRAGMA foreign_keys=ON")
self._thread_local.connection = connection
return connection
Expand Down
5 changes: 3 additions & 2 deletions src/pinky_daemon/research_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from dataclasses import dataclass, field
from pathlib import Path

from pinky_daemon.sqlite_journal import configure_rollback_journal


def _log(msg: str) -> None:
print(msg, file=sys.stderr, flush=True)
Expand Down Expand Up @@ -147,8 +149,7 @@ def _db(self) -> sqlite3.Connection:
connection = getattr(self._thread_local, "connection", None)
if connection is None:
connection = sqlite3.connect(self._db_path)
connection.execute("PRAGMA journal_mode=WAL")
connection.execute("PRAGMA busy_timeout=30000")
configure_rollback_journal(connection, db_label="research.db")
connection.execute("PRAGMA foreign_keys=ON")
self._thread_local.connection = connection
return connection
Expand Down
8 changes: 4 additions & 4 deletions src/pinky_daemon/session_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from dataclasses import dataclass, field
from pathlib import Path

from pinky_daemon.sqlite_journal import configure_rollback_journal


def _log(msg: str) -> None:
print(msg, file=sys.stderr, flush=True)
Expand Down Expand Up @@ -71,8 +73,7 @@ def _db(self) -> sqlite3.Connection:
connection = getattr(self._thread_local, "connection", None)
if connection is None:
connection = sqlite3.connect(self._db_path)
connection.execute("PRAGMA journal_mode=WAL")
connection.execute("PRAGMA busy_timeout=30000")
configure_rollback_journal(connection, db_label="sessions.db")
self._thread_local.connection = connection
return connection

Expand Down Expand Up @@ -314,8 +315,7 @@ def _db(self) -> sqlite3.Connection:
connection = getattr(self._thread_local, "connection", None)
if connection is None:
connection = sqlite3.connect(self._db_path)
connection.execute("PRAGMA journal_mode=WAL")
connection.execute("PRAGMA busy_timeout=30000")
configure_rollback_journal(connection, db_label="sessions.db")
self._thread_local.connection = connection
return connection

Expand Down
5 changes: 3 additions & 2 deletions src/pinky_daemon/skill_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from enum import Enum
from pathlib import Path

from pinky_daemon.sqlite_journal import configure_rollback_journal


def _log(msg: str) -> None:
print(msg, file=sys.stderr, flush=True)
Expand Down Expand Up @@ -153,8 +155,7 @@ def _db(self) -> sqlite3.Connection:
connection = getattr(self._thread_local, "connection", None)
if connection is None:
connection = sqlite3.connect(self._db_path)
connection.execute("PRAGMA journal_mode=WAL")
connection.execute("PRAGMA busy_timeout=30000")
configure_rollback_journal(connection, db_label="skills.db")
connection.execute("PRAGMA foreign_keys=ON")
self._thread_local.connection = connection
return connection
Expand Down
Loading