Events
An Event is a named occurrence appended to a Workspace’s Event history with a payload. Events describe what happened alongside the Items’ current state; a Runtime never rebuilds Item state from them. This chapter defines Event identity, origin, publishing, processing and the bounds on Event chains.
Identity and payload
Section titled “Identity and payload”- An Event is declared on an App, a Template or a Union with
addEventand named by a PRN. - Every appended Event has an Identifier, a Workspace, an Event PRN, the Item it was published against, a creation time, a payload and a trace Identifier. An Event declared on an App is published against the Workspace Item.
- The payload is parsed against the Event’s declared input Properties at publish time. A payload that fails parsing is rejected before anything is appended.
- An Event carries the Identifier of the principal that caused it when the publishing context is
principal,masqueradeorsudo. - An Event carries its lineage: the Identifier of the parent Event being processed when it was published, the Identifier of the root Event of the chain, and the Event PRNs from the root to the parent. An Event with no parent starts a new chain.
- A Runtime never modifies an appended Event’s identity, payload or lineage.
External and internal Events
Section titled “External and internal Events”- An external Event enters the Workspace from outside any execution: a user action, a schedule or an external system.
publishExternalEventenqueues one for processing.execute('readwrite', event, fn)takes the Event being processed as its first argument, so every write and every Event published insidefncarries its lineage. - An internal Event is published from inside a write execution with
publishorimmediate. Its parent is the Event the execution is processing. - Starting a write execution with origin metadata appends nothing. Only
publish,immediateandpublishExternalEventappend Events. - A schedule (
addSchedule) publishes an external Event on each due tick: one against the Workspace Item for an App Event, or one per Item of the Template for a Template Event, restricted to the states the schedule names when it names any. Timing is best effort.
Publishing and processing
Section titled “Publishing and processing”publishappends one Event per payload for asynchronous processing. Awaitingpublishawaits the append within the active execution, not the Listeners.- An Event appended during a write execution becomes eligible for processing when the execution commits. A failed execution leaves no Event.
immediateappends the Event and runs its Listeners inline, inside the active execution, before returning. The reactor never processes animmediateEvent.- Processing an asynchronously published Event runs each Listener registered on the Event, then each parent Listener registered on the Templates along the Item’s parent chain below the Workspace Item, in one write execution under a
systemcontext. That execution is deduplicated by Event Identifier, so the Listeners of one Event are applied at most once. - Neither
publishnorimmediatereturning implies that projections or external effects have completed. Unit of Work defines the commit and failure rules.
Created Event
Section titled “Created Event”- Every Template exposes
events.created. Reading it declares an Event keyedcreatedon the Template, described as “The item has been created”, with no input Properties. Enumeratingeventsdoes not declare it. - When a write execution creates an Item of a Template that declares
created, withcreateChild,upsertChildByKeyorupsertChildrenByKey, the Runtime publishescreatedagainst the new Item with a{}payload, aspublishdoes. An upsert that updates an existing child publishes nothing. createdis reserved:addEvent('created')fails witherror-002-key-in-use.- Only the Runtime publishes
created: a Write Item’seventsdoes not include it.
Handlers
Section titled “Handlers”- A Query runs in a read execution and publishes no Events.
- Mutations, Listeners, parent Listeners and App Hooks run in write executions and may publish Events.
- A Listener receives the Event, the Item it was published against, the App instance that declared the Listener and the write context. A parent Listener also receives the parent Item.
- An App Hook (
onCreate,onSeed) is a lifecycle Listener. It runs when a Workspace is created or seeded, receives a system write context and aprevchain, and is not triggered by Item Events.
Circular references
Section titled “Circular references”- Child Event declarations (
addChildEvent) must not form a cycle. The Builder rejects a Definition whose declared child Events are circular. - A Runtime must reject publishing an Event whose PRN already appears in the lineage of the Event being processed. The rule applies to
publishandimmediatealike.
- A Runtime must bound Event chain depth at 20: an Event whose lineage already holds 20 PRNs cannot publish a child. The bound applies to inline and asynchronous chains alike (Limits and errors).
Related
Section titled “Related”- Behavior and change explains Events, Listeners and operations.
- Handle events declares Events and Listeners and tests them with
tickAll. - Event processing describes how each reactor claims and processes Events.
WriteEventPublishInstanceexposespublishandimmediate.

