Event schema reference
The full AssetEvent envelope with the registration API and the naming rules, so a new event stays readable years after it is emitted.
AssetEventEnvelope
interface AssetEventEnvelope<TPayload = unknown> {
id: string; // evt_<ULID>
tenantId: string;
spaceId: string;
eventType: string; // PascalCase past-tense
eventSchemaVersion: number; // integer per event type
subjectType: string; // PascalCase, must be registered
subjectId: string;
actorId: string;
actorType: string; // see ActorType enum
actionInvocationId?: string; // empty for platform-emitted events not tied to an action
payload: TPayload;
sequence: number; // monotonic per tenant + space ledger
occurredAt: Date;
recordedAt: Date;
correlationId: string;
causationId?: string;
}public interface IAssetEventEnvelope<TPayload>
{
string Id { get; } // evt_<ULID>
string TenantId { get; }
string SpaceId { get; }
string EventType { get; } // PascalCase past-tense
int EventSchemaVersion { get; } // integer per event type
string SubjectType { get; } // PascalCase, must be registered
string SubjectId { get; }
string ActorId { get; }
string ActorType { get; } // see ActorType enum
string? ActionInvocationId { get; } // empty for platform-emitted events not tied to an action
TPayload Payload { get; }
int Sequence { get; } // monotonic per tenant + space ledger
DateTime OccurredAt { get; }
DateTime RecordedAt { get; }
string CorrelationId { get; }
string? CausationId { get; }
}Field semantics
| Field | Required | Notes |
|---|---|---|
id | yes | Sortable Crockford-ULID with evt_ prefix. |
tenantId, spaceId | yes | Replay scope dimensions. Filtered first. |
eventType | yes | Must be in the event type registry. |
eventSchemaVersion | yes | Bump when payload shape changes. Old events still replay against old shape. |
subjectType | yes | Must be in the subject type registry. |
subjectId | yes | The entity this event is about. |
actorId, actorType | yes | Who/what caused the event. |
actionInvocationId | no | Present for events caused by a handler. Absent for some platform events. |
sequence | yes | Tenant/space ledger cursor. It remains ordered after filtering but may have gaps. |
occurredAt | yes | Domain time. May differ from recordedAt for backfills. |
recordedAt | yes | Platform-stamped time of append. |
correlationId | yes | Stable across all events of a related invocation chain. |
causationId | no | Direct parent invocation. Forms a tree for sagas. |
Registration API
From packages/platform/events/index.ts:
export function registerSubjectType(type: string): void;
export function isValidSubjectType(type: string): boolean;
export function getRegisteredSubjectTypes(): string[];
export function registerEventType(type: string): void;
export function isValidEventType(type: string): boolean;
export function getRegisteredEventTypes(): string[];
export interface EventTypeRegistry {
register(eventType: string): void;
has(eventType: string): boolean;
list(): string[];
}
export function createEventTypeRegistry(initial?: string[]): EventTypeRegistry;public static class SubjectTypeRegistry
{
public static void Register(string type);
public static bool IsValid(string type);
public static IReadOnlyList<string> GetRegistered();
}
public static class EventTypeRegistry
{
public static void Register(string type);
public static bool IsValid(string type);
public static IReadOnlyList<string> GetRegistered();
}
public interface IEventTypeRegistry
{
void Register(string eventType);
bool Has(string eventType);
IReadOnlyList<string> List();
}
public static IEventTypeRegistry CreateEventTypeRegistry(IEnumerable<string>? initial = null);Verticals do not call these directly. They declare event types in their FabricModule.eventTypes, and registerFabricModule calls the registration functions for them.
Pre-registered subject types
| Subject type |
|---|
ActionInvocation |
PolicyEvaluation |
AdapterInvocation |
Pre-registered event types
| Event type | Description |
|---|---|
ComplianceBlocked | A policy returned block. |
StateTransitioned | A validated transition recorded in the action's event phase. |
AdapterInvocationStarted | Adapter step beginning. |
AdapterInvocationSucceeded | Adapter step success. |
AdapterInvocationFailed | Adapter step terminal failure. |
WebhookReceived | Webhook captured by integration adapter. |
Host StateTransitioned payload
After a bound state-machine transition validates and the handler succeeds, Host appends this
version-1 fact immediately after domain events in the action's eventPhase. With
transactionWithEvents, it shares the domain events' transaction in that phase; stores without
that capability retain the legacy non-atomic boundary, as they do for domain events:
interface StateTransitionedPayload {
entityType: string;
entityId: string;
fromState: string;
toState: string;
causedByAction: string; // action.actionId
}subjectType is entityType and subjectId is entityId. fromState comes from the trusted
pre-handler state read. The schema version is 1 independently of the action version.
The event is publishable through the outbox by default; applications can filter it with
outbox.shouldPublish.
With before_adapters, the transition is appended during handler execution. With
after_adapters, domain events and the transition are deferred to finalization after required
adapter steps succeed or accept a parked external handoff. Adapter failure withholds both,
so this invocation does not advance the built-in stores' ledger-derived entity state. Handler
writes may have committed separately; custom stores reading domain rows can observe that state. Atomic stores commit the deferred events and invocation finalization
in one transactionWithEvents call; fallback stores append them non-atomically.
Host skips emission for an empty target, an undefined or empty entity ID, an invalid transition,
a failed handler, or idempotent replay without matching saved transition evidence. The replay
shortcut requires the current state's event to carry the same actionInvocationId; a new
invocation validates normally and fails unless the machine defines the edge. A
handler-returned StateTransitioned for the same subject type and ID suppresses the
Host-generated fact in either phase. Applications should remove that workaround to use
Host emission.
For idempotent after_adapters actions, Host persists the validated transition as the invocation's
optional pendingStateTransition. With a mutation transaction, it writes the field after the handler
succeeds and result/events validate, just before the transaction callback returns. Without that
capability, it writes before the handler. Non-idempotent actions do not write the field.
The saved transition is retained as evidence after completion.
On recovery, an admitted same-invocation replay
can emit the original fromState if the saved entity type, entity ID, and target match the binding
and current state. The event keeps its invocation-scoped state:transition ID; memory and
PostgreSQL stores ignore duplicate event IDs, including through the outbox path.
Custom stores must persist and reload pendingStateTransition through store-level and
transaction-scoped updateActionInvocation to support this recovery emission. In a mutation
transaction, the field commits or rolls back with the domain writes. PostgreSQL ensureSchema()
adds the pending_state_transition column. Invocations started before upgrading have no saved
transition and get no re-emitted Host fact; missing or mismatched evidence also leaves emission
suppressed. Host does not infer an earlier fromState from the already-reached target.
Naming rules
Enforced by convention; tooling rejects in code review:
- Event types: PascalCase, past tense fact (
PlanAccepted). Never imperative (AcceptPlan). - Subject types: PascalCase noun (
Plan,Order). - Action IDs:
<namespace>.<snake_verb>(orders.submit). - Policy IDs:
<id>.v<integer>(orders.payment_consent.v1).
Schema versioning rules
When a payload shape changes:
- Bump
eventSchemaVersionfor the affected event type. - Add a new schema for the new version. Keep the old schema accessible.
- Projection reducers that consume both versions branch on
event.eventSchemaVersion. - Never edit past events. The platform replays them as-is.
Common safe changes that don't require a bump:
- Adding optional fields with sensible default behavior in reducers.
Changes that do require a bump:
- Removing a field.
- Renaming a field.
- Changing a field type.
- Adding a required field.
ID format
^[a-z][a-z0-9]{1,7}_[0-9A-Z]{26}$The 26-character suffix is a Crockford-base32 ULID (10 chars time + 16 chars random). The evt_ prefix is fixed for events.
See also
- Events as evidence: the design rationale.
- Event emission stage: how the runtime appends.
- Projection mechanics: how the log is consumed.