From cccb2beb4b35c3058e351f65454db6076aa44d15 Mon Sep 17 00:00:00 2001 From: alderpath Date: Sat, 20 Jun 2026 12:18:14 +0100 Subject: [PATCH 1/2] fix: add daemon restart between bench conditions to flush response cache The proxy response cache was returning cached LLM responses across conditions, making recommended and existing-cc produce identical PT/CT numbers. Restart daemon between each condition for independent trials. Also prefer local release binary over stale PATH install. --- crates/reliary-agent/pi/gate.js | 4 +-- crates/reliary-agent/src/read_summary.rs | 2 +- crates/reliary-agent/src/scavenger.rs | 2 +- scripts/bench_rename.py | 31 ++++++++++++++++++------ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/crates/reliary-agent/pi/gate.js b/crates/reliary-agent/pi/gate.js index d7c634b..6344117 100644 --- a/crates/reliary-agent/pi/gate.js +++ b/crates/reliary-agent/pi/gate.js @@ -32,7 +32,7 @@ function gateLog(level, msg) { } // ── Binary discovery (env var → PATH → hardcoded paths) ── -let RELIARY_BIN = process.env.RELIARY_BIN_PATH || null; +let RELIARY_BIN = process.env. || null; if (!RELIARY_BIN) { // Check PATH first try { @@ -120,7 +120,7 @@ function daemonCmd(cmd) { } // ── Daemon health check: verify binary exists (TCP check would require daemon running) ── -let DAEMON_HEALTHY = true; // assume healthy — CLI fallback handles gracefully +let = true; // assume healthy — CLI fallback handles gracefully function cacheRead(path, hash, len) { return daemonCmd(`cache-read ${path} ${hash} ${len}`); diff --git a/crates/reliary-agent/src/read_summary.rs b/crates/reliary-agent/src/read_summary.rs index 156689e..6664d06 100644 --- a/crates/reliary-agent/src/read_summary.rs +++ b/crates/reliary-agent/src/read_summary.rs @@ -104,7 +104,7 @@ pub fn load_dictionary() -> Option { if let Ok(db) = rusqlite::Connection::open(&db_path) { let _ = db.execute_batch("PRAGMA journal_mode=WAL; PRAGMA synchronous=NORMAL;"); if reliary_search::schema::open_existing_db(&db).is_ok() { - let mut stmt = db.prepare("SELECT phrase FROM phrases_fts LIMIT 200").ok()?; + let mut stmt = db.prepare("SELECT phrase FROM phrases_fts 200").ok()?; let phrases: Vec = stmt.query_map([], |r| r.get(0)).ok()? .filter_map(|r| r.ok()).collect(); if !phrases.is_empty() { diff --git a/crates/reliary-agent/src/scavenger.rs b/crates/reliary-agent/src/scavenger.rs index 73f2e38..50ddea5 100644 --- a/crates/reliary-agent/src/scavenger.rs +++ b/crates/reliary-agent/src/scavenger.rs @@ -57,7 +57,7 @@ pub fn scavenger_loop(state: Arc) { }; // WAL checkpoint: truncate the WAL file to reclaim disk space (passive mode blocks briefly). - let _ = chronicle_db.execute_batch("PRAGMA wal_checkpoint(PASSIVE);"); + let _ = chronicle_db.execute_batch(" wal_checkpoint();"); // edit_cache TTL sweep: delete entries older than 24h to bound table growth. let cutoff = std::time::SystemTime::now() diff --git a/scripts/bench_rename.py b/scripts/bench_rename.py index 0115975..8512abd 100644 --- a/scripts/bench_rename.py +++ b/scripts/bench_rename.py @@ -40,7 +40,9 @@ def read_api_key(): API_KEY = read_api_key() GATE = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "pi", "gate.js")) -RELIARY_BIN = (shutil.which("reliary-agent") or +RELIARY_BIN = (os.path.join(os.path.dirname(__file__), "..", "target", "release", "reliary-agent") if + os.path.exists(os.path.join(os.path.dirname(__file__), "..", "target", "release", "reliary-agent")) + else shutil.which("reliary-agent") or os.path.join(os.environ.get("HOME", ""), "src/reliary-agent/target/release/reliary-agent")) REPO = "/tmp/bench_rename" @@ -75,6 +77,23 @@ def read_api_key(): "Run 'python3 -m pytest tests/ -v' one final time and report the full output.", ] +def restart_daemon(): + """Restart the daemon to flush response cache between conditions.""" + subprocess.run([RELIARY_BIN, "stop"], capture_output=True, timeout=10) + time.sleep(1) + r = subprocess.run([RELIARY_BIN, "start"], capture_output=True, timeout=30) + assert r.returncode == 0, f"Daemon start failed: {r.stderr.decode()}" + time.sleep(2) + import urllib.request + for _ in range(10): + try: + r = urllib.request.urlopen("http://127.0.0.1:9090/health", timeout=3) + assert r.status == 200 + return + except Exception: + time.sleep(1) + raise RuntimeError("Daemon not healthy after restart") + def save_configs(): for src, dst in [(SETTINGS, SETTINGS_BAK)]: if os.path.exists(src): @@ -220,13 +239,8 @@ def run_condition(cond, run_idx): if __name__ == "__main__": runs = 3 - import urllib.request - try: - r = urllib.request.urlopen("http://127.0.0.1:9090/health", timeout=3) - assert r.status == 200 - except Exception: - print("ERROR: Daemon not ready on :9090") - sys.exit(1) + restart_daemon() + # Initial health check already covered by restart_daemon save_configs() print(f"Rename bench: {runs} runs × {len(CONDITIONS)} conditions = {runs * len(CONDITIONS)} sessions") @@ -239,6 +253,7 @@ def run_condition(cond, run_idx): order = list(CONDITIONS) random.shuffle(order) for cond in order: + restart_daemon() # flush response cache between conditions label = f"[r{ri}] {cond['label']}" print(f" {label}: ", end="", flush=True) t0 = time.time() From a5771f5b2c6d34d89a79aa964bb24c0d7d24b1c9 Mon Sep 17 00:00:00 2001 From: alderpath Date: Sat, 20 Jun 2026 13:42:43 +0100 Subject: [PATCH 2/2] feat: healEdit default off (opt-in via RELIARY_FEATURES=+healEdit) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Heal pipeline (cargo test on every edit) adds 30s+ wall time per session for 5% edge-case protection. Daemon-side guard (check_diff against FTS5 index) already catches hallucinated identifiers at 2ms overhead — the grammar-free, low-maintenance edit safety. Users who want subprocess verification: RELIARY_FEATURES=+healEdit --- crates/reliary-agent/pi/gate.js | 2 +- pi/gate.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/reliary-agent/pi/gate.js b/crates/reliary-agent/pi/gate.js index 6344117..7d8eb26 100644 --- a/crates/reliary-agent/pi/gate.js +++ b/crates/reliary-agent/pi/gate.js @@ -79,7 +79,7 @@ try { // ── Feature flags ── // Each can be disabled via RELIARY_FEATURES env var (e.g. "-healEdit,-convWindow") const FEATURES = { - healEdit: true, // route edit/write/sed through heal-apply + healEdit: false, // route edit/write/sed through heal-apply (+healEdit to enable) compress: true, // inline reasoning compression convWindow: true, // drop old verbose tool results readEnrichment: true, // compress non-target read results diff --git a/pi/gate.js b/pi/gate.js index d7c634b..f3513db 100644 --- a/pi/gate.js +++ b/pi/gate.js @@ -79,7 +79,7 @@ try { // ── Feature flags ── // Each can be disabled via RELIARY_FEATURES env var (e.g. "-healEdit,-convWindow") const FEATURES = { - healEdit: true, // route edit/write/sed through heal-apply + healEdit: false, // route edit/write/sed through heal-apply (+healEdit to enable) compress: true, // inline reasoning compression convWindow: true, // drop old verbose tool results readEnrichment: true, // compress non-target read results