Storage Operations
Meerkat resolves durable realm state through oneStorageLayout and one
realm-level storage provider. The rkat storage commands operate below normal
runtime scope so they can inspect or repair states that ordinary realm
resolution correctly refuses.
The three commands have deliberately different safety contracts:
These commands never read, move, or report credential stores. A persistent
rkat-rpc host also keeps approval records in approvals.json under its
resolved persistence store path. That RPC-owned sidecar is not an eighth
StorageProvider domain, and the current storage doctor, migration, and prune
commands do not inventory, migrate, or delete it. The durable decisions beside
it, in approval_decisions.sqlite3 (created by the first hold), are part of
the realm’s database inventory: the doctor reports the file and its
approval-decisions ledger domain, and migration fences it. The
approval_decisions.executor.lock file beside it, and one
approval_decisions.executor.<kind>.lock file per decision kind, hold no
data: each decision executor keeps OS locks on them while it runs, and a
backup need not copy them. Never delete one while a process runs: a new file
is a new lock, which a second executor could claim. The file of a kind no
executor registers any more stays behind, empty; remove it only while no
process uses the store. Keep the store on a local
filesystem, as SQLite needs anyway: on NFS the locks are emulated with POSIX
record locks, which do not exclude a second claim from the same process.
Select Roots And Realms
Without explicit roots, storage commands inspect two sweep candidates:- invocation-context-local
<context-root>/.rkat/realms - the user-global Meerkat data root
.rkat, so run storage commands from that project root (or pass --root) when
you want their local sweep to match the runtime’s project-local candidate.
Use global --state-root or repeatable command --root to provide an explicit
set. Once either is present, only those roots are read; ambient candidates are
not added. Global --realm restricts work to one validated realm ID while
still detecting twins across every swept root.
--default-model are rejected.
Read-Only Diagnosis
rkat storage doctor is safe against a live realm. It takes no realm lease or
maintenance fence, never changes logical database content, and never creates a
database or directory. A read-only SQLite connection may create or update the
-wal/-shm sidecars required for a coherent read of a live WAL database.
On truly read-only media, a WAL database without the required sidecars fails
typed instead of falling back to an unsafe immutable read.
- realm inventory by root and manifest/backend state
- per-database
meerkat_schemaledger domains and versions - the same realm ID materialized under more than one swept root
- persisted-session structural decode failures and transcript footprint
- dangling session-to-blob references
- orphaned lock, lease, index, and registered backup artifacts
- the SQLite lock profile of the
rkatbinary itself (see SQLite Lock Profile) - what a rollback to a release before 0.9.9 would refuse, as informational
findings: the sessions written at session envelope 5
(
operator-instruction-envelope: their documents hold operator-instruction facts, a retired instruction activation body, or a rewrite record that moved an instruction activation row), in SQLite realms and in the runtime store of JSONL realms, and the per-mob databases that hold operator-instruction events at mob event schema 10 (operator-instruction-mob-events). A host-store realm keeps its documents and mob events in the host’s store, which the disk sweep does not read - what a rollback to a release before 0.9.9 does not read in each per-mob
database: its identity-store rows of schema version 2 or later, the rows
of store-owned identities and the tombstones of removed names
(
identity-store-rows, with the counts only: the total, and the archived, tombstone and unreadable ones). The mob crate’s read-only reader counts them, by the rule a running mob’s census counts by, in anrkatbuilt with mob support (the default)
meta/storage/doctor), which from Meta 0.9.10 reports the
same three rollback findings for the files a Meta gateway keeps (see
Downgrading to 0.9.8).
Exit status is 0 when there are no error-severity findings and 1 when
errors are present. Warnings and informational findings alone do not make the
command fail.
The CLI reaches the built-in disk migrator because it intentionally runs
before an external-provider realm can be composed. External providers expose
the same
StorageMigrator::diagnose contract through their provider-native
operator surface; an unknown external backend is report-only to this CLI.Dry-Run And Apply Migrations
storage migrate is a dry run by default:
mobs/
remain report-only in migration v1.
Apply only with the realm offline or after verifying all writers honor the
shared maintenance fence:
--fence-wait-secs.
The one kept connection is a delivery owner’s reader of the runtime store’s
delivery generation, on a store other processes share: it stays open between
store ticks and holds the database’s presence lock (<file>.mpresence) while
it does. The fence takes the presence lock after its fence lock, and creates
<file>.mpresence next to every database it fences. The reader closes before
its owner calls into the host, at its next read, which the fence refuses, or
after a second without a read (KEPT_DELIVERY_READER_IDLE), so the fence gets
the database well inside the default wait. A fence wait shorter than that
second can meet an idle reader and refuse. A closed reader stays closed until
another connection commits or the store watch’s sweep (every 5 seconds)
reads: the reader’s own open and close are no change to the watch. A
notification is only a hint: a commit read while its WAL sync is still
running can wait for that sweep, within 5 seconds.
Windows keeps the fresh-open read path, one verified open per read, because
no CI lane runs the kept reader on Windows. There, a store notification after
which the database and its WAL stat as they did before the last read is
answered from that read without an open. Maintenance from a binary older
than 0.9.4 takes only the fence lock and does not wait for a kept connection:
run maintenance with the same release as the hosts.
Migration refuses when the fence cannot be acquired, a schema is from the
future, the manifest is unreadable, durable identity is ambiguous, or input
does not match a recognized predecessor. It never guesses a merge.
Exit status is 0 for a clean report and 1 for an error or fail-closed
refusal.
Resolve A Split-Brain Realm
If one realm ID exists under multiple swept roots, ordinary runtime resolution and migration both fail closed. First inspect the divergence report:*.pre-<version>-<timestamp> naming scheme.
Meerkat does not synthesize or merge divergent WorkGraph event streams,
schedule aggregates, or session histories.
--adopt-root requires --apply and must name one of the swept roots that
actually contains the realm.
Recover Storage From Before 0.8.10
Ordinary opens enforce the v0.8.10 compatibility floor. Current releases also provide an explicit, fenced bridge for authenticated historical SQLite schemas:sqlite backend. It verifies an exact known physical schema and durable
evidence before importing, then normal strict migration continues under the
same fence. Refusal has three distinct scopes:
- Whole-bridge preflight: unsupported backends (JSONL, memory, or external providers), invalid manifests, malformed ledgers, and future-version evidence refuse before bridge imports or ledger stamping begin.
- Per-domain transaction: an unauthenticated source schema or failed schema migration refuses that domain without committing its migration. Domains already committed remain committed; a later refusal does not roll them back.
- Per-record admission: within an authenticated domain, healthy records can migrate and the domain ledger can be stamped even when other records cannot be carried forward. Those refused records remain byte-identical on disk and are reported individually.
Prune Registered Maintenance Artifacts
storage prune is unrelated to live realm deletion. Its dry run lists only
recognized migration backups and index quarantines:
*.pre-<version>-<timestamp> backups and
*.corrupt-<timestamp> quarantines under the swept roots are candidates.
The command never deletes a live realm or an unregistered filename. Use
rkat realm delete or rkat realm prune for realm lifecycle.
Exit status is 1 only when deletion/reporting errors occur.
Recover From A Durable Projection Halt
If appending a canonical session event fails, the persistent session path records a durable projection-halt marker and refuses replay or resume past the hole. There is currently no self-service command to clear or repair that marker, andstorage doctor does not report it. Do not delete or edit it by
hand. Stop writers, preserve the complete store for diagnostics, and restore
an independently verified complete generation or escalate the store for
provider-specific recovery.
Repair A WholeBlob Session Wedged On Its Audited Endpoint
Symptom: after a turn completes,completed_boundary_commit fails with
Store read failed: WholeBlob body is not a valid current Session: live transcript does not preserve the graph-proved audited endpoint, every later
send answers reload_required, and a reload fails on the same error at
durable-tail recovery. The committed document’s live rows no longer match the
final materialization of its audited transcript graph, so the current-envelope
decoder refuses it on every read.
Current writers refuse to mint such a document (the checkpoint fails instead,
naming the first divergent row), and readers surface the typed
SESSION_WHOLEBLOB_AUDITED_ENDPOINT_DIVERGENCE session error (resume hold
audited_endpoint_divergence) so hosts can tell “needs repair” from I/O
failure. For a session that is already wedged, repair it once:
- Stop or evict the member first. The service refuses while any live actor
owns the session (a live checkpointer or a live registry entry), because
that actor’s in-memory state, not the committed document, is then the
authority. Under Meta, stop the member (or let the identity retire) and
confirm no
reload_memberretry loop is running against it. - Point
rkatat the runtime database that holds the session. A Meta gateway on the default disk layout opens one runtime database directly,<state_dir>/runtime.sqlite(flat under the state directory; the<state_dir>/meta/realm directory next to it holds only the meerkat-level jobs store and manifest pin), so name that file with--runtime-storeand pass the full session UUID. A store that lives in a realm layout (<state_root>/<realm>/runtime.sqlite3, the shape a composite storage provider’s meerkat-level realmmobkituses) is addressed with--state-rootand--realminstead; the realm argument is the realm’s directory name under the realms root (ASCII letters, digits,-or_). Themob.<name>id recorded in a session’s metadata is a mob scope, not a store realm; passing it is refused with a message that says so. A Meta member parked with asession_repair_requiredhold carries the exact form for its own store indiagnose_commandandapply_command. The command opens only that runtime database: it never creates a realm manifest or any other store, a missing database is a typed refusal naming the path it looked for, and a database pinned to the head-canonical profile is refused because this repair only applies to WholeBlob documents. A database whose runtime-store schema is older than therkatbinary is refused through a read-only preflight rather than migrated in place; open it once with the gateway that owns it (or a matchingrkat) first. The only writes an open can make are SQLite’s own: theruntime.sqlite3.mfencelock sibling, the WAL sidecars, and the journal-mode conversion to WAL for a database not already in WAL mode. No--realm-backendflag is needed. - Diagnose, then apply:
"action": "would_reanchor", "divergence": {"kind": "live_prefix_diverges", "endpoint_row_count": 118, "live_row_count": 125, "first_divergent_row": 115},
"graph_edges_dropped": 8, one dropped compaction intent, and the base store
revision and blob digest it read (base_blob_sha256, the digest of the
committed WholeBlob document body; it is not an image blob id, see
Blob digests in meerkat and Meta). The apply report
repeats those facts with
"action": "reanchored" and the new committed_store_revision; a second
diagnose then reports "action": "no_repair_needed" with the decoded
live_row_count. The expected divergence for that report is
LivePrefixDiverges (live rows at least as many as the endpoint, a prefix row
differing). A LiveShorterThanEndpoint divergence is the one shape where
re-anchoring on the live rows drops content the audited endpoint proves
existed; --apply refuses it unless you pass --accept-shorter, and the
report then records both row counts as the audit trail of that decision.
The repair keeps every message byte for byte. It removes the audited
transcript graph, its rewrite prefix authority and the pending compaction
projection intents from the document metadata, commits the result through the
store’s compare-and-swap against the observed authority (a concurrent writer
makes it report a conflict rather than overwrite), and leaves the store-owned
compaction outbox row so the runtime’s ordinary finalization still indexes the
discarded content. Audit history restarts at the next rewrite. The repair
refuses when the live rows themselves do not decode, when the re-anchored
document would change any row, or when a live actor still owns the session.
Hosts embedding PersistentSessionService call
repair_whole_blob_audited_endpoint(session_id, apply, accept_shorter) for
the same procedure.
Resolve A Durable Tail Held For Recovery
Symptom: a turn or resume of a persistent session answersSESSION_DURABLE_TAIL_HELD_FOR_RECOVERY (resume hold
tail_held_for_recovery), and opening the session again does not clear it.
Recovery found a durable tail past the session’s last committed boundary
whose evidence is ambiguous, for example a transcript that ends in a tool
call without its result, and holds the tail rather than guess what happened
(see Session contracts: durable-tail recovery).
The same answer can come from a tail this command does not resolve, for
example one whose input rows cannot be attributed to its run; for those,
the command answers held_otherwise with the reason. Since 0.9.5 an
operator can resolve a hold over ambiguous evidence, and one hold over
input rows that only pre-release builds of 0.9.5, or a store fault, leave (see
An interrupted tail held beside a stranded input):
- Stop every host of the session. The repair is refused while the session’s persisted runtime state shows it in use (for example attached or running) or holds a current run, and a refusal is never retried. A host whose runtime is idle does not show in that state, so stopping the hosts first is the operator’s part.
- Run the command without
--apply. This dry run writes nothing and reports the candidate and its run, the facts that made the tail ambiguous (its run rows, the last stop reason, the calls without a result, results that answer no call, rows after the terminal reply, the run cursor and whether its inputs are still bound), the messages it keeps, the calls it would answer, the inputs it would end, whether the persisted lifecycle is quiescent, and the verdict. - Apply it.
--runtime-store, the command opens the runtime store of the realm
it is scoped to (--state-root, --realm): a sqlite realm’s
sessions.sqlite3 or a jsonl realm’s runtime.sqlite3. It refuses a
memory realm, and a realm whose runtime store an external storage provider
owns: name that runtime database with --runtime-store, or, for a realm
kept in a host’s own database, use the library call below. It refuses a
missing database, or one with another schema version than the rkat
binary’s, without creating or migrating anything. Without --apply it
writes nothing to the session: it checks the database read-only before it
opens it, and refuses one whose switch to another storage profile is still
in progress instead of completing it. As for repair-wholeblob, the only
writes an open can make are SQLite’s own: the .mfence lock sibling, the
WAL sidecars, and the journal-mode conversion to WAL for a database not
already in WAL mode. A database whose schema is older than the binary’s, or
whose storage profile switch is still pending, is opened once with the host
that owns it; then run the command again. A newer schema needs a matching or
newer rkat. --json prints the report as one JSON object.
Applied, the repair commits the held tail as interrupted, through the same
recovery commit as a crash:
- every durable message is kept;
- each call without a result, in the tail’s last assistant message or in a
round’s response saved in the run cursor, is answered with an
outcome_uncertaintool error whose reason namesresolve-held-tailand the candidate; - a notice tells the model that an operator resolved the held run, that every durable message was kept and that the run was closed as interrupted;
- the inputs proved bound to the run end and never run again, and other queued inputs stay queued.
resolution in the JSON report):
A
refused verdict means the session’s persisted runtime state shows it in
use (stop every host of the session and run the command again), a commit
already covers or contradicts the tail, or an input cannot be attributed to
the run. An error means the repair could not proceed (the evidence could
not be verified, or the store refused the write); the session stays held. A
call without a result anywhere but in the tail’s last assistant message is
such an error: the repair only appends, and a result must follow its call.
So is a run cursor that cannot be read, or whose saved response has calls
but no message id: those calls may have run, and the repair cannot place
their results. The results after the tail’s last assistant message are
paired with its calls by position, since providers repeat call ids across
responses; when that pairing does not leave exactly the calls the
transcript shows without a result, the command answers with an error too.
An answer this version of rkat does not know also exits with an error.
With --json, an answer that fails the command (held_otherwise,
refused, or an unknown answer) still prints its report to standard
output, and the error’s message goes to standard error. An error before any
answer (the store cannot be opened, or the evidence cannot be verified)
prints only the error.
Only these holds have an operator path. A session answering
SESSION_DURABLE_EVIDENCE_QUARANTINED stays quarantined;
SESSION_DURABLE_TAIL_RECOVERY_REFUSED clears once the conflicting runtime
quiesces (a refusal over receipts that cover or contradict the tail does
not); SESSION_WHOLEBLOB_AUDITED_ENDPOINT_DIVERGENCE is repaired with
rkat session repair-wholeblob (above). Hosts that embed the runtime,
including any host that keeps a realm in its own database, call
meerkat_runtime::recovery::resolve_held_durable_tail with the store, the
session id and whether to apply. It answers HeldTailResolution and works
on any runtime store, a host store included.
An interrupted tail held beside a stranded input
Builds of 0.9.5 from before its release did not close a run when it was interrupted: the run’s last round commit stayed as the session’s durable tail. A turn submitted after the interrupt was then staged for a new run that never committed, and recovery holds the interrupted tail beside that input, because the input could be the tail’s own. The command resolves this hold when the store proves that the input is not the tail’s own:- the tail carries a run cursor, which binds exactly the inputs whose content the tail holds, and the cursor does not bind the input;
- the input carries content, is staged or queued, and names another run as its run, and that run has neither a boundary receipt nor a durable tail (the store keeps one tail per session, the interrupted run’s).
stranded_inputs,
with the report an ambiguous hold gets plus the inputs the repair
requeues. Applied, the repair commits the tail as interrupted, as recovery
commits any interrupted run: every row is kept, the interrupted notice is
appended, and the run’s own inputs do not run again. In the same commit it
puts each stranded input back in its queue with its content, bound to no
run, so it runs once, after the interrupted run, when the session next
starts. The command requeues no input this proof does not cover (one that
names a run with a receipt, one that names the interrupted run without its
cursor binding it, or one in another phase): while such an input stands
beside the tail, the answer stays held_otherwise and nothing is
written.
On a WholeBlob session, run the command before 0.9.5 opens the session.
The first open ends the stranded input as abandoned, and the next start
then closes the interrupted run by itself; the abandoned input does not
run, so submit it again. An interrupted tail with no input beside it needs
no operator: the next start closes it as interrupted.
Blob Digests In Meerkat And Meta
Meerkat and Meta both render image blob ids assha256:<64 lowercase hex digits>, and both feed a media type, a 0x00 separator and the image into
SHA-256. They hash different representations of the image, so the same PNG
carries a different id under each recipe. Never compare a meerkat content blob
id with a Meta blob id: the ids are indistinguishable by shape.
Which recipe a Meta-backed store applies depends on the entry point, not on
the store. Every image that reaches a Meta store through meerkat’s
BlobStore face (Base64BlobStoreAdapter::put_image, used by the gateway, the
unified runtime and the console voice host) and every image uploaded through
the console (meta/blob/upload, multipart image_upload placeholders) is
addressed with meerkat’s content_blob_id and stored under the canonical media
type, so meerkat’s read-back verification accepts it. Only blobs written
through Meta’s native BinaryBlobStore::put_bytes (non-image meta/blob/*
objects) carry the raw-bytes form, as do image blobs written by Meta builds
that predate this rule. A Meta store resolves both forms through both faces,
so references written before the rule keep hydrating.
Why the same image differs: base64 text of a byte string is not that byte
string, so the two SHA-256 inputs differ for every non-empty image. Meerkat
chose the encoded form because an inline image in a transcript hydrates from
its blob’s own base64 and the two representations must share one identity.
Meta chose the decoded form because its byte-serving store never holds the
base64 text.
How to recognize which form you hold: the string does not tell you, the
provenance does. An id that appears in a meerkat session document (an
externalized image row, an audit edge, a hydration error, a
BlobIdentityMismatch)
is a meerkat content blob id, including when the store behind it is Meta’s.
An id minted for a non-image object by put_bytes, or for an image by a Meta
build that predates meerkat addressing, is a Meta blob id; both appear in
blob object paths, /blobs/{id} URLs and meta/blob/* metadata. Meta’s
local object store also still reads a legacy layout whose ids were minted over
the base64 text without media-type canonicalization; those legacy ids equal
meerkat’s only when the media type was already canonical.
What is safe: compare meerkat ids with meerkat ids (an externalized row against
its blob store entry, a hydration payload against its row) and Meta ids with
Meta ids. Re-deriving one from the other requires the payload: decode the
meerkat base64 and hash it under Meta’s recipe, or encode the Meta bytes and
hash them under meerkat’s recipe. Do not hand-roll either derivation in new
code; call the owning function.
Unification of the two schemes onto one recipe is planned as its own release,
with a digest migration for existing manifests and repair tooling that
re-anchors stored ids. Until then the two schemes coexist as documented here.
Store-attested legacy references
A transcript can still hold an image reference in the Meta raw-bytes form, written by a Meta build that predates meerkat addressing. Meerkat’s recomputation cannot match such a reference, so a store may vouch for it:BlobStore::attest_address(blob_id, payload) returns
BlobAddressAttestation::StoreAddress when the store recomputes its own
address recipe over exactly the returned payload and gets blob_id. The
default implementation returns Unattested, which keeps every gate
fail-closed. An implementation must recompute from the payload; answering from
a lookup, or attesting unconditionally, defeats the check.
Two paths consult the attestation:
- The durable fork preflight (which
fork_offand council participant forks go through) verifies throughverify_stored_image_blob_accepting_store_addressand re-homes an attested reference: it stores the payload under meerkat’scontent_blob_idand rewrites the reference in the child’s copy of the transcript only. The source transcript and its legacy object are left as they are. - Realtime image hydration accepts an attested reference.
BlobIdentityMismatch. A Meta store
attests its legacy references once its blob adapter implements
attest_address.
Upgrading A Realm To 0.9.4
Since 0.9.4 every runtime input row a binary writes is stored input state version 7, including a row it read at an older version; versions 3 to 6 are still read. A 0.9.3 or older binary refuses a version 7 row before installing any state and leaves the stored bytes in place, so once a 0.9.4 process has written an input row there is no downgrade to 0.9.3. Snapshot the realm’s durable stores before the upgrade, keep the snapshot with the 0.9.3 binary, and upgrade every process that shares a runtime store together. The same holds for a HeadCanonical session that has recorded a failed realtime response: it writes realtime sidecar event schema 4, and 0.9.3 and earlier refuse that session with “unsupported realtime event schema 4”. 0.9.3 and earlier could log a one-time error when two processes used durable delivery over the same store for the first time at the same moment: “schema domainruntime-delivery has no ledger row but already owns objects …;
refusing to infer or stamp an unversioned schema”. It needed no repair: the
process that logged it wrote nothing and the delivery stayed durably pending.
Do not run a schema bridge for it. Since 0.9.4 the open-time check reads the
schema ledger and the catalog in one snapshot, so a domain another process
creates at that moment is seen whole or not at all, and a delivery whose
projection failed is retried on the next delivery wake (see
durable jobs).
Write Volume Of Per-Round Commits
Since 0.9.5 a run in a durable session commits twice per tool round (see Durable runs). On asqlite realm, a HeadCanonical
store, each commit writes the rows the round added. A jsonl realm’s runtime
store is WholeBlob: each commit writes the whole session document, so the
bytes a run writes grow with the square of its tool rounds. A realm kept in a
host’s own database through the host store SPI
is WholeBlob as well. Choose a sqlite realm for long, tool-heavy runs.
Operational Runbook
For an unreadable or refused realm:- Stop writers if any mutation may be needed.
- Run
storage doctor --jsonagainst an explicit root set and save the report with the deployment evidence. - If the issue is split-brain, identify the authoritative generation from
external provenance, then use
--apply --adopt-root. Do not choose by newest timestamp alone. - If the report identifies pre-v0.8.10 SQLite state, take a backup and use the explicit compatibility bridge.
- Run
storage migrateas a dry run, then--applyonly after the report is clean and the maintenance fence can be acquired. - Run
storage doctoragain and boot the candidate normally. - Prune registered backups only after the rollback window expires.
See Also
- Realms
- CLI commands
- Session contracts
- Durable jobs and monitors
- Durable runs and host stores
- Upgrading for the one-way schema migrations each release performs, and the 0.8.50 SQLite session data note.
