Repository navigation
State Database
Design stage. Nothing here is implemented.
One local SQLite database in WAL mode, at /var/minecraftai/shared/state.db. Accessed through GRDB from the engine process. Nothing else on the host touches it.
The engine has one continuous writer — the reconciliation loop — and a steady trickle of readers: every website request asking what is deployed, what is running, which mods are on 26.2.
In SQLite's default rollback-journal mode those block each other. A reader waits behind a write transaction, so a slow reconcile makes the website hang. WAL removes that: readers see a consistent snapshot and never block the writer, and the writer never blocks readers.
WAL still allows only one writer at a time, which is a constraint rather than a problem. It maps directly onto the engine's structure: a single actor owns the write path and everything else reads. That is the design the concurrency model wants anyway, so the database enforces something the code should be doing regardless.
PRAGMA journal_mode = WAL; -- persistent; set once on the file
PRAGMA synchronous = NORMAL; -- the correct pairing with WAL
PRAGMA busy_timeout = 5000; -- ms; without it, contention is an instant error
PRAGMA foreign_keys = ON; -- per connection, not per database
PRAGMA journal_size_limit = 67108864;Notes on each, because the defaults are wrong for this workload:
-
synchronous = NORMALis durable across an engine crash. It risks only the last transaction on an OS crash or power loss, which for mod bookkeeping is recoverable by re-running a reconcile.FULLcosts an fsync per commit and buys nothing worth having here. -
busy_timeoutmust be set explicitly. SQLite's default is zero — a contended write returnsSQLITE_BUSYimmediately rather than waiting. Nearly every "SQLite doesn't handle concurrency" complaint is this pragma being unset. -
foreign_keysis per connection. It reverts to off on every new connection unless set each time. GRDB does this by default; it is listed here so nobody removes it thinking it is redundant. -
journal_size_limitcaps the-walfile after checkpoint. Without it a burst of writes leaves a large WAL on disk indefinitely.
In GRDB this is a DatabasePool, which uses WAL and gives concurrent reads. DatabaseQueue serializes everything and would discard the benefit.
WAL mode creates state.db-wal and state.db-shm beside the main file. Both are part of the database.
Copying state.db alone produces a corrupt or stale snapshot. For a consistent backup:
VACUUM INTO '/var/minecraftai/shared/backups/state-20260823.db';This yields a single consistent file while the engine keeps running, with no locking of the live database. It replaces the file-copy approach, which is the standard way people silently lose data in WAL mode.
The database must live on local disk. WAL relies on shared memory between processes and does not work correctly on network filesystems.
| Area | Contents |
|---|---|
| Versions | The version table: Minecraft version, NeoForge build, port, role, sheet tab, state. The source of truth for what versions exist. |
| Mods | Per version: name, provider URLs, category, operator intent, protection flags. |
| Resolved files | The pinned file for each mod: filename, version, SHA-256, provider, resolution timestamp. |
| Modsets | Digests and their members — the lockfiles. |
| Validation runs | Verdicts against digests, timings, failure classification, pointers to retained logs. |
| Conflict graph | Proven incompatibility edges, scoped to mod versions and Minecraft version, with the run that proved each. |
| Deployments | Which digest went to which version, when, and on whose approval. |
| Sheet sync | Last reconcile per tab, last written values, so write-back is idempotent. |
- Jars live in the content store on disk, addressed by hash. A database is not a blob store, and hardlinking a row is not a thing.
- Logs stay as files. The database holds a path and a verdict, not megabytes of server output.
- Worlds, obviously.
The rule: the database holds facts and pointers. Anything large enough to matter lives on the filesystem with its hash or path recorded here.
GRDB's DatabaseMigrator, with each migration registered in order and applied at startup before the engine serves anything.
v1 kept numbered SQL migration files and that discipline was correct — the failure was that its schema.sql entrypoint referenced a path that did not resolve from the repository root, so the canonical way to apply them did not work. Migrations should be exercised by the test suite against a fresh database on every run, which turns that class of mistake into a test failure rather than a discovery during deployment.
Runtime code should never issue CREATE TABLE IF NOT EXISTS as a safety net. v1 did, and the result was two competing definitions of the schema — the migrations and the guards — that could drift apart silently.
Design stage — not implemented
Design
Validation
Trust
Interfaces
Operations
Project
Reference