Skip to main content

Module backend

Module backend 

Source
Expand description

Where the atoms’ state lives: a Backend the host chooses.

§Why the state is held here, and not composed over ikigai-store or urn:file:

The obvious design is the ledger’s: author every read and write as a sub-request to a store’s named graph (or to the host’s file workspace through urn:file:*), and own no bytes. It does not work for scripts, and the reason is the kernel’s own rule: a sub-request carries the caller’s capability unchanged (Invocation::issue). Whatever this crate writes on a caller’s behalf, the caller must hold the grant to write directly — and here the record IS the authority:

  • every publisher would hold write over the graph (or file) that stores a script’s granted-at-publish snapshot, so a publisher could rewrite their own snapshot through urn:iki:store:graph-update and have their script run with grants they never held. That is exactly the elevation this crate exists to rule out.
  • every runner records a run, so every runner — the anonymous principal included, for a public script — would hold store write. An unauthenticated door holding write over the run log can forge the log.

So the atoms hold their own state, behind this trait, and nothing but this crate’s endpoints write it. No caller needs a storage grant, and no storage grant reaches an authority record. The golden threads are still the kernel’s: a Sink or Delete to urn:script:{name} cuts the thread named after it, and every derived read hangs from that thread.

§Out-of-band edits are survivable

DirBackend keeps plain files a person can read and edit, and assumes an editor got there first:

  • a head is replaced by compare-and-set against the head the writer READ, so a hand edit in between is a typed Conflict, never a lost update;
  • a version file is checked against the digest it is named by on every read, so an edited version is refused by name (“edited out of band”) and every other version and script still works;
  • a malformed head fails that script alone, with the file named; the catalog lists it as broken rather than failing whole.

What it cannot do is SEE an edit: a read the kernel cached before the edit is served until the host cuts urn:script:{name} (a watcher on the directory, or sink urn:kernel:cut urn:script:{name}), the same contract every file-backed resource has. A hand edit is the host operator’s act — the same trust as the ceiling files in the config home — and the run-time intersection with the stored snapshot and the host’s ceiling still holds whatever the files say.

Structs§

DirBackend
Every script as plain files under one directory the host chooses:
MemoryBackend
Every script in memory: for tests, and for hosts whose scripts are configuration that is published again at every start.

Traits§

Backend
Where a host keeps its scripts. Every method is called from inside an endpoint, so an implementation must not block for long; both built-ins are synchronous and local.