From 0c7d44b265188af9f54015129e2cc235926751b6 Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Wed, 11 Feb 2026 19:01:26 +0100 Subject: [PATCH] fix(db): sqlite connector always reads/writes main worktree database MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same fix as the ticket CLI — uses git rev-parse --git-common-dir to resolve DB path to the main worktree. Prevents WAL/journal pollution when sqlite-query or sqlite-exec are called from feature branches. Co-Authored-By: Claude Opus 4.6 --- db/connectors/sqlite_connector.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/db/connectors/sqlite_connector.py b/db/connectors/sqlite_connector.py index 774273535..dd022b783 100755 --- a/db/connectors/sqlite_connector.py +++ b/db/connectors/sqlite_connector.py @@ -13,6 +13,7 @@ Usage: import json import os import sqlite3 +import subprocess import sys from pathlib import Path @@ -25,12 +26,26 @@ CONFIG_PATH = SCRIPT_DIR / "config.json" SCHEMA_PATH = SCRIPT_DIR.parent / "schema.sql" +def _main_worktree(): + """Find the main worktree root via git's common dir.""" + try: + common = subprocess.check_output( + ["git", "rev-parse", "--git-common-dir"], + stderr=subprocess.DEVNULL, text=True + ).strip() + return Path(common).resolve().parent + except (subprocess.CalledProcessError, OSError): + return SCRIPT_DIR.parent.parent + + def load_config(): """Load config.json and resolve the SQLite database path.""" with open(CONFIG_PATH, "r") as f: cfg = json.load(f) - # Resolve sqlite_db relative to the connectors directory - db_path = (SCRIPT_DIR / cfg["sqlite_db"]).resolve() + # Always resolve DB path in the main worktree to avoid + # WAL/journal pollution on feature branches causing merge conflicts. + main_root = _main_worktree() + db_path = (main_root / "db" / "commonwealth.db").resolve() cfg["sqlite_db_resolved"] = str(db_path) return cfg