Internals

One transaction, one store, one door.

Three mechanisms carry most of kovee's weight: every authoritative mutation is a single SQL transaction that either happened or did not; one SQLite database holds both the query model and the immutable ledger; and every byte that leaves for a model provider passes an authority no call site can construct.

One command, one transaction

An authoritative mutation performs one transaction. Design §12.2 sets the requirement plainly:

"If the process dies after commit and before reply, replay returns the stored result. If it dies before commit, none of state, event, outbox, budget, or idempotency result exists."

"Normalized state is the query model, and the immutable ledger is the audit/attention record. They commit together and recovery tests prove they cannot diverge."

The implementation puts every one of those things inside the same IMMEDIATE transaction, so a check-and-act is a real compare-and-swap rather than a hopeful read followed by a write:

Two details matter more than they look. The §11.8 result-size bound is judged inside the transaction, so an over-large result is refused rather than committed and then found unreturnable. And the event append enqueues its own outbox notification, so there is no window where an event exists with nobody told about it.

Replay and refusal

The dedup key is a triple — (actor_scope, operation, idempotency_key) — and actor_scope encodes the surface, the actor and the realm. A worker's key is scoped to its invocation; an owner's to its realm. Two actors cannot collide, and neither can two surfaces.

What is compared on a repeat is not the raw bytes but a canonical request digest over version, surface, operation, realm, project, expected revision, arguments and extensions — deliberately excluding the request id and trace headers, so a genuine retry of the same intent matches even though its envelope differs. Three outcomes:

SituationWhat happens
Same key, same canonical request The stored result is returned byte for byte. The work is not re-executed. Before those bytes are released, an operation-specific replay authorizer runs inside the same transaction — so a replay cannot hand out receipts an actor is no longer entitled to.
Same key, different canonical request Refused: same scoped idempotency key, different canonical request. Never a silent overwrite.
Worker-surface command with no replay authorizer A hard internal refusal at the store boundary. The path fails closed rather than defaulting to "allow".

Crash-honesty

The interesting claim is not that the transaction is atomic — SQLite gives you that — but that the daemon around it does not leak or duplicate at the two moments that matter. That is tested by killing the real process, not by mocking a failure.

The store carries two crash hooks, armed from the environment as KOVEED_ABORT=<phase>:<operation>. The phase names a point — immediately before commit(), or after commit but before the reply is written — and at that point the process calls std::process::abort(). No unwinding, no destructors, no flushing: the same thing a power cut does.

KOVEED_ABORT=before_commit:space_create → daemon dies with the txn open KOVEED_ABORT=after_commit:space_create → daemon dies with the txn committed, before the client hears anything

The crash matrix spawns the actual koveed binary armed this way, fires the target command, asserts the daemon dies before replying, then restarts on the same database and checks:

Twenty such matrices cover project, space, contribution, relation, frontier, assembly and invocation creation, artifact upload and finalize, lifecycle changes, prepared widening, participants, grants, dispositions, lenses, reactions, aliases and application events — each at both phases. One further test crashes after an artifact finalize commits, confirms the plaintext staging copy really does survive the crash, and then that the startup sweep removes it and that replaying the cleanup is idempotent.

The acceptance test goes further and cuts the worst possible moment in a live agent loop: a real Python assistant, over the worker socket, with the daemon armed to die after its synthesis contribution commits but before the reply reaches the SDK. On restart the SDK's bounded retries replay, and the ledger is asserted to hold exactly one synthesis, exactly one addresses relation, one succeeded invocation, and a context assembly holding exactly the question with zero omissions. Re-running a completed invocation is refused as stale rather than handed its old receipts.

The store

One SQLite database, <data-dir>/kovee.db, opened with:

PragmaWhy
journal_mode = WALReaders do not block the writer. The daemon refuses to run if the mode it gets back is not WAL — a network filesystem silently downgrades it, and a silent downgrade would quietly weaken every durability claim on this page.
synchronous = FULL"After commit" means on disk, which is what makes the crash matrix meaningful.
foreign_keys = onReferential integrity enforced by the database, not by convention.
secure_delete = onFreed pages are overwritten — erasure has to reach the file, not just the row.
busy_timeout = 5000Bounded waiting rather than immediate failure under contention.

Schema changes are numbered migrations keyed to SQLite's own user_version; there are 10 of them today. The DDL and the version bump commit together, so a crash between them cannot strand the database half-migrated.

First start bootstraps the installation identity, the personal realm, and the key material the rest depends on — the cursor secret, the privacy chain key, the governance scope key and the realm object key. Bootstrap is idempotent, and an older database missing a key mints it at open rather than failing.

The ledger and its cursors

Events carry two dense sequences — one per stream, one per project — both allocated inside the transaction, so an aborted transaction consumes no number and a gap in the sequence is a real anomaly rather than routine. Uniqueness is a database constraint on both pairs, not a check in Rust.

Clients never see a raw sequence. A cursor is kc1.<hex payload>.<hex HMAC>, minted under the installation's cursor secret and bound to the source it was minted for. A cursor from another installation, another source, or a truncated paste is indistinguishable from a forgery and returns invalid. Possession still grants nothing: authorization is rechecked at read time, every time.

