- Erlang 76.1%
- Python 10.1%
- Rust 5.7%
- Shell 4.7%
- Dockerfile 3.4%
|
All checks were successful
build-and-push / guard-1 (push) Has been skipped
build-and-push / guard (push) Successful in 0s
c4 model / c4-model-1 (push) Successful in 3s
c4 model / c4-model (push) Successful in 0s
build-and-push / check (push) Successful in 5m5s
lint-and-test / check (push) Successful in 5m2s
build-and-push / The tested lock arrives whole (push) Has been skipped
build-and-push / test (push) Successful in 0s
lint-and-test / The tested lock arrives whole (push) Has been skipped
build-and-push / File the tested resolve for the signer (push) Successful in 3s
build-and-push / build-and-push (push) Has been skipped
|
||
|---|---|---|
| .github | ||
| apps/mcl_graph | ||
| architecture | ||
| assets | ||
| config | ||
| deploy | ||
| native | ||
| scripts | ||
| .dockerignore | ||
| .gitignore | ||
| .tool-versions | ||
| CHANGELOG.md | ||
| Containerfile | ||
| LICENSE | ||
| README.md | ||
| rebar.config | ||
| SECURITY.md | ||
The store is created on first start. A RocksDB directory that an earlier release left in the data directory is neither read nor imported; see The store.
It runs on macula 18 through mcl_om 1.6, with post-quantum signatures on every call and fact. The architecture, as a C4 model, is in architecture/.
Mesh surface
Procedures, reached as mcl-graph/<name>. Each of its own procedures is open to
any member of the realm, and the graph is a commons: nothing limits how much a
member adds. mcl-om adds mcl-graph/info and mcl-graph/get_limits to every
service, both open, and capabilities/0 is the list. A caller becomes reachable
only after the realm has admitted the mcl-graph org. Until then the node is
healthy and nothing can reach it.
| Procedure | Parameters | Returns |
|---|---|---|
resolve_link |
subject, and optionally predicate, direction (out, in, both; default out) and depth (1 to 8, default 1) |
rows: one map per link, or per reachable entity at the fewest hops that reach it when depth > 1; at most 1000 |
resolve_entity |
entity_id |
id, attributes, first_seen, source, out_degree, in_degree, predicates |
learn_link |
subject, predicate, object, and optionally confidence (default 1.0), metadata and asserted_by |
link_id, entities_new |
narrate_entity |
entity_id |
entity_id, prose |
narrate_link |
same as resolve_link |
subject, prose |
info |
none | name, version, description, org, node id, health, the procedures above (added by mcl_om to every service, as is get_limits) |
get_limits |
optionally procedure |
that procedure's guard stats, or those of every declared procedure (added by mcl_om to every service) |
Facts, on app-tier topics under the graph's org, for example
io.macula/mcl-graph/graph/knowledge/link_learned_v1:
| Fact | Direction | Payload |
|---|---|---|
entity_learned_v1 |
published | entity_id, attributes, source, learned_at |
link_learned_v1 |
published | subject, predicate, object, confidence, source, learned_at |
truth_asserted_v1 |
heard | subject, predicate, object: any realm member may publish one for the graph to learn (the subscription declares sources => members) |
Text arrives as text and times are milliseconds since the epoch.
Learning and provenance
learn_link creates any entity it has not seen, publishing entity_learned
for it, then records the link and publishes link_learned. CozoDB's :insert
decides whether an entity is new in a single round trip, so two racing calls
for the same new entity publish entity_learned once.
The caller becomes part of the graph. By default the caller is the
wire-authenticated node id of the call. A relay calling on behalf of others
can name who it acts for in asserted_by, which carries an identity and an
ownership proof bound to mcl-graph/learn_link, this realm, every field of
the triple and one use. A claim that is present must hold: if it does not,
the call is refused with the reason (bad_signature, stale_proof,
replayed, ...; invalid_asserted_by when it is not a map, realm_unknown
before the realm is known) and nothing is learned. It never falls back to the
wire caller, which would hide a forgery attempt and record a link its signer
never asserted under the relay's name. The caller, hex-encoded, is linked
asserted to both endpoints at confidence 1.0. To ask what X has told the
graph, call resolve_link with subject X and predicate asserted.
A heard truth_asserted fact goes through the same path, with its verified
publisher as the caller, at confidence 0.7. A fact whose publisher did not
verify is refused, and so is one that is not a map.
Every query carries CozoDB's own timeout (10 s), so no single call can hold
the store. A failure in the store reaches the caller as store_error and is
logged in full.
Narration
narrate_* render the graph one sentence per link, from a fixed template. The
narration involves no model and no network call, so it costs nothing and
cannot fail.
Build and test
The CozoDB NIF (native/mcl_graph_nif, Rust) is built from source on every
compile and needs cargo, cmake and a C++ toolchain: it compiles CozoDB's SQLite
storage, into the bundled SQLite, and nothing else. If the NIF fails
to build, the compile fails. Nothing falls back. It
is built for the baseline x86-64 CPU (native/build-nif.sh), never the build
machine's: the fleet's small boxes are Celeron J4105s without AVX2, where a Rust
crate built with -mavx2 dies with SIGILL.
The image builds in the fleet's plain pair on the forge registry
(macula-ci-otp / macula-pq-runtime, each pinned by digest, pulled with the
org's read-only CI_IMAGE_PULL credentials), and CI runs lint, eunit and
dialyzer in the same builder. The NIF links no RocksDB, so neither image's
librocksdb is read or wanted.
The image also builds on the lock CI tested. rebar.lock is not in git, so the
build context gets the file the tests ended on — filed on the tested-locks
pre-release for host00's signer — and the Containerfile cmps it after
rebar3 get-deps and refuses a rewrite. A release therefore carries the
transitive versions eunit and dialyzer ran against, not whatever hex serves on
the day of the build. A local build needs a lock of its own: rebar3 get-deps
makes one.
scripts/ci-gate.sh # lint, eunit, dialyzer in the CI image, as root
FRESH=1 scripts/ci-gate.sh # the same, with no cached _build: what CI sees
scripts/ci-gate.sh rebar3 eunit # one command, same image
rebar3 as prod release
mcl_graph_store_tests runs against a real CozoDB. The desk tests also send
their payloads through macula's own codec, so they see what a real call
delivers.
The store
The graph is CozoDB's SQLite engine, in graph.sqlite in the data directory
(MCL_DATA_DIR). The file is created, with its schema, on first start; there is
nothing to import and nothing to convert.
An earlier release kept the graph in a RocksDB directory — the data directory
itself. This release never reads it: the file it serves is graph.sqlite, and a
directory that holds no such file starts a fresh, empty store whatever else it
holds. The old store is dropped, not carried over. mcl-graph had no graph
data before the cutover — the directory held the relation definitions and nothing
else — and the fleet change that moved this service to SQLite deletes the old
data directory after the switch.
Configuration
| Variable | Default | What |
|---|---|---|
MCL_REALM |
(required) | the realm tag, 64 hex |
MCL_REALM_NAME |
(required) | the realm name the topics carry; its sha256 must be MCL_REALM |
MCL_REALM_KEY |
(required) | the realm's public signing key, hex |
MACULA_STATION_SEEDS |
(required) | host[:port],... |
MACULA_STATION_NODE_IDS |
(required) | the seeds' node ids, 64 hex each, in the same order |
MCL_BOX |
(required) | the host it runs on. It labels the boot claim, and the realm admits no claim without it |
MCL_SERVICE_NAME |
mcl-graph |
the service, on the same claim |
MCL_DATA_DIR |
/data |
the directory holding graph.sqlite |
MCL_NODE_NAME, MCL_NODE_HOST, MCL_COOKIE |
mcl_graph, 127.0.0.1, unset |
Erlang distribution. Distribution and epmd listen on 127.0.0.1 only. No cookie ships: with MCL_COOKIE unset the image makes a random one on first start (/etc/mcl/secrets/erlang.cookie, 0600) and keeps it. |
The node identity is kept at /etc/mcl/secrets/identity.key and must be on a
persistent volume. deploy/docker-compose.yml runs the service with both
volumes in place, the image by digest (MCL_GRAPH_IMAGE_DIGEST) and the graph
at MCL_GRAPH_DATA (default /bulk0/mcl-graph). With {mesh, required} a boot
missing the realm, its key or the pinned stations stops and names each one.
Deployment
A v* tag publishes ghcr.io/macula-services/mcl-graph:<version> and nothing else. Nothing
signs it yet: the keyless attest-image.yml job went with the forge port and signing comes
back with P6, on host00's signer. A push to
main publishes :main and :<sha>, and no box runs either: the fleet instead pins a
release by digest, macula-fleet's pin-releases workflow verifying the signed tag and
writing <version>@sha256:<digest> (macula-fleet edge/gitops/release-targets:81-82;
macula-fleet#14, #15), so a green v* tag is the deploy. :latest stays published as a
pointer and nothing reads it. To roll back, revert the pin and hold the image there.
/health reports down when the store is not open. It reports degraded
when the truth_asserted subscription is not held: the graph still answers
calls but hears no truths.
License
Apache-2.0.
Dependency licences
| Dependency | Licence | How it is used |
|---|---|---|
| cozo 0.7 (with cozo's SQLite storage) | MPL-2.0 | the graph database, linked into the NIF |
| sqlite, sqlite3-src (vendored SQLite) | Apache-2.0 / MIT (the crates), public domain (SQLite itself) | cozo's storage, compiled into the NIF |
| rustler 0.38 | MIT / Apache-2.0 | the NIF bridge |
| mcl_om, macula | Apache-2.0 | the mesh substrate |
MPL-2.0 is file-level copyleft: changes to cozo's own files would be published under MPL-2.0; this repository's code stays Apache-2.0.