LedgerMind 3.0 3.3.2: How We Turned 'It Works' into 'It Works Brilliantly'

Published: (March 14, 2026 at 06:15 PM EDT)
8 min read
Source: Dev.to

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

Metricv3.0v3.3.2Change
Search (OPS)~2 0005 500++175 %
Write (latency)~500 ms14 ms‑97 %
Commits between versions497😅
Critical bugs in productionHad themZero 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.

  1. First agent checks – no conflicts.
  2. Second agent checks – no conflicts.
  3. First agent writes.
  4. 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 locked

What 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.pid for 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

PhaseMeaning
PATTERNThe system noticed a repeating event
EMERGENTThe pattern confirmed itself several times
CANONICALThis 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 automatically

This 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

ClientAutomation Level
VS CodeHardcore – shadow context, terminal, chats
Claude CodeFull – auto‑record + RAG
CursorFull – auto‑record + RAG
Gemini CLIFull – 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_id validation 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
-- 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?

  1. SQLite WAL write
  2. Git commit for cryptographic audit
  3. Vector embedding generation
  4. Link‑count updates

All of this fits into 8 operations per second. For comparison, v3.0 managed ~2 OPS.

How?

  • Deferred VectorStore loading
  • Splitting transactions into proposals
  • Path‑validation caching

Mobile Support (Termux)

LedgerMind now runs on Android via Termux, using a 4‑bit quantized model.

MetricMobile (GGUF)Server (MiniLM)
Search (latency)0.13 ms0.05 ms
Write (latency)142.7 ms14.1 ms
Search (OPS)5 15311 019

Why? Because sometimes you need to prototype on the go. And because we can.


Bug‑Fixes & Improvements

SymptomCauseFix
Merging duplicates returned ≥ 2 targetsGroup‑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 PATTERNsThe 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 disappearedSQL 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 workers

TL;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 management

Why?
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_languagenow enrichment_language
  • arbitration_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

CategoryDetail
PerformanceWrites are 35× faster (500 ms → 14 ms)
ReliabilityRace conditions and DB locks fixed
FeaturesDecisionStream, Trajectory Reflection, Zero‑Touch for Gemini
SecurityBandit vulnerabilities patched
MigrationAutomatic, non‑destructive

Getting Started

Backup

ledgermind-mcp run --path /path/to/v3.0/memory

Upgrade

pip install --upgrade ledgermind

Initialize

ledgermind init

Feature Roadmap (Confidence & Evidence)

FeatureConfidenceEvidence
Real‑time collaboration (CRDT)MediumMulti‑agent namespacing groundwork
Cloud hostingMediumDocker + REST gateway ready
Knowledge‑graph visualizationHighDecisionStream ontology enables graph queries
LangChain / LlamaIndex integrationHighMCP 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";
}
0 views
Back to Blog

Related posts

Read more »

Jemalloc un-abandoned by Meta

- Meta recognizes the long‑term benefits of jemalloc, a high‑performance memory allocator, in its software infrastructure. - We are renewing focus on jemalloc,...

Meta’s renewed commitment to jemalloc

Meta recognizes the long‑term benefits of jemalloc, a high‑performance memory allocator, in its software infrastructure. We are renewing focus on jemalloc, aimi...