Repository navigation
CodeDB 0.2.5864
Formalizes OpenPuffer and CodeDB memory-ownership and search/caching kernels in Lean 4 (lean-proofs/), eliminates mid-operation OOM memory leaks across HNSW insertion and search result builders, and cuts codedb_search latency by 40.4% (13.6µs → 8.1µs) and codedb_context latency by 58.0% (384.8µs → 161.8µs).
Lean 4 Formal Verification Suite (lean-proofs/)
Adds a self-contained Lean 4 proof suite (./lean-proofs/verify.sh, 373 finite state-cube checks via by native_decide and universal theorems with zero sorrys):
CodeDB/OpenPufferLifecycle.lean: Proves zero leaked layer allocations and exact 11-slab length conservation acrossplanInsert,appendRecord,publishInsert, andcommitInsertunder arbitrary allocation failure points.CodeDB/OpenPufferSearch.lean: Proves membership equivalence of sparse dirty-nodevisitedreset insearchLayer, zero heap allocations fordim ≤ 2048insearchAdvanced, and dual-accumulator SIMD dot-product equivalence invector.dot.CodeDB/SearchLifecycle.lean: Proves zero memory leaks on mid-loop OOM acrossSearchResult/SymbolResultbuilders,2 * Nfewer string allocations via zero-copy transfer insearchContentWithScope, partial-output rollback inrenderPlainSearch, and zero-allocationsymbol_indexnudges.CodeDB/SearchCache.lean: Proves observational equivalence of epoch-memoized environment fingerprints (cio.envEpoch+rankingEnvSnapshot), byte-budgeted LRU cache conservation, and post-lazy-init generation capture undermu.lockShared().
Memory Safety & Fault-Injected OOM Cleanups
- OpenPuffer (
vendor/openpuffer/src/hnsw.zig):planInsertzero-initializeslayersslots so mid-layer OOM frees all previously allocated neighbor slices.appendRecordrecords all 11 parallel slab lengths before appending and restores them viashrinkRetainingCapacityonerrdeferbefore updatingpublished.publishInsertandcommitInsertguardInsertPlanbuffers withdefer/errdefer p.discard(self.allocator).
- CodeDB (
src/explore.zig,src/warmup.zig):- Deep-free
errdeferblocks infindSymbol,findAllSymbols,searchContentUncached,searchContentRegex, andwarmup.topQueries. renderPlainSearchrolls backouttoout_startwhenrenderPlainSearchUncachedfalls through after writing the result header.- Paired with
std.testing.FailingAllocatorfault-injection unit tests invendor/openpuffer/src/hnsw.zigandsrc/test_search.zig.
- Deep-free
Search & OpenPuffer Latency Optimizations
- Epoch-memoized ranking environment snapshot (
src/cio.zig,src/explore.zig): Replaces 10 per-querygetenvscans and 18 Wyhash updates on every cached search with an atomicenv_epochcheck. - Zero-allocation symbol nudge (
src/explore.zig,src/mcp.zig):Explorer.renderSymbolNudgeinspectssymbol_indexdirectly undermu.lockShared()instead of allocating and freeingfindAllSymbolsslices on every identifier search. - Post-lazy-init cache generation capture (
src/explore.zig): Capturessettled_gen = self.search_gen.load(.acquire)undermu.lockShared()after lazy index builds (rebuildWordIndex,ensureSymbolIndex,ensureCallGraph,ensureCoChange) complete, eliminating false self-invalidation on Query #2 while preserving immediate invalidation on external mutations. - Fast non-git ancestor pre-check (
src/git.zig):hasGitAncestorchecks for.gitin-process before spawninggitingetGitHeadandbuildCoChange, avoiding a ~14msfork+execwhen querying directories outside a git repository. - OpenPuffer ANN search (
vendor/openpuffer/src/hnsw.zig,vendor/openpuffer/src/vector.zig): ReplacesO(N)visited.setRangeValue(0..capacity, false)per layer with sparse dirty-ID clearing, expands stack buffers insearchAdvancedfrom512to2048floats/int8s, and unrollsvector.dotinto dual 16-lane@Vector(16, f32)accumulators.
In-Process MCP Benchmark (zig build bench)
| Tool | v0.2.5863 Latency |
v0.2.5864 Latency |
v0.2.5863 Ops/sec |
v0.2.5864 Ops/sec |
Change |
|---|---|---|---|---|---|
codedb_search |
13.6µs |
8.1µs |
73,206 |
122,850 |
-40.4% latency / +67.8% ops/s |
codedb_context |
384.8µs |
161.8µs |
2,598 |
6,179 |
-58.0% latency / +137.8% ops/s |
codedb_tree |
3.1µs |
2.4µs |
317,460 |
401,606 |
-22.6% latency / +26.5% ops/s |
codedb_symbol |
3.1µs |
2.7µs |
319,489 |
366,300 |
-12.9% latency / +14.7% ops/s |
codedb_outline |
3.2µs |
2.9µs |
308,642 |
334,448 |
-9.4% latency / +8.4% ops/s |
codedb_deps |
200ns |
90ns |
5,000,000 |
11,111,111 |
-55.0% latency / +122.2% ops/s |
codedb_bundle |
16.5µs |
15.5µs |
60,459 |
64,267 |
-6.1% latency / +6.3% ops/s |