The usual way to monitor a system is to guess, in advance, what will go wrong: an alert on the error rate, another on latency, a dashboard for the things someone once asked about. The guesses are made while the code is written, by whoever has the least time to think about them, and they check what's easy to measure rather than what matters. Then production does something nobody guessed, and someone reads logs until they understand it.
Logika turns this around. While the code is written, your agent logs what happens: every state transition, with the entity, its values before and after, and the cause (AI engineering). Every so often, once there's real data to look at, you sit down with your agent for a dedicated session, a reflection round, and decide together what your system is supposed to do. That goes into the ledger; from then on, Logika checks it every 5m, and your agent fixes what breaks it, often before anyone notices.
Why later
A rule about what must hold can only check what was recorded, and it's only as good as its author's picture of the system. Written up front, it checks a guess. Written from captures, it checks what the code actually does, in the words the code actually uses: the events it really emits, the paths its operations really take, the timings they really have. And you're there for the one thing no agent can infer: which of those behaviours is a bug, and which is the business working as intended.
It also means the rules are cheap to change. They're data in logika.json, versioned with the code, reviewed in pull requests like anything else; a rule that raised a false alarm is fixed in the next round, not muted in a vendor's UI.
A round
logika init sets up nock in your repository: a small toolbox that keeps coding agents coherent across sessions. Among other things, it runs the round. Once a component is instrumented and there's something to read (captures from logika test, or what production sent), ask your agent:
nock reflect logika
The round has two parts, run side by side: rules, what must hold, and analytics, what you want to measure. Each reads the code and the data and proposes; the session brings you the questions only you can answer, a few at a time, each naming what it would settle and the answer it recommends. If you'd rather answer later, the agent records the answer it proposes as a decision for you to accept or reject, and carries on with it. The round ends with a report: what was added or changed and the evidence for each, how it was tested, what was left out and why, and the instrumentation it suggests where the data is missing something a rule would need.
Rules, proven on replays
The rules part writes what must hold, in the forms the ledger has for it:
| What must hold | How the ledger says it |
|---|---|
| a fact about one event's values | validate: "amount > 0" |
| the order of an operation's steps | span.paths: "reserved (captured|declined)" |
| something finishes in time | span.timeout: "2m" |
| one event obliges another | a rule: every captured payment is fulfilled or refunded within 15m |
| a relation between events | an invariant: a SQL query returning the rows that break it |
Failures need no rule: a span that fails, or a log record with an exception, is already an issue.
It starts where a mistake costs most: money, stock, access, anything that changes shared state. And every rule is tested twice before it lands: it must be silent on the real captures, and it must fire on a replay that breaks it. Take the classic double charge, two charges for one order, each valid in its own trace:
"invariants": [{
"name": "one_charge_per_order",
"description": "An order is charged once",
"key": ["order_id"],
"query": "SELECT _span_id FROM (SELECT _span_id, row_number() OVER (PARTITION BY order_id ORDER BY _end, _span_id) AS n FROM \"checkout.captured\") WHERE n > 1"
}]
logika replay '{"on": "capture", "duplicate": ["checkout.captured"]}'
The replay judges the last capture again with every checkout.captured copied, as if the code had charged twice; the invariant fires, so it works. Run on the capture as it is, it's silent, so it won't wake your agent for nothing. A replay can also fail, delay or drop events, or set a param to another value: whatever the rule claims to catch, the round shows it catching.
Every rule gets a one-sentence description, which becomes its issue's title: "An order is charged once" is what you'll read in the email, should it ever break.
Analytics, written with you
The second part asks what you want to know about your system, and declares it: which params identify a person or an account (identity), which are worth breaking things down by (dimension), the funnels your users go through and the milestones they reach, and the views that put them on a page, each panel with a title and the sentence it opens with. Declarations are backfilled from the data already stored, so a funnel declared today shows the last month at once. Analytics has the details.
The ledger as the contract
When the round is done, logika check validates everything, and logika sync deploys the ledger; nothing syncs on its own, so you decide when. From that moment, the ledger is the contract between your code and production:
- Logika judges every event against the version of the ledger its code was built with, so an old release is never held to a new rule.
- What breaks it is an issue, with its evidence, and the loop starts: your agent wakes, fixes, reports.
- An issue you dismiss as not a problem means the contract was wrong: the next round corrects the ledger, rather than muting the alarm.
Rounds are cheap, so have them often: nock says when one is due, and runs one only when you agree. The next round starts with what's owed: the decisions you rejected or noted since, and every rule that raised a false alarm, which it fixes or takes out.
What changes
You stop reading logs, and you stop guessing in advance. You spend an hour every so often saying what your system is for; Logika watches that it does it, continuously; and when it doesn't, your agent hears about it before your users do, and might well have fixed it before anyone deigns to complain.