zrocks — Project Report

Porting RocksDB to a pure Zig 0.16 LSM engine · Branch main · Window 2026-05-28 → 2026-05-30 CEST · 278 commits · 36 milestones + 8 migration branches · 529 tests green · real librocksdb v11.4.0 opens the output
Two reports folded into one page: Part I — the whole project, then Part II — a deep-dive on the final RocksDB-only migration.

The goal & what was built

The whole project is the migration: re-implement RocksDB as a pure-Zig 0.16 LSM key-value engine, built bottom-up under strict TDD, and finish by making byte-exact RocksDB the only on-disk format zrocks emits — proven by having a real librocksdb v11.4.0 binary open zrocks's flush, compaction, range-delete and WAL output through a verify_open oracle.

The result is a working, durable, crash-recoverable, leveled-compacting LSM store with a CLI: foundation (slice/status/coding/comparator/arena/CRC32C/options) → Env over std.Io → WAL · skiplist · memtable · WriteBatch → block-based SST (builder/reader, bloom, footer) → LRU cache → iterators → VersionEdit/VersionSet/MANIFEST → recovery → flush + leveled/universal/FIFO compaction → snapshots → column families, merge operator, prefix seek, compaction filter, range delete, transactions, checkpoints → then the format migration to byte-exact RocksDB.

278
Commits
151 / 126 / 1 per day
36 + 8
Milestones + migration branches
Phases 0–7, then RocksDB-only
529
Tests green
oracle OPEN_OK count=34
59
Zig files
≈31,970 lines
1.22 B
Total tokens processed
incl. cache reads
4.48 M
Output tokens generated
+0.20M input, 43.4M cache-create
121
Subagent runs
43 direct + 78 workflow
4
Orchestrated workflows
6,383 total tool calls

Timeline

Times are CEST. Blue = core engine build (Phases 0–7); violet = RocksDB-only format migration.

Token usage

Across all 125 transcripts (1 main session + 3 helper sessions + 121 subagent/workflow runs). Cache reads dominate because every agent turn re-reads its cached context cheaply; the real generation cost is the output column. "Total" sums input+output+cache-create+cache-read.

ModelOutputInputCache createCache readTotalRole
claude-opus-4-74,115,123145,34137,685,1491,070,637,4621,112,583,075Primary driver — orchestration + all coding subagents
claude-sonnet-4-6351,66847,6285,661,202102,440,903108,501,401Lighter-weight subagent work
claude-opus-4-810,2087,87669,667308,802396,553Reporting sessions (this report)
All4,476,999200,84543,416,0181,173,387,1671,221,481,029

By day

DayOutput tokensCache readTool callsAgents spawned
2026-05-282,748,676
550,233,8482,58939
2026-05-291,675,993
618,047,5263,7354
2026-05-3069,896
5,490,851630

Day 1 (28th) built the entire Phases 0–7 core; day 2 (29th) drove the most tool-heavy work — read-interop tooling plus the RocksDB-only migration.

Tool usage

ToolCalls
Bash3,321
Read1,570
Edit1,040
Write128
StructuredOutput115
TaskUpdate84
Agent43
TaskCreate42
ToolSearch · Monitor · Workflow · EnterWorktree · …≤14 ea
6,383 tool calls in total.
531 ran in the main orchestration session; 5,852 (92%) ran inside subagents — the coding happened in delegated agents, as the workflow intended.

The Bash/Read/Edit shape is the TDD loop: run zig build test, read the failure, edit, repeat. StructuredOutput calls are workflow agents returning validated JSON (design verdicts, migration findings). 43 Agent spawns + 4 Workflow runs drove 121 subagent transcripts.

Tool failure analysis

128 errored tool results out of 6,383 — an overall 2.0% failure rate. Breakdown by tool and by cause below.

By tool

ToolErrorsCallsRate
StructuredOutput4011534.8%
EnterWorktree44100%
Monitor11010.0%
Bash653,3212.0%
Edit151,0401.4%
Write11280.8%
Read21,5700.1%

By root cause

CategoryCount
Schema-mismatch / transient / misc (mostly StructuredOutput retries + "model temporarily unavailable")76
Bash: command / Zig compile error (the expected red side of TDD)31
File not found / EISDIR13
Edit: stale read or non-unique match6
Permission / denied2

What the failures actually were

