Event emission and sequencing
How AssetEvents are appended, ordered, and bound to the action that caused them.
A mutating action must emit at least one AssetEvent. The action registry enforces this at registration time:
// packages/platform/actions/index.ts
if (definition.mutatesDomain && definition.emitsEvents.length === 0) {
throw new Error(
`Action "${definition.actionId}" mutates domain but emits no events.`,
);
}// packages/platform/actions/index.ts
if (definition.MutatesDomain && definition.EmitsEvents.Count == 0)
{
throw new InvalidOperationException(
$"Action \"{definition.ActionId}\" mutates domain but emits no events.");
}This is not a style preference. The event log is the source of truth for everything else (read models, projections, audit, analytics). An action that mutates state without emitting an event creates a divergence.
What gets emitted
The handler appends events via the platform's event-append API in the same transaction as its domain writes. Each event becomes an AssetEventEnvelope:
interface AssetEventEnvelope<TPayload = unknown> {
id: string; // evt_<ULID>
tenantId: string;
spaceId: string;
eventType: string; // e.g. "PlanAccepted"
eventSchemaVersion: number;
subjectType: string; // e.g. "Plan"
subjectId: string;
actorId: string;
actorType: string;
actionInvocationId?: string;
payload: TPayload;
sequence: number; // tenant/space ledger cursor
occurredAt: Date;
recordedAt: Date;
correlationId: string;
causationId?: string;
}public class AssetEventEnvelope<TPayload>
{
public string Id { get; set; } = default!; // evt_<ULID>
public string TenantId { get; set; } = default!;
public string SpaceId { get; set; } = default!;
public string EventType { get; set; } = default!; // e.g. "PlanAccepted"
public int EventSchemaVersion { get; set; }
public string SubjectType { get; set; } = default!; // e.g. "Plan"
public string SubjectId { get; set; } = default!;
public string ActorId { get; set; } = default!;
public ActorType ActorType { get; set; }
public string? ActionInvocationId { get; set; }
public TPayload Payload { get; set; } = default!;
public int Sequence { get; set; } // tenant/space ledger cursor
public DateTime OccurredAt { get; set; }
public DateTime RecordedAt { get; set; }
public string CorrelationId { get; set; } = default!;
public string? CausationId { get; set; }
}Sequencing model
| Field | Scope | Property |
|---|---|---|
sequence | Per tenant + space ledger | Strictly increasing in the complete ledger; filtered streams may have gaps. |
recordedAt | Global | When the platform appended it. |
occurredAt | Per event | When the underlying fact happened. |
correlationId | Per request thread | Shared across all events of a related invocation. |
causationId | Immediate parent invocation | Forms a tree when sagas spawn child actions. |
Within a subject, the ledger cursor preserves order even though other subjects create gaps. Event
sources that expose a contiguous subject-local cursor use ReplayableAssetEvent.subjectSequence.
Global replay uses recordedAt with deterministic tiebreakers (action ID, correlation, subject,
sequence, see packages/platform/projections/index.ts:compareGlobalEvents).
Naming conventions
Event types are PascalCase past-tense facts:
| Good | Bad |
|---|---|
PlanAccepted | AcceptPlan (imperative) |
CreditPullCompleted | UpdateCreditStatus (CRUD) |
LeadIngested | LeadCreate (verb-noun mix) |
Past tense matters: events describe what happened, not what is being requested. The verb form belongs on the action ID (orders.submit), not the event.
Event type registry
A vertical declares its event types in its FabricModule:
{
eventTypes: [
{ eventType: "PlanAccepted", schema: planAcceptedPayloadSchema, version: 1 },
"PlanDeclined", // shorthand: name only
],
}new FabricModule
{
EventTypes =
[
new EventTypeRegistration("PlanAccepted", planAcceptedPayloadSchema, version: 1),
"PlanDeclined" // shorthand: name only
]
};The platform pre-registers a small set of cross-cutting event types:
ComplianceBlockedStateTransitionedAdapterInvocationStarted,AdapterInvocationSucceeded,AdapterInvocationFailedWebhookReceived
Host emits ComplianceBlocked, StateTransitioned, AdapterInvocationStarted,
AdapterInvocationSucceeded, and AdapterInvocationFailed. WebhookReceived comes from
integration adapters; registration alone does not cause Host to emit it.
For a validated bound transition on an entity with a non-empty ID, Host appends
StateTransitioned immediately after the handler's domain events in the action's eventPhase.
With transactionWithEvents, both share the transaction used for that phase; otherwise they
follow the legacy non-atomic boundary. Under after_adapters, the events are deferred until
finalization after required adapter steps succeed or accept a parked external handoff.
Adapter failure withholds the transition and domain events, leaving Host's recorded state
unchanged by that invocation. Host suppresses its fact if the handler returns one for the same
entity; applications should remove that workaround.
See the payload and emission conditions.
Schema versioning
eventSchemaVersion carries an integer per event type. When you change a payload shape:
- Bump the version.
- Add a new schema for the new version.
- Keep the old schema deserializable for replay (events from before the change still exist).
The platform's projection engine does not migrate old events. It replays them as they were. Projections that read both versions handle the difference.
Diagram
The transaction boundary is the guarantee. If the commit fails, neither the domain write nor the event lands.
See also
- Events as evidence: why this design.
- Event schema reference: full envelope, registration API.
- Projections: what consumes the log.