Tracing a Single AI Decision: The correlationId Pattern

Juan Piaggio · 2026-07-27 · 7 min read · ai · engineering · observability

Sooner or later an AI agent will do something you can't immediately explain. A ticket gets closed, a label appears, an expert gets assigned, and someone asks the only question that matters: what happened, exactly? If your answer is a shrug and a grep across five services, you don't have an AI product. You have an AI mystery. The fix is a single thin thread woven through the whole decision — a correlationId.

The problem with distributed AI reasoning

A modern agent decision is not one event. It's a chain: a trigger fires, context gets gathered, a prompt is assembled, a model is called, a confidence score comes back, a risk score is computed, a gate is checked, and finally an action either executes or waits for approval. Each step often lives in a different service, log stream, or table. Individually they make sense. Collectively they're a haystack.

When something goes wrong, you don't want to reconstruct that chain from timestamps and guesswork. Timestamps lie under load, and two concurrent decisions on the same issue will interleave in your logs until they're indistinguishable. You need a way to say "show me everything that belongs to this one decision" and get exactly that back.

One ID, threaded end to end

The pattern is almost boringly simple: mint a unique identifier at the very start of a decision and attach it to every record, log line, and event that decision produces. That's the correlationId. It is not a database foreign key to one table; it's a label that travels across tables and services, tying otherwise-unrelated rows into a single narrative.

At Meshworq the correlationId is the spine of the AI decision audit ledger. The same identifier tags the model call, the confidence and risk scores, the gate decision, the resulting action, any approval it required, and any escalation that followed. Because the ledger is unified around a nullable correlationId rather than a rigid per-feature schema, decisions of different shapes — a transition here, a governance action there — all thread onto the same trail. Ask for one correlationId and the entire life of that decision assembles itself in order.

A correlationId turns "what did the AI do?" from a forensic investigation into a single query.

What good threading looks like

The value is entirely in the discipline of never dropping the thread. A few rules keep it intact:

Get these right and you gain something quietly powerful: any decision, no matter how it played out, can be replayed step by step after the fact.

Beyond debugging

Threading an ID through every decision pays off well past incident response.

Accountability. When a customer or auditor asks why the AI did something, you produce the actual chain — the confidence it had, the risk it scored, whether a human approved it — not a reconstruction you hope is accurate. For an AI product operating in someone else's workspace, that provenance is not a nicety; it's the basis of trust.

Tuning. Aggregate across correlationIds and patterns surface. Which triggers produce the low-confidence decisions? Where do humans most often reverse the agent? Which action types escalate? The correlationId is what lets you group by decision instead of by isolated event, and grouping by decision is where the insight lives.

Safe autonomy. You can only widen an agent's autonomy if you can see what it's doing at the resolution of individual decisions. The audit trail is what makes it responsible to let an agent do more, because "do more" always comes with "and show your work."

A pattern, not a product

None of this requires exotic infrastructure. You need three things: a place to mint the ID, the discipline to pass it everywhere, and a store you can query by it. The hard part isn't the technology; it's refusing to let the thread break. Every new code path in the decision flow is a chance to drop it, and every dropped thread is an audit gap you'll discover at the worst possible moment. Treat forwarding the correlationId the way you treat forwarding an auth context — non-negotiable, checked in review, never optional.

The takeaway

AI decisions are distributed by nature, and distributed things become unexplainable the moment you can't stitch them back together. A correlationId is the cheapest possible insurance against that: one identifier, minted at the start, carried to the end, queryable forever after. It's what lets Meshworq answer "what happened, exactly?" with a trail instead of a theory. Thread the ID through everything, guard it like an auth token, and you turn your agent's reasoning from a black box into a record you can read.

← All Field Notes