Reading the rate: of 128 errors, the large majority are designed-in — TDD red builds, schema-validation retries, and a harness guardrail. Subtracting those, genuine unexpected tool failures (stale edits, wrong path, EISDIR, transient model unavailability) number roughly ~25, i.e. well under 0.5% of all tool calls. The agent recovered from every one without losing milestone progress. Part II reports the migration phase's own failure ledger: 0 subagent retries.

Process: TDD cadence & orchestration

Commit shape

PrefixCommits
feat75
Merge (per-milestone --no-ff)75
test54
chore37
refactor31
fix / docs5

61 commits say "red", 51 say "green" — the literal failing-test-first / make-it-pass rhythm of every milestone.

Agent orchestration

A single main session acted as orchestrator; nearly all code was written by delegated subagents, one per milestone, mostly in isolated git worktrees. Four deterministic workflows structured the bigger fan-outs:

  • execute-roadmap — drove the Phase 0–7 milestone build
  • next-directions — post-core roadmap exploration
  • rocksdb-only-migration-design — design + adversarial verification of the migration
  • rocksdb-only-execute — milestone-by-milestone, each gated by verify_open

43 direct Agent spawns + 78 workflow-launched agents = 121 subagent transcripts.

Part II · Deep-dive

The final RocksDB-only format migration

Window 2026-05-29 18:38 → 23:52 CEST (5h 14m wall clock) · 2 sequential workflows, 28 subagents · 9 / 9 milestones merged · oracle OPEN_OK count=34 · 529 tests green

This is the last phase of the timeline above, examined on its own. Goal: make byte-exact RocksDB the only on-disk format zrocks emits, delete every native/“clean” write path, and prove it by having a real librocksdb v11.4.0 binary open the output via a widened verify_open oracle that exercises point-Get, Seek+range-scan, and absent-key checks.

Headline numbers

2,653,408
total tokens
5h 19m
workflow CPU time
28
subagents
1,681
tool calls (subagents)
9 / 9
milestones merged
17 files
+1,320 / −1,810 LoC
21
commits to main
0
subagent retries

Token total = design workflow (1,581,977) + execute workflow (1,071,431). Wall clock (5h 14m) < workflow CPU time (5h 19m) because the design phase had agents running in parallel.

Two-phase structure

PhaseWorkflowStartedDuration AgentsTokensTool callsStatus
1. Design + verifyzrocks-rocksdb-only-migration-design17:22 UTC 41.5 min191,581,977613 completed
2. Executezrocks-rocksdb-only-execute18:05 UTC 278.2 min91,071,4311,068 completed

Phase 1 fanned out 9 design agents (one per format component) and 9 adversarial verifiers in parallel, then a single synthesizer produced the sequenced plan (28 min, 183 k tokens by itself). Phase 2 ran the 9 plan milestones sequentially on the shared repo (each had to commit before the next started, because they all touch src/format/ and src/db/).

Per-milestone breakdown (execution phase)

#MilestoneCommitModelDuration TokensTool callsTests afterOracle
1oracle-widen
widen verify_open to Get+Seek+absent-key
d3c39a6sonnet‑4‑626:4048,65249530OPEN_OK 11
2properties-always
emit full 29-field RocksDB v11 table-properties
94ae493opus‑4‑715:0183,32545530OPEN_OK 11
3sst-default-flip
delete sst_output enum + native single-level index + native finish path
33d7b6fopus‑4‑741:39204,807137524OPEN_OK 11
4manifest-rocksdb-exact
compaction emits kNewFile4 (tag 103) with min/max seqnos — fixed latent bug
26a9639opus‑4‑715:19111,70555525OPEN_OK 8
5filter-rocksdb-only
FastLocalBloom full filter in every SST; drop block-based-bloom write path
22a3afeopus‑4‑722:19113,679101525OPEN_OK 11
6range-del-rocksdb
emit/read range tombstones in rocksdb.range_del meta-block format
4c6e3fbopus‑4‑728:35111,88662528OPEN_OK 5
7wal-writebatch-cf
replace kColumnFamilyTag=0x10 with RocksDB CF value-type bytes (0x4/0x5/0x6/0xE)
b13f6a2opus‑4‑737:12160,351414532OPEN_OK 11
8partitioned-index-drop
delete partitioned_index.zig (373 LoC); drop Options.IndexType
55f0668sonnet‑4‑638:18119,790107528OPEN_OK 11
9remove-native-and-tests
final sweep: SharedManifest.writeSnapshot emits kNewFile4
aba5a2bopus‑4‑753:05117,23698529OPEN_OK 34