events_read pages forward from a cursor with a limit capped at 512. events_wait long-polls from one — and it takes the store lock only while it looks, releasing it between polls, so a waiting reader never blocks a writer. Replies are capped at 1 MiB and requests at 256 KiB.

The audit chain

Alongside the ledger there is an append-only audit log, hash-linked: each entry's hash covers the previous hash, the sequence, the timestamp and the length-framed event and detail, starting from a genesis of thirty-two zero bytes. It is body-free — it records that a command happened and under what authority, not what was said — and it is written inside the command transaction, so there is no committed command without a matching audit row. A verifier walks the chain and re-derives it.

The sealed consumption authority

Model egress is gated by one type. The rule it enforces: no byte leaves without a valid byom execution-consumption receipt for this exact execution key.

Four operations exist on that authority, and each verifies the previous one's keyed tag rather than assuming it, so the chain is authenticated end to end under a single secret the call site never supplies:

byom reply │ admit parse and stamp a keyed admission tag ▼ ExecutionConsumptionReceipt │ attest bind it to the committed consumption row ▼ ConsumedReceipt │ authorize check admission, provenance, one-shot, execution key, ▼ audience, digests, incarnation, epoch, fence, expiry ExecutionPermit (sealed over all 14 recorded members) │ dispatch verify the seal, claim the single use in the ledger, ▼ and only then open the socket one request

Every property in that diagram is a compile error to violate, not a convention:

One door per process

In a build with the daemon feature — only koveed enables it — there is exactly one public function that yields the authority. It answers once: a process-wide atomic flag is swapped on the first call, and every later call returns nothing, including one made with different key material. koveed takes it behind a lock so two threads racing cannot burn the grant, and if it ever comes back empty the daemon refuses the model call rather than proceeding under an authority it did not make.

The durable single-use claim is one conditional UPDATE that moves a consumption row from unspent to spent, and it happens before the socket opens. If the update moves no row — because the consumption never existed, or was already spent — dispatch terminalizes without sending anything. A ledger error is a refusal too: a use that cannot be recorded is a use that does not happen.

Proved against rustc

Those refusals are checked by a test that shells out to rustc directly. For each case it compiles a control snippet that must succeed and a denied snippet that must fail, and asserts that rustc's own stderr contains the expected error code and wording. There are 24 such cases in a build without the daemon feature, and the count itself is asserted, so deleting a case fails the test.

Why not a compile_fail doctest: one of those passes when the snippet fails to compile for any reason, including a typo, and rustdoc does not enforce the error code even when you write one. The gate also refuses to guess which build artifact it is testing — it compiles a fingerprint witness against every candidate library and demands exactly one survivor, because an earlier mtime-based pick once read a stale artifact and reported a mutant as green.

What is not closed

Read this before quoting any of the above

The module's own documentation states the boundary, and the site does not claim more than it does: closing the constructors removes the external-crate path — the one every probe so far exercised. It does not, and cannot, distinguish the daemon from other code compiled into the daemon. Code inside a daemon build that runs before koveed takes the grant can take it instead; code holding a reference to the daemon's authority can call admit, attest and authorize with material of its own.

Even then a forged permit must claim its single use in the daemon's own durable ledger, which moves a row that only a real byom consumption created — so a fabricated consumption reference still sends nothing, and there is a test that mints a permit from an attacker-built authority with identical key material and proves not one byte leaves. But note what bounds that forgery: the durable ledger, not cryptography. Closing the rest needs byom to sign its receipts so kovee can verify provenance against a peer key; that is a cross-boundary protocol change and it is deferred.

And none of it is a confinement claim: see provider bypass.

The crate map

15 crates in one workspace.

CrateHolds
kovee-coreRecords, closed enums, limits, canonical digests, the branch-head fold, and the operation table.
kovee-storeSQLite, migrations, the command transaction, the event ledger and cursors, the audit chain.
kovee-authPrincipals, actor scopes, and the authorization dependency sets re-read per command.
kovee-spaceSpace, contribution, relation, frontier and lens logic.
kovee-artifactsStaged uploads, per-object secrets, sealed blobs, erasure.
kovee-effectsDisclosure, the permit gate, the broker's dispatch path, the compile gate.
kovee-runtimeInvocations, attempts, fences, deployments.
kovee-byomThe one governance adapter. There is never a second.
kovee-aksonThe cross-installation edge.
kovee-busOutbox delivery.
kovee-commitmentLocal commitment records.
kovee-attentionA two-line stub. The attention machinery is not built.
koveedThe daemon: sockets, dispatch, handlers, the model broker, governance and formation sagas.
kovee-cliThe six-verb client. No argument-parsing dependency; it is one file.
kovee-mcpThe stdio MCP server and its schema interpreter.

unsafe_code is denied across the workspace; the one documented exception is a geteuid call in the CLI. Everything canonicalized or digested lands with golden vectors that two independent re-derivers — one Python, one TypeScript, sharing no code with the Rust — check in CI: 415 vectors against 197 schemas.