How ankka-reasoning works¶
ankka-reasoning is one ankka service with four parts: records, graph consumers, answers, and the blueprints it hosts on ankka's agent runtime. A writer sends a record, or a run of a blueprint writes one through a tool; the service checks it and keeps it; the record is published to a Kafka topic as a node and its edges; ankka's graph sink copies the topic into Neo4j; and a reader's question is answered by walking that graph. The write never waits for the graph, and the graph is never written by the service.
Records: where the truth is¶
Each record is one ankka entity, kept in the service's Postgres database. A question, a holder, a source, a piece of evidence, a claim and a market are each a key value entity; a belief, one holder's probability for one hypothesis, is an event sourced entity whose events are its revisions.
Whether a record may be held is decided here and nowhere else. A claim must name evidence that is held; a belief revision cannot rest on a claim dated later than itself; a writer must speak for the holder it writes as. Each rule is checked against the service's own records before the record is kept, and a record that breaks one is refused by the rule's name with nothing changed. Refusals lists them.
The graph database is never consulted for a rule. It is a moment behind the records, so a rule checked against it could pass for a record that should be refused.
The check runs before the entity's command and is still true after it, with no lock, because nothing a rule depends on can stop being true: a record that is held stays held, its date and its links never change, and a question's hypotheses and a holder's writers are only ever added to. Two rules do depend on state that changes, which revision of a belief is current and which resolution of a market is, and those two are decided inside the one entity that owns that state.
Graph consumers: one writer per element¶
Every record is published as a node, and every link it stated as an edge, by an ankka graph consumer. There is one consumer per kind of record, and each publishes the record whole: its node and every edge that leaves it.
A link is stated by one record, the newer of the two it joins, and is published with that record and by nothing else. So no node and no edge has two writers. That is what makes the topic safe to compact and the graph safe to rebuild: the latest delta under an element's key is the whole truth about that element.
What may be published is fixed by the vocabulary, a value in the code that names every kind of node and edge, its properties, and the kind of record that publishes it. A consumer builds an element only through the vocabulary, so an undeclared label or property is an error in a unit test and never reaches the topic.
The topic and the sink: the graph is a copy¶
The deltas go to one compacted Kafka topic, reasoning-graph, keyed by element. ankka's
graph sink, deployed as a service of its own from
ankka-contrib's image ghcr.io/thinkmorestupidless/ankka-graph-sink-neo4j, reads the topic and
merges each delta into Neo4j, replacing a node's properties whole and passing over a delta older than
what the graph holds. It keeps no state of its own: the topic is where it starts from.
The graph database holds nothing the topic does not. It can be emptied and filled again from the topic alone, with the service not involved, and every answer is the same afterwards. Operate the service does it.
Runs: a blueprint writes through tools¶
The service hosts one blueprint, the appraiser, on ankka's agent runtime. A run of it is started by a request and carried out by ankka: its workers call the three tools the service gives them, and each tool writes a record exactly as a request to the belief layer's route would, under the same rules, and then writes the record's act. The run, its ending and the blueprint's versions are ankka's own records, which the service copies into records of its own as ankka's events arrive, so that they reach the graph beside what the run wrote. The process layer is the model, and Run a blueprint the requests.
A run asks a text model and a judgment through ankka's providers, from keys in the environment.
Without a key the service starts and serves everything else; a run that asks ends failed naming the
key. The build's suites script both providers and never call out.
Answers: a walk, made of records¶
An answer is a Cypher query that starts from one node found by its identifier and walks outwards: from a belief revision to the claims it rests on, the evidence each derives from, and each piece's source. The reply is those records and their identifiers. No text is generated, so an explanation cannot say anything the records do not.
Answers read the graph database; nothing else does. A route that reads it answers 503 when it cannot
be reached, and every other route, writes included, is unaffected.
Ask for explanations shows each answer.
What a write waits for¶
A write is answered when the service's database holds the record. It does not wait for Kafka, the sink or Neo4j, so a graph database that is down costs a writer nothing.
The graph follows within a few seconds: a consumer learns of a changed record by polling the database
once a second, then the delta crosses Kafka and the sink applies it. A writer that needs to read its
own write from the graph asks POST /graph/wait, which ends when the graph holds the record's node
and every edge it stated, or when a limit passes.
Where each part runs¶
ankka-reasoning is two services in one ankka project. reasoning is one image: the layers are
compiled into it and composed by the service module, and it runs as one Pekko cluster of one or
more instances, its records in its own database in the project's Postgres. reasoning-graph-sink
is ankka's graph sink in ankka-contrib's image; no code of ankka-reasoning is in it, and it shares
nothing with the service but the topic and the secret that names Neo4j's user. The topic is in the
installation's Kafka, declared on the project. Neo4j is provided by whoever deploys it.
There are three ways in. People reach the service through the installation's gateway at its exposed
hostname, with a token from an issuer the service lists. Another ankka service reaches it inside the
cluster over mutual TLS and writes as service:<its project>/<its name>. A reader with a Cypher
client reads Neo4j directly, as Read the graph shows. Only the sink
writes to Neo4j. Deploy on ankka applies each part.
The modules¶
The code is six sbt modules, and the direction they depend in is the layering:
| Module | Holds |
|---|---|
graph |
the vocabulary as a value, the only way to build an element, the reader of the graph database |
belief |
the belief layer: its records, rules, graph consumers, answers and routes |
market |
the market layer, built on belief |
process |
the process layer, built on market: acts, runs, versions, the tools, the appraiser and the golden set |
service |
the three layers composed into the one deployable, with the providers from the environment |
seed |
a client of the service over HTTP: seed files and the two measuring tools |
belief does not depend on market, and neither on process, so a market word in the belief layer
or a process word in either does not compile. Layers and the vocabulary says what that
buys.