System of record
The GitHub repo (markdown + frontmatter) is the system of record. The Postgres/PGLite database is a derived cache. We do not back up the database — we rebuild it from the repo. This document is the canonical reference for that contract. Every code path that writes user-knowledge state should match the pattern described here. The CI gate atscripts/check-system-of-record.sh
enforces it programmatically.
Why this matters
The DB is a derived index over the markdown content. It exists to make search fast, to dedup embedding-similar claims, to materialize the cross-page graph. None of that data is irreplaceable — as long as the markdown is intact,modusbrain sync && modusbrain extract all rebuilds the
entire DB from scratch.
This means:
- Disaster recovery is one command. If your DB volume corrupts, if
Postgres eats itself, if PGLite’s WASM lock wedges — you don’t need
a backup. You wipe the DB, re-import from your brain repo, and the
derived state regenerates. v0.32.3 ships
modusbrain rebuild --confirm-destructiveas the documented one-liner. - Multi-machine sync is git. Your brain is a repo. Push from one machine, pull from another, and the second machine’s DB rebuilds on its next sync. No “back up the database” step.
- Privacy is in your hands. Sensitive entity pages can be
gitignored (via
modusbrain.ymldb_onlypaths or per-page) and they stay on disk but not in git. The fence respects whatever git tracking choice you make at the page level. - Cross-agent collaboration is possible. Multiple agents can write to the same brain because the fence is the merge point, not the DB. Git handles concurrent edits the way git handles concurrent edits.
The three categories
Every table in the modusbrain schema belongs to exactly one of three categories. The category determines how it gets rebuilt during disaster recovery.FS-canonical (markdown is the source of truth)
These are user-authored knowledge. The DB row is a derived index over the markdown — wipe the table andmodusbrain extract rebuilds it
identically. The CI gate keeps direct DB writes from drifting away
from the markdown contract.
Derived from FS but not user-authored
These hold derived state that’s automatically reconstructible from the markdown but not directly authored as markdown by the user. The chunker + embedder rebuild these on import.DB-only by design (named exceptions)
These hold runtime / infrastructure state that’s intentionally not in the repo. The architectural rule still holds — these aren’t “user knowledge” — but they’re DB-only by design.
A new derived table that holds user-knowledge MUST land FS-first.
If you’re tempted to add one as “DB-only for now,” the structural
question is: does it belong in this DB-only-by-design list? If not,
it’s FS-canonical and needs a fence (or frontmatter field) plus a
reconciler.
The privacy boundary
Private knowledge in a fence still lives in the markdown file. If the user commits the page to git, the private data lands in git too. This is the existing operational model — we don’t infer git policy. For untrusted readers (remote MCP, subagent), the v0.32.2 release ships a 3-layer strip:- Layer A (chunker):
src/core/chunkers/recursive.tscallsstripFactsFence({keepVisibility: ['world']})+stripTakesFencebefore chunking. Private fact text never reachescontent_chunks.chunk_text, embeddings, or search results. - Layer B (get_page): when
ctx.remote === true, the response body has both fences stripped (private rows from facts; entire takes fence). Local CLI (ctx.remote === false) sees the full fence. - Layer C (git tracking): the user decides whether to commit the
entity page.
modusbrain.ymldb_onlypaths are gitignored automatically; per-page choices via the user’s normal git workflow.
db_only in
modusbrain.yml. The file stays on disk but never lands in git.
The forget contract
modusbrain forget <id> and the MCP forget_fact op rewrite the fence
row with strikethrough + valid_until = today + context: "forgotten: <reason>". The DB’s expired_at = valid_until + now() derivation
reconstructs the forget state on every rebuild because the fence is
canonical.
Strikethrough has two semantics distinguished by context:
~~claim~~+context: "superseded by #N"→ row was replaced by a newer row in the same fence~~claim~~+context: "forgotten: <reason>"→ row was retracted via the forget op
extract_facts cycle wipes the DB row.
Disaster recovery
The promise the rule makes:test/e2e/system-of-record-invariant.test.ts
exercises this exact flow on every CI run.
Rule for new code
When you add a new user-knowledge category:- Define the markdown shape. Fence (
<!--- modusbrain:NAME:begin --> ... :end -->table) or frontmatter field. - Build a parser that produces structured data from markdown.
See
src/core/fence-shared.tsfor the shared primitives. - Build a writer that round-trips: parse + edit + render produces byte-identical markdown for identical input.
- Add the engine method that takes parsed data and stamps a derived table. The method gets an entry in the CI gate’s banned-direct-call list.
- Add a reconciler: a cycle phase that walks pages, parses the
fence, and rebuilds the derived table from scratch. The reconciler
is the only legitimate call site for the engine method;
// modusbrain-allow-direct-insert: <reason>annotates it explicitly. - Add a round-trip test in
test/e2e/system-of-record-invariant.test.tsthat proves DELETE + reconcile rebuilds the table byte-identically.
scripts/check-system-of-record.sh fails any PR that
adds a new direct call to a derived-table writer outside the
reconciler / migration layer without the explicit allow-list comment.
Related
~/.claude/plans/system-instruction-you-are-working-expressive-pony.md— the v0.32.2 design plan (decisions D1-D22 + Q1-Q8, Codex round 1 and round 2 finds)skills/migrations/v0.32.2.md— the agent-facing migration guideCHANGELOG.mdv0.32.2 entry — the release manifestoscripts/check-system-of-record.sh— the CI gate that enforces the rule