TechFabricTechFabricPlatform
Platform referenceGovernance

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

TablePopulated whenWhat it carries
ActionInvocationEvery invokeAction callactor, parameters, status (pending → terminal), correlation/causation, error message
PolicyEvaluationEvery policy that runs during an invocationpolicy ID, version, kind, result, reason, full dispatchEvidence
AssetEventEvery domain event emitted by a handler/sagatyped 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

QuestionQuery
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:

  1. 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.
  2. Failed attempts are persisted. A validation_failed, blocked_by_policy, or failed invocation creates an audit row. Discarded attempts do not exist.
  3. Decisions are inspectable. dispatchEvidence records exactly which conditions evaluated, which evaluator ran, and which fallback triggered. "Why" is structured, not narrative.
  4. 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.
  5. Time travel. The AssetEvent log 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 altered

What the generator does:

  • Fails closed on scope. A record whose tenantId or spaceId differs from the context throws EvidencePacketGenerationError (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 as payload.redaction. Pass { fields: [] } to redact nothing.
  • Orders deterministically. Events sort by occurredAt, recordedAt, sequence, then id; the other sections by id. Event timestamps must carry an explicit zone. With the same now, packet id and options, the same records give the same payload and checksum whatever order they arrive in.
  • Checksums the payload. checksum is the hex SHA-256 of canonicalJson(payload), recorded with checksumAlgorithm. It covers the payload, not the other envelope fields. verifyEvidencePacketChecksum returns false for 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, policyId and status, 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

On this page