LedgerMind 3.0 3.3.2: How We Turned 'It Works' into 'It Works Brilliantly'
Source: Dev.to
Spoiler: 497 commits, three sleepless nights with SQLite, and one very stubborn race condition that refused to die
Reading time: ~12 minutes · For: AI‑agent developers, architecture‑drama enthusiasts
If you missed the last few months of LedgerMind’s life, here’s the short version: we took a system that in version 3.0 simply worked, and turned it into a system that works fast, reliably, and with elements of artificial intelligence.
Sounds like marketing bullshit? I get it. So let’s jump straight to the facts.
Metrics
| Metric | v3.0 | v3.3.2 | Change |
|---|---|---|---|
| Search (OPS) | ~2 000 | 5 500+ | +175 % |
| Write (latency) | ~500 ms | 14 ms | ‑97 % |
| Commits between versions | — | 497 | 😅 |
| Critical bugs in production | Had them | Zero now | 🎉 |
But let’s start from the beginning. Because behind these numbers lies a real engineering drama.
The Problem: A Classic TOCTOU Race
Two agents simultaneously decide to write a decision for the same target.
- First agent checks – no conflicts.
- Second agent checks – no conflicts.
- First agent writes.
- Second agent writes.
Boom. Metadata corrupted.
“This rarely happens,” someone said.
“Rarely isn’t never,” replied CI/CD at 3 AM.
Fix
- Real ACID transactions with
BEGIN IMMEDIATE - A global lock registry
- Automatic stale‑lock cleanup after 10 minutes
Now you can run ten agents on one project – they’ll figure it out.
SQLite & Concurrency
SQLite is wonderful—until you try to write to it from a background worker and a user request simultaneously. Then it becomes… less wonderful.
sqlite3.OperationalError: database is lockedWhat we tried (and failed)
- ❌ Increasing timeouts (didn’t help)
- ❌ Adding retry logic (helped, but hacky)
- ❌ Praying to database gods (didn’t work)
What finally worked
- Split enrichment batches into per‑proposal transactions
- Use
worker.pidfor detecting stuck workers - Automatic stale‑lock cleanup
Result: the background worker now runs every 5 minutes and users don’t even notice it exists. As it should be.
Knowledge Lifecycle: PATTERN → EMERGENT → CANONICAL
| Phase | Meaning |
|---|---|
| PATTERN | The system noticed a repeating event |
| EMERGENT | The pattern confirmed itself several times |
| CANONICAL | This is no longer just an observation, it’s truth |
LifecycleEngine manages transitions automatically. You do nothing – the system decides when knowledge has “grown up.”
Why? After a month of operation you accumulate hundreds of decisions. You want to see current ones in search, not those you wrote on day 1 and forgot.
Favorite feature of v3.3
Before: you record decisions, the system stores them.
After: the system analyzes sequences of your decisions and identifies thinking patterns.
# You just record decisions
memory.record_decision("Use PostgreSQL", target="db")
memory.record_decision("Add JSONB", target="db")
memory.record_decision("Migrations via Alembic", target="db")
# The system notices the pattern:
# "When user builds API → PostgreSQL + JSONB + Alembic"
# And next time will suggest this stack automaticallyThis isn’t magic. It’s the Trajectory‑based Reflection Engine, which builds graphs of your decisions and finds repeating paths in them.
Integration & Automation Levels
| Client | Automation Level |
|---|---|
| VS Code | Hardcore – shadow context, terminal, chats |
| Claude Code | Full – auto‑record + RAG |
| Cursor | Full – auto‑record + RAG |
| Gemini CLI | Full – auto‑record + RAG |
What does this mean in practice?
You don’t think about LedgerMind at all. It just works.
- Before every LLM request, the system injects context from memory.
- After every response – it writes the result automatically.
You work as usual. The system works for you.
Search Slow‑down & Fix
Early in v3.3 development we noticed search slowed from ~4 000 OPS to ~2 000 OPS.
- Cause: added
linked_idvalidation for connections between events and decisions. Every search performed a full table scan. - Fix:
- Index on
linked_id - Fast‑path heuristics for simple queries
- Metadata batching
- Index on
-- Before: slow JOIN without index
SELECT * FROM decisions WHERE linked_id IN (...);
-- After: fast lookup by index
CREATE INDEX idx_linked_id ON episodic_events(linked_id);Result:
- 5 500+ OPS for semantic search
- 14 000+ OPS for keyword‑only search
Write Path: What Happens When You Write a Decision?
- SQLite WAL write
- Git commit for cryptographic audit
- Vector embedding generation
- Link‑count updates
All of this fits into 8 operations per second. For comparison, v3.0 managed ~2 OPS.
How?
- Deferred
VectorStoreloading - Splitting transactions into proposals
- Path‑validation caching
Mobile Support (Termux)
LedgerMind now runs on Android via Termux, using a 4‑bit quantized model.
| Metric | Mobile (GGUF) | Server (MiniLM) |
|---|---|---|
| Search (latency) | 0.13 ms | 0.05 ms |
| Write (latency) | 142.7 ms | 14.1 ms |
| Search (OPS) | 5 153 | 11 019 |
Why? Because sometimes you need to prototype on the go. And because we can.
Bug‑Fixes & Improvements
| Symptom | Cause | Fix |
|---|---|---|
| Merging duplicates returned ≥ 2 targets | Group‑size validation happened after transaction start, after data was partially modified. | Validate group size before transaction; randomize candidates to prevent infinite merge loops. |
CANONICAL knowledge ranked lower than fresh PATTERNs | The vitality field needed for lifecycle ranking wasn’t loaded in the search fast‑path. | Add vitality calculation to fast‑path; fix transitions in LifecycleEngine. |
| Worker processed the same proposals repeatedly; tokens/time disappeared | SQL query didn’t exclude already‑processed records. | Add enrichment_status field with pending → completed transition; add stuck‑record detection. |
Architecture Refactor
Before: one huge Memory class (~2 000 lines).
After: nine specialized services:
Memory (coordinator)
├── EpisodicStore # short‑term events
├── SemanticStore # long‑term knowledge
├── VectorStore # embeddings
├── LockRegistry # global lock handling
├── TransactionMgr # ACID transaction orchestration
├── LifecycleEngine # knowledge phase transitions
├── SearchEngine # fast‑path & semantic search
├── AuditLog # Git‑based cryptographic audit
└── WorkerPool # background enrichment workersTL;DR
- +175 % search throughput, ‑97 % write latency.
- 497 commits, 0 critical bugs in production.
- Real ACID transactions, global lock registry, stale‑lock cleanup.
- Knowledge now evolves automatically (PATTERN → EMERGENT → CANONICAL).
- Full‑stack integration (VS Code, Claude Code, Cursor, Gemini CLI).
- Mobile support via Termux.
That’s the story of how LedgerMind went from “it works” to “it works fast, reliably, and intelligently.” 🚀
decisions + Git
├── VectorStore # embeddings
├── ConflictEngine # conflict detection
├── ResolutionEngine # supersede validation
├── DecayEngine # pruning old data
├── ReflectionEngine # pattern discovery
└── LifecycleEngine # phase managementWhy?
Each component can be tested, optimized, and replaced independently. When a new developer arrives in six months, they won’t run away in horror.
Changes Made
preferred_language→ nowenrichment_languagearbitration_mode→ replaced with intelligent conflict resolution- Lite mode → completely cut from the architecture
Why does this matter?
Less dead code = fewer bugs = fewer questions like “what does this setting do?”.
Benefits
| Category | Detail |
|---|---|
| Performance | Writes are 35× faster (500 ms → 14 ms) |
| Reliability | Race conditions and DB locks fixed |
| Features | DecisionStream, Trajectory Reflection, Zero‑Touch for Gemini |
| Security | Bandit vulnerabilities patched |
| Migration | Automatic, non‑destructive |
Getting Started
Backup
ledgermind-mcp run --path /path/to/v3.0/memoryUpgrade
pip install --upgrade ledgermindInitialize
ledgermind initFeature Roadmap (Confidence & Evidence)
| Feature | Confidence | Evidence |
|---|---|---|
| Real‑time collaboration (CRDT) | Medium | Multi‑agent namespacing groundwork |
| Cloud hosting | Medium | Docker + REST gateway ready |
| Knowledge‑graph visualization | High | DecisionStream ontology enables graph queries |
| LangChain / LlamaIndex integration | High | MCP protocol compatibility |
Reflections on v3.3 Development
“When we started v3.3, I thought: ‘A few features, some optimizations, release in a month.’”
Reality: 497 commits, three critical bugs in production, one night debugging SQLite locking, and lots of coffee.
But seeing search run at 5,500+ OPS, the background worker operating without a single lock, and the system automatically “understanding” patterns in decisions—it was worth it.
LedgerMind v3.3.2 isn’t just “a new version.” It’s a system you can trust.
Now go build something awesome.
Article written based on analysis of 497 commits between v3.0.0 and v3.3.2. The author didn’t sleep for two nights but will catch up tomorrow.
P.S. If you find a bug — open an issue. We’re fast. Promise.
P.P.S. You can watch the video tutorial on my X.com.
Dark‑Theme Tweet Embed (Optional)
var iframe = document.getElementById('tweet-2032901678538580120-188');
if (document.body.className.includes('dark-theme')) {
iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=2032901678538580120&theme=dark";
}