Audit trail
What the platform records about every attempted action, and how to read it.
The audit trail is not a separate logging system. It is a direct readout of three platform tables that are populated by the mutation pipeline as a side effect of normal operation.
The three tables
| Table | Populated when | What it carries |
|---|---|---|
ActionInvocation | Every invokeAction call | actor, parameters, status (pending → terminal), correlation/causation, error message |
PolicyEvaluation | Every policy that runs during an invocation | policy ID, version, kind, result, reason, full dispatchEvidence |
AssetEvent | Every domain event emitted by a handler/saga | typed payload, subjectType/subjectId, sequence, actor info, actionInvocationId link |
Every action is one ActionInvocation row + zero-or-more PolicyEvaluation rows + zero-or-more AssetEvent rows. They share correlationId so a single SQL WHERE correlationId = … reconstructs everything.
What you can answer
| Question | Query |
|---|---|
| Who took which actions in this tenant in the last 30 days? | ActionInvocation filtered by tenantId, createdAt |
| Why was this invocation blocked? | PolicyEvaluation WHERE actionInvocationId = … |
| What was the parameter shape of an action 6 months ago? | ActionInvocation.parameters is preserved verbatim |
| What events did this saga produce? | AssetEvent WHERE correlationId = … |
| Did agents take any actions in the last week? | ActionInvocation WHERE actorType = 'agent' |
| Did anyone bypass policy X? | They couldn't, but you can confirm by joining PolicyEvaluation |
What auditors get for free
Because every mutation flows through the pipeline:
- No "shadow writes." Boundary tests (
packages/api/modules/*/boundary.test.ts) reject direct ORM mutations from API or UI code. There is no second path. - Failed attempts are persisted. A
validation_failed,blocked_by_policy, orfailedinvocation creates an audit row. Discarded attempts do not exist. - Decisions are inspectable.
dispatchEvidencerecords exactly which conditions evaluated, which evaluator ran, and which fallback triggered. "Why" is structured, not narrative. - Causality is preserved. Sagas link child invocations via
causationId. A reviewer can walk the tree from a top-level user action to every downstream side effect. - Time travel. The
AssetEventlog replays. State at any historical timestamp is reconstructible.
Evidence packets
For deeper compliance use cases, @fabricorg/platform/evidence defines an EvidencePacketEnvelope and, in TypeScript, a generator that builds one:
interface EvidencePacketEnvelope<TPayload> {
id: string; // cep_<ULID>
tenantId: string;
spaceId: string;
packetType: string; // e.g. "credit_pull_consent_packet"
status: "draft" | "sealed" | "superseded";
subjects: EvidencePacketSubject[];
references: EvidencePacketReference[]; // → action_invocation, asset_event, etc.
payload: TPayload;
generatedAt: Date | string;
generatedBy: string;
policyVersion?: string;
checksum?: string;
checksumAlgorithm?: string; // "fabric-canonical-json-sha256-v1" when generated
correlationId: string;
causationId?: string;
}public interface IEvidencePacketEnvelope<TPayload>
{
string Id { get; set; } // cep_<ULID>
string TenantId { get; set; }
string SpaceId { get; set; }
string PacketType { get; set; } // e.g. "credit_pull_consent_packet"
string Status { get; set; }
IReadOnlyList<EvidencePacketSubject> Subjects { get; set; }
IReadOnlyList<EvidencePacketReference> References { get; set; } // → action_invocation, asset_event, etc.
TPayload Payload { get; set; }
DateTimeOffset? GeneratedAt { get; set; }
string GeneratedBy { get; set; }
string? PolicyVersion { get; set; }
string? Checksum { get; set; }
string CorrelationId { get; set; }
string? CausationId { get; set; }
}A packet is a curated bundle of references the platform can hand to a regulator: "here is the consent record, the credit pull invocation, the policy evaluations that allowed it, and the resulting events."
Packets have status, draft (under construction), sealed (immutable, the official record), superseded (replaced by a newer sealed packet, retained).
Generating a packet
generateEvidencePacket builds a sealed packet for one subject. Your application supplies a read port over its own store. The generator persists nothing, so storing the returned envelope is your job. It is TypeScript-only for now; the C# port defines the envelope but has no generator and no ChecksumAlgorithm field.
import {
generateEvidencePacket,
verifyEvidencePacketChecksum,
type EvidencePacketReadPort,
} from "@fabricorg/platform/evidence";
const port: EvidencePacketReadPort = {
listEvents: ({ tenantId, spaceId, subjects }) => store.eventsFor(tenantId, spaceId, subjects),
// Optional. Each absent reader leaves its section empty.
resolveRelatedSubjects: (subject, scope) => store.relatedSubjects(subject, scope),
listActionInvocations: (scope, ids) => store.actionInvocations(scope, ids),
listPolicyEvaluations: (scope, invocationIds) => store.policyEvaluations(scope, invocationIds),
listAdapterInvocations: (scope, invocationIds) => store.adapterInvocations(scope, invocationIds),
};
const packet = await generateEvidencePacket(
{ subject: { subjectType: "Case", subjectId: caseId }, policyVersion: "2026-06" },
{ tenantId, spaceId, actorId, correlationId, db, now: new Date() },
{
port,
anonymizationPolicy: { fields: [{ match: "key", value: "email", method: "tokenize" }] },
},
);
await store.savePacket(packet);
verifyEvidencePacketChecksum(packet); // true until the payload is alteredWhat the generator does:
- Fails closed on scope. A record whose
tenantIdorspaceIddiffers from the context throwsEvidencePacketGenerationError(EVIDENCE_SCOPE_MISMATCH) rather than being included or dropped. An error thrown by the port propagates, and no packet is returned. - Redacts before hashing. The payload runs through the privacy engine with data class
"evidence_packet", and the resulting metadata is stored aspayload.redaction. Pass{ fields: [] }to redact nothing. - Orders deterministically. Events sort by
occurredAt,recordedAt,sequence, thenid; the other sections byid. Event timestamps must carry an explicit zone. With the samenow, packet id and options, the same records give the same payload and checksum whatever order they arrive in. - Checksums the payload.
checksumis the hex SHA-256 ofcanonicalJson(payload), recorded withchecksumAlgorithm. It covers the payload, not the other envelope fields.verifyEvidencePacketChecksumreturnsfalsefor a changed payload, a missing checksum or an unknown algorithm. - Builds references for each action invocation, asset event, policy evaluation and adapter invocation, read from the redacted payload. Their metadata holds a fixed set of fields per record kind, such as
eventType,subjectId,policyIdandstatus, and nothing from event payloads.
createEvidencePacketRenderer(options) wraps the generator as an EvidenceRenderer for one packet type. FabricModule has an evidenceRenderers field, but the module registry does not call it, so invoke the generator or renderer from your own code. The @fabricorg/platform README lists the full guarantees and the residual redaction risks.
Query patterns
-- Reconstruct everything that happened in one user request
SELECT *
FROM action_invocation, policy_evaluation, asset_event
WHERE correlation_id = $1
ORDER BY created_at;
-- All blocked attempts for a tenant
SELECT ai.*, pe.policy_id, pe.reason
FROM action_invocation ai
JOIN policy_evaluation pe ON pe.action_invocation_id = ai.id
WHERE ai.tenant_id = $1 AND ai.status = 'blocked_by_policy';
-- Per-actor activity heatmap
SELECT actor_type, action_id, COUNT(*)
FROM action_invocation
WHERE tenant_id = $1 AND created_at >= NOW() - INTERVAL '30 days'
GROUP BY 1, 2;See also
- Compliance: privacy, redaction, retention.
- Events as evidence: the underlying data model.
- Action triggers: why the pipeline is the only mutation path.