olog.cc

olog

Spec

The normative contract. Every implementation — TypeScript, Go, Python, Rust, Java — reproduces it exactly, and the same consistency vector proves it.

SKILL.md GitHub

1 · The ontology

A flat TSV file. One directive per line, tab-separated. Blank lines and # comments are ignored.

type	Request
enum	Request	state	queued,running,completed,failed
trans	Request	queued	running
trans	Request	running	completed
trans	Request	running	failed
DirectiveMeaning
type <T>Declare a type. A type is one concept — if Service could mean a module or a process, split it.
enum <T> state <a,b,c>The state vocabulary for type T. Omit ⇒ T has no state machine and its op is free-form.
trans <T> <from> <to>A legal transition. from may be * for "any state".
req <T> <prop>The entity of type T must carry this property. Checked on the entity's merged props after the fold — an early event may omit it if a later one supplies it.
forbid <T> <prop>This property must not appear on any event of type T.
enum <T> <prop> <a,b,c>Allowed values for a property, checked whenever it appears on an event.
rel <name>Declare a relation.
rfrom <name> <T>The subject type allowed on this relation.
rto <name> <T>The object type allowed on this relation.

An entity's state is the op of its latest event. trans therefore reads as "from state X, op = Y is legal". The req / forbid / enum vocabulary is inherited from x-cmd's ondb module — same names, same meaning.

2 · The event

One JSON object per line. JSONL — the only output format that exists.

{"seq":3,"ts":1764000000123,"run":"run-1","type":"Request","id":"req-7",
 "op":"running","props":{"method":"GET","path":"/api/x"},
 "links":{"caused_by":["job-2"]}}
FieldRequiredMeaning
seqyesMonotonic within the log file. This is the replay order.
tsyesEpoch milliseconds.
runyesThe replay unit — one request, one build, one session.
typeyesA type declared in the ontology.
idyesEntity id. Unique within type.
opyesThe transition. The entity's new state is op.
propsnoProperties. Merged into the entity on replay.
linksnoOutgoing edges: {"<rel>": ["<id>", ...]}. The emitting entity is the subject.

Fields olog deliberately does not have

AbsentWhy
levelA filter knob for human eyes. If severity matters, make it a property: req Request severity + enum Request severity info,warn,error.
loggerA hierarchical name is a naming convention, not an ontology. The type is the grouping.
mdc / ndcImplicit context has no readable scope. Put it in props or links.
threadAn implementation detail of the host language.
msgProse cannot be checked. Put facts in props; let the agent write the sentence.
exception / stackA blob of text that no replay can reason about. Use props.reason and props.cause.

props never participates in replay decisions except for the property rules (req / forbid / enum). Replay reads type, id, op, links.

3 · The five actions

Identical semantics in every language.

ActionDoes
emit(type, id, op, props?, links?)Append one event.
link(from, rel, to)Append one event carrying only a link.
replay()Fold the log into states + anomalies + timeline.
validate()Check the ontology itself is coherent.
open(dir)Open a log directory (ontology + JSONL).

The directory is:

<dir>/
├── ontology.tsv        the ontology
└── olog.log.jsonl      the events — JSONL, one per line, append-only
import { olog } from "olog";

const log = olog.open("./olog");
log.emit("Request", "req-7", "running", { method: "GET", path: "/api/x" });
log.link("req-7", "caused_by", "job-2");

const { states, anomalies } = log.replay();
// states.Request["req-7"] === { state: "running", props: { method: "GET", path: "/api/x" } }

4 · Replay semantics

Replay folds the events in seq order:

state[(type, id)] = { state: <last op>, props: { ...merged... } }

The fold never skips. Every event is applied — its op becomes the entity's state, its props are merged in. Anomalies are reports, not rejections: a log that breaks the contract is still a log worth folding.

At each step the replay checks five things. A failure is an anomaly.

AnomalyConditionUsual cause
illegal_transitionThe entity's current state has no trans to this op.A skipped state, concurrent writers, or a wrong ontology.
unknown_entityThe entity appears for the first time with an op that is not an initial state.A missing event, or the entity was deleted.
dangling_linkA links target names an entity that does not exist at that point in the log.Events were written in the wrong order.
invalid_propA forbidden property is present, an enum value is not allowed, the event's type is not declared, or an entity ends the fold missing a required property.The event does not match the ontology.
bad_relationThe relation is not declared, or the subject/target type is not allowed by rfrom / rto.The link does not fit the ontology.

Initial states

Initial states are derived, not declared: for type T, the states that appear as from in some trans but never as to. Request above has queued as its only initial state. A trans with from = * matches any current state. A type with no enum … state has no state machine: its op is free-form.

Self-transitions

A transition whose op equals the entity's current state is always legal. It records facts or links without moving the entity — that is how link() works, and it means re-emitting the same state is never an error.

Link resolution

For links[rel] = [id, …], the subject is the emitting entity (type, id). If rel declares exactly one rto type T, the target is (T, id); otherwise it is whichever entity carries that id, in any type. If no such entity exists yet, the link is dangling_link — the cause was supposed to be logged first.

Casual mode

An ontology that declares no types at all is no contract. The log is then folded without any checks: no unknown_entity, no illegal_transition, and no "type is not declared" — the states are still computed, but nothing is judged. The moment the ontology declares a type, the checks light up.

Ordering

The anomaly list is sorted by seq, ascending, and stable within a seq. Within one event the order is invalid_prop (event level), bad_relation, unknown_entity / illegal_transition, dangling_link. An entity that ends the fold missing a required property is an invalid_prop attributed to that entity's last event's seq.

Replay is deterministic: the same log plus the same ontology always yields the same states and the same anomalies. Nothing about the current time, the host, or the log file's mtime may enter the result.

5 · The consistency vector

Every implementation ships the same vector and must produce byte-identical results. It is the executable form of this spec.

Ontology

type	Request
enum	Request	state	queued,running,completed,failed
trans	Request	queued	running
trans	Request	running	completed
trans	Request	running	failed

type	Job
req	Job	cmd
enum	Job	state	queued,running,done,failed
trans	Job	queued	running
trans	Job	running	done
trans	Job	running	failed

rel	caused_by
rfrom	caused_by	Request
rto	caused_by	Job

Log

{"seq":0,"ts":1000,"run":"r1","type":"Job","id":"j1","op":"queued","props":{"cmd":"build"},"links":{}}
{"seq":1,"ts":1001,"run":"r1","type":"Request","id":"q1","op":"queued","props":{"method":"GET"},"links":{}}
{"seq":2,"ts":1002,"run":"r1","type":"Request","id":"q1","op":"running","props":{},"links":{"caused_by":["j1"]}}
{"seq":3,"ts":1003,"run":"r1","type":"Job","id":"j1","op":"running","props":{}}
{"seq":4,"ts":1004,"run":"r1","type":"Job","id":"j1","op":"failed","props":{"reason":"timeout"},"links":{}}
{"seq":5,"ts":1005,"run":"r1","type":"Request","id":"q1","op":"failed","props":{"reason":"upstream"},"links":{"caused_by":["j1"]}}
{"seq":6,"ts":1006,"run":"r1","type":"Request","id":"q2","op":"running","props":{}}
{"seq":7,"ts":1007,"run":"r1","type":"Request","id":"q2","op":"completed","props":{"code":200},"links":{"caused_by":["j-404"]}}

Expected replay

states:
  Job      j1  { state: "failed",    props: { cmd: "build", reason: "timeout" } }
  Request  q1  { state: "failed",    props: { method: "GET", reason: "upstream" } }
  Request  q2  { state: "completed", props: { code: 200 } }

anomalies (sorted by seq; rel/target are "" when they do not apply):
  { "seq": 6, "kind": "unknown_entity", "type": "Request", "id": "q2", "op": "running", "rel": "", "target": "" }
  { "seq": 7, "kind": "dangling_link",  "type": "Request", "id": "q2", "op": "completed", "rel": "caused_by", "target": "j-404" }

Note that q2 still ends up in completed: the unknown_entity at seq 6 is a report, not a rejection — the fold continues and the state is applied.

6 · Rules for agents

  1. Never invent a level. Severity is a property of a type, declared in the ontology. level=error in a log line is a bug.
  2. Never write prose into op. op is a state name from the ontology. op: "failed to fetch user" is a bug; op: "fetch_failed" + props.reason is correct.
  3. Facts go in props, relationships go in links. If two entities are related, that is a link, not a string in a property.
  4. Do not log secrets. There is no redaction layer, because redaction rewrites history. Redact before you emit.
  5. Do not change the ontology to silence an anomaly. An illegal transition is a finding.
  6. Do not reformat the log. JSONL only. One event per line.
  7. Read anomalies first. Start from anomalies, then walk the timeline backwards from the failing entity.