Repository navigation
Description
Problem
The daemon operates without essential safety mechanisms. Without periodic WAL checkpointing, WAL could grow. Without pending-dict eviction, the watcher leaks memory. Without cursor pruning, old file rows remain forever. Without periodic rescan, inotify misses are never reconciled. Worker timeouts for stuck parse jobs. Bounded _pending dict with eviction.
Deep audit (2026-05-03, ~65 subagents) found concrete file:line evidence for all of these and additional gaps.
Connection profile bypasses (14 sites)
Every bare sqlite3.connect() without WRITE_CONNECTION_PRAGMA_STATEMENTS (WAL, busy_timeout=30s, foreign_keys=ON, cache_size=128MiB, mmap=1GiB, synchronous=NORMAL):
Severe (read-write on main archive, all pragmas missing):
write_gateway.py:120— dead code (ArchiveWriteGateway never instantiated), but severe if wiredreset.py:44,62,145— 3 sites in reset commandblob_gc.py:141— GC operations without busy_timeoutsampling_db.py:163,274— schema samplingcorpus.py:229— validation with conditional writessqlite_vec_runtime.py:24— missing 7 of 9 pragmasdaemon/cli.py:39— FTS startup check, no busy_timeout
WAL checkpoint
- Only
wal_autocheckpoint=10000(~40 MiB). No periodic/forced checkpoint. - One manual
PRAGMA wal_checkpoint(TRUNCATE)inrepair.py:915, never called automatically. - No checkpoint on connection close — unclean shutdown leaves up to 40 MiB in WAL.
GC lease mechanism non-functional
blob_gc.py:47 queries pending_blob_refs for lease safety but NO code inserts into this table. _has_active_lease() always returns False. GC could delete blobs mid-ingest. MIN_AGE_S=60 and generation tracking are defense-in-depth but the primary mechanism is non-functional.
Pidfile lifecycle
daemon/cli.py:53-64: pidfile written, never cleaned up on ANY exit path (no finally, no atexit, no SIGTERM handler)- No flock/advisory lock — TOCTOU race on simultaneous starts
- No process identity verification — only
os.kill(pid, 0), any process with that PID blocks daemon start - Status command never reads pidfile — cannot report daemon liveness
Daemon silence
- Zero
logger.info()calls in entirepolylogue/daemon/directory - HTTP access logs explicitly suppressed (
daemon/http.py:41-42, no-oplog_message) configure_logging()never called at daemon startupfaulthandlernot installed at any entry point- No periodic heartbeat or progress reporting during watcher catch-up scan
Daemon shutdown fragility
_drain_tasks()(cli.py:119-121):asyncio.gather(return_exceptions=True)results never inspectedasyncio.gather()at cli.py:99,101 has no timeout — fully dependent on SIGINT→CancelledErrorawatchcan enter tight loop preventing cancellation_catch_up()has no stop-event check — startup/shutdown latency proportional to file count- Orphaned
_debouncedchild tasks (watcher.py:110) not cancelled at shutdown, access closed DB ThreadingHTTPServeruses non-daemon threads — stuck request blocks process exit
Acceptance criteria
- All 14 connection sites route through
connection_profile.pyfactories. Linter rejects baresqlite3.connect()in production code. - Periodic WAL checkpoint in daemon loop (every 5 min or after N writes). WAL checkpoint on daemon shutdown.
- GC lease populated:
pending_blob_refsinserted before ingest, removed after success. - Pidfile cleaned on exit. Advisory flock. Process identity verified via /proc/PID/cmdline.
- Daemon logs startup, shutdown, periodic health. faulthandler installed.
-
_drain_tasksinspects results.gatherhas timeout._catch_upchecks stop event. -
_debouncedchild tasks tracked and cancelled at shutdown. Non-daemon threads avoided or timed out. - Cursor pruning: old
source_file_cursorrows cleaned up. - Pending dict bounded with eviction.
- Worker timeouts for stuck parse jobs.
Ref: deep audit C2, C4, P3-7, 3a, 3b, 4b. Ref #730, #778 (closed, consolidated here).
Activity
Sinity commentedon May 3, 2026
Concrete findings from deep audit (2026-05-03)
15 subagents analyzed connection profiles, WAL behavior, and daemon operational safety. Key additions to this issue:
Connection profile bypasses (14 sites)
Every bare
sqlite3.connect()site without WRITE_CONNECTION_PRAGMA_STATEMENTS:write_gateway.py:120— dead code (never instantiated), but would be severe if wiredreset.py:44,62,145— 3 sites, all zero-pragmablob_gc.py:141— GC operations without busy_timeoutsampling_db.py:163,274— schema sampling, no busy_timeoutcorpus.py:229— validation, no pragmassqlite_vec_runtime.py:24— vector operations, missing 7 of 9 pragmasdaemon/cli.py:39— FTS startup check, no busy_timeoutinsights/storage.py:77,daemon/events.py:44,live/cursor.py:73— separate DBs, minimal pragmastail_overlay.py:33-34— transient, acceptableWAL checkpoint
wal_autocheckpoint=10000(40 MiB) — no periodic/forced checkpointPRAGMA wal_checkpoint(TRUNCATE)inrepair.py:915, never called automaticallyBusy timeout gaps
Specific fix targets
connection_profile.pyhas the canonical profiles — route ALL connections through themfix(daemon): operational safety — WAL checkpoint, pidfile, logging, G…
Sinity commentedon May 4, 2026
Resolved by PR #789. WAL checkpoint, pidfile with flock+cleanup, structured logging, faulthandler, GC leases populated, drain timeout 5.0s.
Sinity commentedon May 4, 2026
Post-close check (2026-05-04)
Re-verified the daemon code against the features claimed in this issue:
Confirmed present:
_periodic_wal_checkpoint()in cli.py, runs every 5 min ✓_acquire_pidfile()+_verify_pidfile()via fcntl.flock ✓_drain_tasks()with 5s timeout ✓Not found in current daemon code:
live_cursorrows_pendingdict or LRU eviction in watcherIf these were implemented differently than expected (e.g., cursor pruning happens implicitly, rescan isn't needed because inotify is reliable on this filesystem), a brief note on the implementation choice would help future readers.
Ref: #830 (daemon ops — remaining hardening items)
fix(daemon): operational safety — WAL checkpoint, pidfile, logging, G…
Sinity commentedon May 8, 2026
Reopened during the closed-issue audit.
The post-close check on this issue explicitly found missing operational-safety items after the original "resolved" comment: cursor pruning, bounded pending-path eviction, periodic rescan for missed filesystem events, and worker timeouts for stuck parse jobs. Current grep still shows an unbounded
_pending_pathsset in the live watcher and no obvious pruning/rescan owner.WAL checkpoint, pidfile locking, and drain timeout can remain marked done; keep this issue open for the remaining daemon operational-safety items unless they are split into narrower issues.
Sinity commentedon May 8, 2026
Closing: core implementation landed. Remaining edges are incremental.