Skip to content

fix(daemon): reduce memory footprint, fix LLM crash, fix DB lock contention#83

Merged
ashu17706 merged 3 commits into
mainfrom
fix/daemon-footprint-and-locking
Jul 25, 2026
Merged

fix(daemon): reduce memory footprint, fix LLM crash, fix DB lock contention#83
ashu17706 merged 3 commits into
mainfrom
fix/daemon-footprint-and-locking

Conversation

@ashu17706

Copy link
Copy Markdown
Contributor

Summary

  • Daemon was leaking a fresh LlamaCpp/Llama backend on every ingest flush (never disposed), causing multi-GB RSS spikes and a recurring LlamaGrammar ... different Llama instance crash (~404 occurrences observed in a 24-day-old daemon.log, roughly 1 in 8 flushes) traced to the fire-and-forget expandQuery() auto-enrich call racing across overlapping flush cycles.
  • closeDb()/closeQmdStore() now explicitly dispose the LLM backend on close instead of leaving it to the 5-min inactivity timer; the daemon now defaults SMRITI_INGEST_NO_ENRICH=1 so routine ingest never triggers LLM work as a side effect (opt back in via enrichOnIngest: true); daemon flushes are now serialized (verified: overlapping construct/dispose of LlamaCpp/Llama instances can abort the process with a native GGML_ASSERT in ggml-metal, since the shared _db/_store singletons were never safe to touch concurrently).
  • Added PRAGMA busy_timeout=5000 — reproduced a real database is locked failure between the daemon and a manual smriti ingest --force writing to the same SQLite file at once; this makes concurrent writers retry briefly instead of failing instantly.
  • scripts/monitor-resources.ts (resource-usage sampler used to verify all of the above) had its own bug: child.exited was observed to never resolve even after the spawned process had fully exited, hanging the wrapper indefinitely. Fixed with an independent pid-liveness watchdog raced against the real exit promise.

Verification

  • Full test suite: 373/373 passing, including two new cases in test/daemon-runner.test.ts (enrich env var default + override) and a new test/store.test.ts (LLM dispose behavior).
  • Live-verified against the actual running daemon: restarted it, triggered real flushes via the socket poke path, confirmed zero new LlamaGrammar errors post-fix (previously ~1 in 8 flushes).
  • Live-verified the lock fix with a full forced re-ingest of 403 real sessions (51k messages) while the daemon was concurrently restarting — zero new database is locked errors, versus one reproduced pre-fix.

Test plan

  • bun test --cwd ./test — 373 pass, 0 fail
  • Manual: restart daemon, trigger flushes via socket poke, confirm no LlamaGrammar errors in daemon.log
  • Manual: smriti ingest claude --force while daemon runs concurrently, confirm no database is locked errors
  • Manual: bun run monitor exec -- <cmd> completes and exits cleanly instead of hanging

@ashu17706
ashu17706 force-pushed the fix/daemon-footprint-and-locking branch from e7bdb53 to 1375369 Compare July 25, 2026 03:29
… commit in range

run()'s .trim() stripped the trailing %x09 of the oldest commit in a
range whenever that commit had an empty body, dropping it below the
3-field threshold in parseCommit() and silently excluding it from
commit_count/release notes. Confirmed this already affected v0.8.1's
published notes (missing fix(ci): scope test runs to smriti suite).
getCommits() now only strips trailing newlines, not the whole output.
@ashu17706
ashu17706 force-pushed the fix/daemon-footprint-and-locking branch from 1375369 to e49a798 Compare July 25, 2026 03:35
@ashu17706
ashu17706 merged commit f83c7ca into main Jul 25, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant