Skip to content

research: history for the graph, and alternatives to the chant/lifecycle orphan branch and the git-ref index store #5435

Open

Description

@lex00

Research. Where chant keeps records over time, and what could replace the chant/lifecycle orphan branch and the git-ref index store, judged by what a graph reader needs from history.

Related: #4519 (the index store), INTENTIUS/behold#1025 (the index), INTENTIUS/behold#1027 (the graph pane), INTENTIUS/behold#1028 (index diff).

Why now

behold's graph pane loads each index scope's latest version into LadybugDB and nothing older (latestVersions in behold's src/graph-db/sources.ts). Resource keys are <scopeKey>/<id> with no version, so two versions of one scope would collide. chant's history template says so in its note: "Snapshot history (chant#4519's store) is not loaded into the session yet." History today is a diff of two JSON documents (index diff), not something Cypher can ask.

Loading every version (to a cap) into the session would let a person ask "what was true at T" and "when did this edge appear" in Cypher. Before behold builds that, the question is whether the stores underneath it are the right shape for history reads, or whether a different store would make the projection simpler or unnecessary.

What exists, checked at chant 799f239

There are two kinds of record, and they need different things.

Indexes and snapshots are derived, stamped and never load-bearing (#4519; index-store-load-bearing.test.ts). They sit behind SnapshotStore (lifecycle/snapshot-store.ts), with git-ref (refs/chant/snapshots, indexes under _index/), local, s3, none, and read-only orphan-branch. Each version is a file named <UTC stamp>-<digest12>.json under its scope path. History on git-ref is the ref's commits and the version files; on local it is the latest file only; on s3 it is the bucket's object versions.

Op records are not derivable, and some decide what an Op may do next. They stay on the chant/lifecycle orphan branch: gate ledgers (_gates/<op>.jsonl), checkpoints, applied lines, deploy outcomes (<env>/outcomes.jsonl), converge and release ledgers, stored change sets and build manifests (_builds/). Writes go through writeBlobToPath (lifecycle/git.ts): hash-object, mktree, commit-tree and update-ref, with a compare-and-swap retry, and a --force-with-lease push (pushLifecycle). #4519 left open whether these leave the branch, and named refs/chant/ledger as one answer.

Questions

  1. What history questions do readers ask? Measure rather than guess: behold's pane and history template, index diff, chant search --at, lifecycle diff --live (declared, then, now), gate audit, operator status, components status.
  2. What are the sizes on real estates: versions per scope per month, bytes per version, records per ledger file, write rate under converge? The three-cloud demo and the fan-out demo are two candidates.
  3. What does each record kind need from its store: compare-and-swap, append-only, review in a pull request, offline reads, read without write credentials (behold reads with none), retention and erasure of a masked value that should not have been kept?
  4. Can a reader enumerate versions cheaply, and read one version without reading the rest?
  5. Is the graph a projection of the store, or could it be the store for either kind of record?

Alternatives to compare

For Op records:

  • The orphan branch as it is.
  • The same layout under refs/chant/ledger (or a ref per stream, such as refs/chant/gates/<op>), which keeps the mechanics, drops the branch-list and protection objections, and narrows compare-and-swap contention to one stream.
  • git notes on the source commit, for records keyed by commit (the plan a gate approved). Weak for records not keyed by a commit.
  • An object store with conditional writes (S3 If-None-Match and If-Match, GCS generation preconditions): one object per record, append by unique key, compare-and-swap on a head pointer. Needs credentials to read, which the git-native stores do not.
  • A hosted store with conditional writes (DynamoDB, Postgres). Strongest concurrency, and a service to run.
  • A versioned or bitemporal store such as OxiliteDB's log level (SQLite, Turso, D1) or Tiramemsu (append-only SQLite, transaction and valid time). History becomes a query. Both are months old and single-maintainer, and both are RDF-shaped with Cypher translated on top.
  • choudoufu's record store as the model (pkg/staterecord): Get, PutIfAbsent, PutIfVersion, Delete, List, with compare-and-swap per key on each backend. One key per event means writers never conflict and history comes from the key names. Costs the git-native story and needs credentials to read. (comment)

For indexes:

  • The git-ref store as it is, with behold loading every version to a cap and adding version to the key.
  • A columnar copy per version (Parquet) that LadybugDB or DuckDB imports in bulk. behold now inserts one row per prepared statement; a bulk load would also shorten the session build.
  • A persistent graph file in behold's per-user data directory, loaded incrementally by version name and still safe to delete. This trades the per-session rebuild for a file that must survive LadybugDB upgrades.
  • A bitemporal store as above, where behold's observedAt is valid time and readAt is transaction time.
  • The index as an event log: one file per changed resource, created only if absent, with a checkpoint every N versions. History costs about the size of the changes; reading the latest version becomes a fold. (comment)
  • Dolt as an opt-in store, run through the dolt CLI with a git remote (refs/dolt/data). History and diff are SQL queries (AS OF, dolt_diff). DoltLite is the in-process option for Node, but has no git remote. (alternative, research)

For each: what a reader gains, what is lost (reviewability, portability, offline, the git-native story, the credential boundary), migration from what exists (old snapshots and ledgers must stay readable), and who owns it (chant's store, or a projection behold keeps).

Findings so far

Dolt, measured on synthetic data with a local git remote (results):

  • It works for indexes. History survives a fresh clone past the git history cap. AS OF and diff answer in under a second. A second writer fails at once with a clean error and leaves nothing half-written.
  • It costs a dolt binary and at least 2.5 s per push. The git remote also adds a visible branch, __dolt_remote_info__.
  • It saves no storage. Over 40 versions, today's git layout took 292 KB, Dolt's row tables 584 KB, and Dolt with one JSON cell per version 1.2 MB. The case for Dolt is history as a query.

Not yet done: question 2 on a real estate, and the comparison table.

Done when

  • A comment here measures question 2 on at least one estate and answers questions 1, 3 and 4 per record kind.
  • A comparison table scores the alternatives against question 3's needs, with a recommendation for indexes and one for Op records, which may differ.
  • Follow-up issues are filed for what is chosen, including the behold side (loading versions into the session).
  • No production code merges under this issue.

Activity

  1. added
    area:lifecycle
    design
    epic:graph-query
    on Nov 20, 2026
  2. lex00 commented on Nov 20, 2026

    @lex00
    ContributorAuthor

    Two more alternatives, both keeping records as files.

    The index as an event log, the shape the Op records already have

    Today an index version is a whole document, <scope>/<stamp>-<digest12>.json, so a history read loads many near-identical copies. The alternative writes one line or file per changed resource (added, removed, changed, with observedAt) and a full checkpoint every N versions.

    • Gained: history costs about the size of the changes. Index diff becomes reading the changes since a version. A graph reader loads a checkpoint plus the changes since, which maps directly onto valid-time rows.
    • Lost: reading the latest version is a fold from a checkpoint. The format needs checkpoint rules and a fold that is correct, and old whole-document versions stay readable.

    How it is written matters. On the git-ref store an "append" is not one: writeLedgerFiles (lifecycle/git.ts) reads the file, writes a new blob holding every line, rebuilds the trees, and moves the ref with a compare-and-swap. Packs keep the disk cost small, but every write is a read-modify-write of the whole file under one ref, and a file many writers append to is a hot spot. S3 has no append at all. So the shape that works on every store is one file per change, created only if absent, never a file that grows.

    choudoufu's record store as the model

    choudoufu's live backend already keeps its records this way (pkg/staterecord, choudoufu f8e250dce6). The estate's truth is the markers on the resources and live reads. Each managed instance has one small record holding only what a read leaves out, and the state file a run writes is a cache that may be thrown away.

    The store is five calls: Get, PutIfAbsent, PutIfVersion, Delete and List. Keys and payloads are opaque, and a version is opaque except that "" means no record. Each backend gives a real compare-and-swap per key with its own primitive:

    Store Record Conditional write Past versions
    local a file under .tofu-records hard link for create, a sidecar lockfile and rename for update; one machine only none
    s3 an object If-None-Match: *, If-Match bucket versions (the contract refuses an unversioned bucket); live-history lists them without payloads
    gcs an object ifGenerationMatch not listed
    azurerm a blob ETag conditions not listed
    kubernetes a Secret in tofu-records-<estate> resourceVersion none

    What chant would take from it:

    • Concurrency per key instead of per ref. writeLedgerFiles makes the whole chant/lifecycle ref the unit a writer races on, and detects conflicts per path on top. With one key per event (_gates/<op>/<stamp>-<digest>) written with PutIfAbsent, two writers never conflict and no append re-reads anything.
    • History on every backend from the key names, because an event is never overwritten. choudoufu gets history only from S3 versioning, because its records are replaced in place; the local and Kubernetes stores keep none.
    • The conformance suite as the shared contract. design: a pluggable index store - snapshots and every other index, off the orphan branch, queryable, never load-bearing #4519 already said chant and choudoufu share contracts, not code; chant is TypeScript and staterecord is Go.

    What it costs:

    • The git-native story: no commit per write to review, no git fetch to copy history to another clone, no offline read of a remote store.
    • The credential boundary: reading S3, GCS, Azure or Kubernetes needs credentials, where behold reads refs/chant/snapshots with git alone.
    • A git-ref backend for the same five calls is possible (one ref per key, or a tree under one ref) and keeps the git story, but it brings back one ref as the unit of contention unless each stream gets its own ref.

    For the graph, both alternatives keep records as the storage and the graph as a projection, which is also how choudoufu treats its own state file.

  3. lex00 commented on Nov 21, 2026

    @lex00
    ContributorAuthor

    Another alternative: a versioned database kept in files, Dolt or DoltLite. Checked 2026-11-20 against DoltHub's docs, blog and the npm registry; the points not yet checked are marked.

    Dolt

    A SQL database (MySQL wire protocol, Apache-2.0, v2.7.5 released 2026-11-18) with commit, branch, merge, diff, clone, push and pull.

    • History is a query: dolt_history_<table> and dolt_diff_<table> (system tables). AS OF reads are documented elsewhere and not yet checked here.
    • Merge is per cell: two changes to one row conflict only when they touch the same column (three-way merge).
    • Remotes: DoltHub or DoltLab, file://, s3:// (conditional writes, no DynamoDB), aws:// (S3 plus DynamoDB), gs://, oci://, ssh, http, and since v1.81.10 a git remote (remotes, git remotes). The git remote keeps the data under refs/dolt/data (changeable with --ref), needs a git binary and an existing repository, and a plain git clone does not fetch it, the same as refs/chant/snapshots. v1.81.10 failed when git asked for credentials on stdin (dolt remote operations with git remotes fail when credentials require inline password. dolthub/dolt#10486); whether that is fixed is not checked.
    • From Node there is no binding: run the dolt CLI (dolt sql works against a directory with no server), or dolt sql-server with a MySQL client. DoltHub lists mysql and mariadb for Node; mysql2 is not listed and not checked. The in-process engine (dolthub/driver) is Go only, so choudoufu could embed it and chant could not.
    • Writes to the commit graph take a lock per branch (concurrency). Startup cost of dolt sql per command is not documented.

    The graph pane's four tables (Resource, CloudId, KNOWN_AS, REF) would be Dolt tables as they are, with a commit per index version. Index diff becomes dolt_diff_*, and behold loads any version into LadybugDB. Content-addressed storage with structural sharing would make a whole snapshot per version cost about what it changed, which removes the need for the event-log shape above. That is Dolt's design, but this comment has no cited page for it yet.

    DoltLite

    A SQLite fork with Dolt-style versioned storage, a separate engine from Dolt (repo, why).

    • @dolthub/doltlite, a native Node addon with a node:sqlite-style API, and @dolthub/doltlite-wasm for the browser, both 0.51.14 and Apache-2.0. Beta since about 2026-08-31, with a storage format it calls stable.
    • One writer at a time; other writers get SQLITE_BUSY.
    • Not format-compatible with Dolt: the two cannot push or pull to each other (storage comparison). Its remotes are files and HTTP, with no git remote mentioned.
    • Whether it has AS OF and dolt_history_* is not checked.

    It is the only route with an in-process engine for TypeScript, and the only one that runs in an exported bundle beside LadybugDB's WebAssembly build.

    Gained and lost

    • Gained: history and diff as queries without code of ours; whole snapshots without whole copies; with the git remote, the data stays in the repository on a ref of its own, as refs/chant/snapshots does now.
    • Lost: a new runtime outside npm for Dolt (the dolt binary on every machine and runner), or a beta engine for DoltLite; Dolt and DoltLite cannot share one history, so chant (Node) and choudoufu (Go) would have to pick one engine or keep separate histories; and Op records' compare-and-swap rule becomes transactions on one writer per branch, where choudoufu's store gives it per key.

    Fit: indexes, where queryable history is the need. Op records are better served by a record per key with a conditional write (above).

    Also worth a line:

    • TerminusDB: a graph database with git-style versioning, the nearest thing to the graph as the store with history. It has its own query languages, not Cypher. Not checked here.
    • Table formats on object storage (DuckLake, Iceberg, Delta): Parquet plus a catalog, with time travel, read from Node through DuckDB. Suited to large append-only indexes, and poorly suited to small conditional writes. Not checked here.
  4. lex00 commented on Nov 21, 2026

    @lex00
    ContributorAuthor

    More on Dolt, as an opt-in store spawned through the dolt CLI with a git remote. Checked 2026-11-20 from DoltHub's docs, blog, releases and issues. Nothing was run.

    The git remote

    • refs/dolt/data points at a git commit whose tree holds Dolt's table files and manifest as blobs, split into parts past 50 MB (how it works, blobstore: add chunked-object mode to GitBlobstore dolthub/dolt#10424, v1.81.8).
    • A push makes several git commits. After git-remote.max-history-commits (default 64) the next write starts a commit with no parent, so git can collect old objects (remotes). The git commits are transport. Dolt's own history is in the table files, so I expect it to survive this, but nothing I read says so outright. That needs a check.
    • Speed: the only published numbers are for a six-row table, a clone of 7.6 s and a push of 28.5 s (announcement). publish after every snapshot would be slow; it fits a store that publishes once per run.
    • Credentials: Dolt runs git. Since v1.82.1 it turns git's prompts off and fails fast, and v1.86.4 keeps a user's GIT_SSH_COMMAND. dolt remote operations with git remotes fail when credentials require inline password. dolthub/dolt#10486 (passphrases on stdin) is still open, so CI needs a token in the URL or a credential helper. Bitbucket is not supported.

    History as a query

    • AS OF takes a commit hash, a branch, HEAD^2, or TIMESTAMP('...') (querying history). Tags are not mentioned.
    • DoltLite has dolt_log, dolt_history_<table>, dolt_diff_<table>, dolt_blame_<table>, branches, merge and tags, and reads a past revision with dolt_at_<table>('<rev>') rather than AS OF (README). Its remotes are file://, its own HTTP server and DoltHub; no git remote, and no plan for one that I found.

    What storage costs, and what that means for a schema

    Dolt keeps tables in prolly trees of content-addressed chunks of about 4 KB. One changed value costs about 4 KB times the tree depth; appends are cheap; edits scattered across a table can touch almost every chunk; adding a column rewrites the table (structural sharing). There are no published numbers for many near-identical snapshots. Garbage collection has run automatically since 1.75, but history that is still reachable is never collected; squashing it is dolt rebase plus dolt gc --full (disk space).

    That decides the schema:

    • Storing each index document as one JSON cell (Dolt as a plain Medium) shares almost nothing between versions, because every read changes values throughout the document. At minimum observedAt changes on every node. It would pass the conformance suite and gain little.
    • Storing rows (resources, edges, cloud ids, as the graph pane's tables) shares well only if values that change on every read stay out of the rows: observedAt and the read stamp go in a table per version, and a resource row changes only when the resource did. Then a commit costs about what changed, and dolt_diff_* answers what changed.

    Driving it from chant

    • dolt sql -q ... -r json exists. The JSON shape is not documented beside it; dolt table export writes {rows: [...]}. Needs a check.
    • No published numbers for how long the CLI takes to start; DoltHub says it is slow on large databases because it loads storage indexes. Needs measuring.
    • Two dolt processes on one directory: nothing documents whether the second waits or fails, and one third-party report describes a stale lock file after quick successive commands. chant should run one dolt at a time per store until this is measured. Workspace members written in parallel are the case to test.
    • dolt table import reads json and jsonl (with --schema). No size limit for a JSON cell is documented.
    • Dolt and DoltLite are Apache-2.0, so spawning or shipping the binary needs the licence and NOTICE files and nothing more.

    Still to measure, before building

    1. CLI start and a one-row commit on a small database.
    2. Push and fetch over a git remote for one real index (the three-cloud demo's).
    3. Storage growth over a few dozen reads of one scope, with the row schema above.
    4. Two concurrent writers on one directory.
    5. That history older than max-history-commits still answers AS OF after a fresh clone.
  5. lex00 commented on Nov 21, 2026

    @lex00
    ContributorAuthor

    The five Dolt measurements from the previous comment, run 2026-11-21 with Dolt 2.7.6 on macOS arm64.

    Limits. No checkout here has a real index store, so the data is synthetic. It is shaped like graph-schema/fixtures/index.json, with 400 resources and about 600 edges, and one document is 416 KB. Each version moves observedAt on every node, changes an attribute on 2% of resources, and adds and removes one resource. The git remote is a bare repository on local disk, so the times have no network in them.

    1. CLI start and a one-row commit

    Call Time
    dolt version, first run / after 645 ms / 200-300 ms
    dolt sql -q "select 1", small db 130-205 ms
    same, db with 62 commits 190-335 ms
    insert one row and call dolt_commit(...) in one dolt sql about 155 ms
    dolt_diff('HEAD~20','HEAD','resources') 415 ms
    one past version of resources via AS OF, as JSON 746 ms

    -r json prints {"rows":[...]} once per statement, one line each, and JSON columns come back as objects. Each call costs a process start of roughly 150-300 ms, so a store should batch a version's writes into one dolt sql call.

    2. Push and fetch over a git remote

    Step Time
    first push, 40 versions (584 KB of Dolt data) 2.1 s
    clone 0.5 s
    push with nothing new 2.7 s
    push of one version, history cap at the default 4-8 s, median about 5 s
    push of one row, cap 0 (unlimited) 2.5 s
    fetch with nothing new / pull of two commits 0.9 s / 0.9 s
    plain git fetch of refs/dolt/data 0.15 s

    A push costs about 2.5 s with no network, before any data moves, and the history cap's reset adds more. That confirms the earlier advice: publish once per run, not once per snapshot.

    The git remote writes three refs: refs/dolt/data, the existing refs/heads/main left as it was, and a branch, refs/heads/__dolt_remote_info__, holding a DOLT_REMOTE.md. That branch shows in the branch list and on the forge, which is the objection that moved chant's indexes off chant/snapshots. Not checked: whether the --ref option also moves the info branch.

    3. Storage growth over 40 versions

    Store Size
    raw documents, 40 x 416 KB 16.2 MB
    Dolt, one JSON cell per scope (Dolt as a Medium) 3.2 MB, 1.2 MB after dolt gc
    Dolt, row tables (resources, edges, cloud_ids, observations) 2.2 MB, 584 KB after dolt gc
    git, one new file per version (today's git-ref layout) 760 KB loose, 292 KB after git gc --aggressive

    This corrects the previous comment. A JSON cell does share storage between versions: Dolt chunks JSON values, so a document whose observedAt changes on every node still costs about 30 KB a version after gc, not a full copy. The row schema is half the size, and git's delta compression is half again. Storage alone is no argument for Dolt over the current layout. What Dolt adds is history as a query (AS OF, dolt_diff), which the git layout leaves to reading and comparing whole documents.

    Writing a version took about 0.8 s for the JSON cell and 1.2 s for the row tables, using one dolt table import per table and so a process each. Doing it in one dolt sql call should cut most of that; not measured.

    On the remote, each push added about 70 KB to the bare repository until git gc (1.9 MB after 20 pushes, 764 KB after gc). The cap exists so a forge can collect those objects; with cap 0 they stay.

    4. Concurrent writers on one directory

    Three loops, each running 30 single-row insert-and-commit calls against one directory:

    • 18 of 90 calls failed, all with cannot update manifest: database is read only. The second process opens the database read-only and fails at once rather than waiting.
    • Every row that landed has its commit: 72 rows, 72 commits, a clean working set. No half-written state.
    • Nothing stale was left behind. The LOCK file stays, empty, and the next write succeeds.
    • While dolt sql-server holds the directory, dolt sql from another process sends its writes through the server, and they land.

    So chant either retries on that error, holds one writer per store per run, or starts a sql-server for a run that writes in parallel (workspace members) and sends every write through it.

    5. History past the cap after a fresh clone

    With DOLT_GIT_REMOTE_MAX_HISTORY_COMMITS=4, 20 pushes reset the git chain repeatedly (2 to 4 commits on refs/dolt/data). A fresh clone then had all 62 Dolt commits. AS OF the oldest data commit returned version 0, and dolt_diff from it answered. The cap prunes git's copy of old table files, not Dolt's history.

    Where this leaves the opt-in store

    • It works as described: history survives, queries on history are fast enough for behold's pane, and failures under contention are clean.
    • Costs: a dolt binary, about 2.5 s or more per push, a visible __dolt_remote_info__ branch, and per-process start costs that make the write path one batched call per version.
    • Worth it for indexes if the history questions in question 1 of this issue want AS OF and diff as queries. Not on storage grounds.

    The scripts that produced this are a generator and two shell scripts, available on request. They use no chant code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:lifecycledesignepic:graph-query

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions