---
name: olog
description: Ontology-organized logging for the AI era — every log line is a typed state transition, so the log replays into a state machine and machine-checkable anomalies (illegal transition, dangling link) become the debugging output. Use when adding logging to a service that agents must debug, when replaying a run to find what broke, or when building an olog ontology for a domain.
version: 0.1.0
metadata:
  openclaw:
    emoji: 📜
    homepage: https://olog.cc
---

# olog — the log is the state machine

**olog** organizes logs by an **ontology**: every log line is one *typed state
transition* of one entity, and the ontology declares which transitions are legal.
Replay the log and you get a state machine — plus a list of the places where the
code broke the contract.

**Not** a logging framework. There is no logger, no level, no layout, no MDC, no
appender. There are five actions and one file format.

- Spec & downloads: **https://olog.cc**
- Implementations: `olog-cc/{ts,go,python,rust,java}`

---

## 1. When to use this

Use olog when **an agent has to debug the thing**, not when a human reads a tail
of text. It pays off when:

- the log is the evidence an agent reasons over (CI failures, incident forensics,
  an agent's own tool calls);
- "what went wrong" has a mechanical answer (which transition was illegal);
- the log must be *replayed*, not skimmed.

Do **not** use it for: human-facing audit trails, high-volume telemetry, or
anything that needs levels and per-request filters.

---

## 1b · The loop

Three steps. **The first one works with no setup at all.**

**1 · Log the state, not a sentence.**

```ts
import { olog } from "olog";

const log = olog.open("./olog");        // a directory — created on first write
log.emit("Request", "req-7", "queued", { method: "GET", path: "/api/x" });
log.emit("Request", "req-7", "running");
log.emit("Request", "req-7", "completed", { code: 200 });
```

**2 · Say how your system is supposed to behave** — `olog/ontology.tsv`:

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

**3 · Replay and read what broke.**

```sh
npx olog replay ./olog
```

```
2 entities

  Request  req-7  completed
      code=200  method=GET  path=/api/x
  Request  req-8  completed
      code=500  method=POST  path=/api/y

1 anomaly

  seq   4  illegal_transition   Request req-8 cannot go from "queued" to "completed"
```

**The CLI reads any olog log**, whatever language wrote it — the format is the
contract, not the implementation. `--json` gives machine-readable output;
`olog runs <dir>` lists the replay units.

**With no ontology at all the log is folded in "casual" mode**: the states are
still computed, but nothing is checked, because there is no contract to check
against. The moment you declare a type, the checks light up.

---

## 2. 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
```

| Directive | Meaning |
| --- | --- |
| `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".

`req` / `forbid` / `enum` on properties are inherited from the `ondb` vocabulary
(x-cmd's `ondb` module) — same names, same meaning.

A ready-to-copy example: [`olog.ontology.tsv`](olog.ontology.tsv).

---

## 3. The event

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

```json
{"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"]}}
```

| Field | Required | Meaning |
| --- | :---: | --- |
| `seq` | ✔ | Monotonic within the log file. **This is the replay order.** |
| `ts` | ✔ | Epoch milliseconds. |
| `run` | ✔ | The replay unit — one request, one build, one session. |
| `type` | ✔ | A type declared in the ontology. |
| `id` | ✔ | Entity id. Unique within `type`. |
| `op` | ✔ | The transition. The entity's new state is `op`. |
| `props` | | Properties. Merged into the entity on replay. |
| `links` | | Outgoing edges: `{"<rel>": ["<id>", ...]}`. The emitting entity is the subject. |

### Fields olog deliberately does not have

| Absent | Why |
| --- | --- |
| `level` | A filter knob for human eyes. If severity matters, make it a property: `req Request severity` + `enum Request severity info,warn,error`. |
| `logger` | A hierarchical name is a naming convention, not an ontology. The `type` is the grouping. |
| `mdc` / `ndc` | Implicit context has no readable scope. Put it in `props` or `links`. |
| `thread` | An implementation detail of the host language. |
| `msg` | Prose cannot be checked. Put facts in `props`; let the agent write the sentence. |
| `exception` / `stack` | A 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`.

---

## 4. The five actions

Identical semantics in every language.

| Action | Does |
| --- | --- |
| `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
```

### TypeScript

```ts
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" } }
```

### Go

```go
log, err := olog.Open("./olog")
log.Emit("Request", "req-7", "running", map[string]any{"method": "GET"})
log.Link("req-7", "caused_by", "job-2")
res := log.Replay()
```

### Python

```python
from olog import olog

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

result = log.replay()
# result.states["Request"]["req-7"].state
# result.anomalies
```

### Rust

```rust
use olog::{props, Olog};

let mut log = Olog::open("./olog")?;
log.emit("Request", "req-7", "running", Some(props(vec![("method", "GET")])), None)?;
log.link("req-7", "caused_by", "job-2")?;

let result = log.replay();
```

### Java

```java
import dev.olog.Olog;

Olog log = Olog.open(Path.of("./olog"));
log.emit("Request", "req-7", "running", Map.of("method", "GET"));
log.link("req-7", "caused_by", "job-2");

ReplayResult result = log.replay();
```

---

## 5. 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, and the rest of it must
stay analyzable.

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

| Anomaly | Condition | Usual cause |
| --- | --- | --- |
| `illegal_transition` | The entity's current state has no `trans` to this `op`. | A skipped state, concurrent writers, or a wrong ontology. |
| `unknown_entity` | The entity appears for the first time with an `op` that is not an initial state. | A missing event, or the entity was deleted. |
| `dangling_link` | A `links` target names an entity that does not exist **at that point in the log**. | Events were written in the wrong order. |
| `invalid_prop` | A 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_relation` | The relation is not declared, or the subject/target type is not allowed by `rfrom` / `rto`. | The link does not fit the ontology. |

### 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. This is the
ondb spectrum — *casual* to *designed* — applied to a log.

### Initial states

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 and it never
produces `illegal_transition` or `unknown_entity`.

### 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 the target 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.

### Ordering

The anomaly list is sorted by `seq`, ascending, and stable within a `seq`.
Anomalies are reported in this order within one event: `invalid_prop` (event
level), then `bad_relation`, then `unknown_entity` / `illegal_transition`, then
`dangling_link`. The "entity ends the fold missing a required property" case is
an `invalid_prop` attributed to the 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.

---

## 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.** olog records facts as given; there is no redaction
   layer, because redaction rewrites history and a replay of rewritten history
   is a lie. Redact before you emit.
5. **Do not change the ontology to silence an anomaly.** An illegal transition
   is a finding. Fix the code or fix the ontology deliberately — but do not
   paper over it.
6. **Do not reformat the log.** JSONL only. One event per line. If you need a
   different shape for a human, render it — do not log it.
7. **Read anomalies first.** When debugging, start from `anomalies`, then walk
   the timeline backwards from the failing entity.
8. **A self-transition is legal.** Emitting the state an entity is already in
   records facts without moving it. Do not treat it as a bug, and do not add a
   `trans` for it just to silence a report.

---

## 7. 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** (`olog.log.jsonl`)

```
{"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.

The `detail` string on an anomaly is human-readable and **not** normative; the
fields above are.

---

## 8. Corpus

- **https://olog.cc** — the spec, the reason, the downloads
- `olog-cc/olog` — this skill and the example ontology
- `olog-cc/ts` · `olog-cc/go` · `olog-cc/python` · `olog-cc/rust` · `olog-cc/java`
  — the implementations, one per language, same semantics, same vector