Oracle column = result of /home/ghpu/rocksdb-interop/verify_open <db> on the milestone’s gate fixture (a full flush+compaction+range-del+WAL DB). Intermediate dips to 5 / 8 are expected — each step proves its own component opens in isolation while later steps still emit native formats for the others. The final 34 means the final fixture is richer (more keys + multi-level + tombstones) and reads end-to-end.

Tool usage (migration)

Across all 28 migration subagents.

ToolCallsShare
Bash (zig build, git, grep, oracle)1,083
Read401
Edit104
StructuredOutput (schema-bound return)69
Write10
Monitor9
ToolSearch3
TaskStop2

Read/Edit/Bash dominance is the signature of strict TDD on a Zig codebase: read the file, write a red test, build, edit, build, run the oracle. Almost no Write (large new files) — the migration is mostly deletion.

Model mix (migration)

ModelAgentsTokens
claude-opus-4-7171,910,733
claude-sonnet-4-611878,675

Sonnet 4.6 handled the 9 design agents (broad-but-shallow assessment) and 2 execute steps with narrow, well-specified scope (oracle-widen, partitioned-index-drop). Opus 4.7 handled all adversarial verifiers, the synthesizer, and 7 of 9 execute milestones — everywhere the work touched contended core files (db.zig, compaction.zig, table_builder.zig).

Resulting diff

17 files changed
+1,320 insertions
-1,810 deletions
net −490 LoC
21 commits to main

Net negative LoC despite adding RocksDB format features — because nine entire native/“clean” write paths were deleted in the process.

Failure analysis (migration)

The migration completed with 0 retries and 0 quarantined milestones. Every one of the 28 subagents finished on its first attempt; every one of the 9 execute milestones merged to main. The execute workflow’s pre-commit gate (full zig build test + the real-RocksDB verify_open oracle) was the safety net that made retries unnecessary — an agent that broke the gate would have been quarantined and its dependents skipped, but none did.

EventWhereOutcome
Latent bug discovered mid-flight Milestone 4 (manifest-rocksdb-exact) Fixed in-band. Before the migration, compaction.zig:commitCompaction emitted compaction outputs via addFile (legacy kNewFile=7, no seqnos). This wasn’t caught earlier because no test exercised compaction after a multi-level fill. The milestone’s red test surfaced it; the same milestone’s green commit (4d0f04b) fixed it by switching to addFile4 with real min/max seqnos.
Oracle count regression at milestone 6 range-del-rocksdb (OPEN_OK 5) Expected. The narrower fixture used by intermediate gates only carries 5 live non-tombstoned keys; the gate’s contract is “real RocksDB opens it,” not a fixed count. The next milestone’s richer fixture lifted it back to 11, and the final milestone’s end-to-end DB hit 34.
2x TaskStop in subagent traces Execute phase (long-running background zig build jobs) Cooperative. Both were agent-initiated stops of own background zig build test jobs after a faster path produced the answer — no test was abandoned.
Subagent retries — 0 / 28 — every agent reported attempt=1, state=done.

What the migration deleted

Evidence on disk (post-migration)

$ zrocks /tmp/demo put keyN value-from-zrocks-N   # via the zrocks CLI
$ ls /tmp/demo
000002.log  CURRENT  MANIFEST-000003

$ /home/ghpu/rocksdb-interop/verify_open /tmp/demo   # the REAL librocksdb binary
OPEN_OK count=10
key0=value-from-zrocks-0
…
key9=value-from-zrocks-9

Plus the CI self-consistency gate tests/rocksdb_write_interop_test.zig, which on every zig build test asserts on the raw bytes that footer is format_version=5 / crc32c, metaindex carries rocksdb.properties, and MANIFEST uses kNewFile4 with no stray kColumnFamilyAdd.

Generated 2026-05-30 by Claude Opus 4.8 (1M context). Part I sources: 278 git commits on main; 125 session transcripts (≈44 MB) under the project's Claude history; DEVSTATE.md. Token figures are exact sums of per-message usage; failure analysis counts tool_result blocks with is_error. Part II sources: the design + execute workflow journals (wf_19b0a837-1b4, wf_d94d13f7-c95), 28 subagent traces, and git log bf8bc96..aba5a2b. All times CEST unless suffixed UTC.