Skip to content

WakeEvent

Describes why an entity handler was invoked. Passed as the second argument to the handler function.

Source: @durable-streams/darix-runtime

ts
type WakeEvent = {
  source: string
  type: string
  fromOffset: number
  toOffset: number
  eventCount: number
  payload?: unknown
  summary?: string
  fullRef?: string
}

Fields

FieldTypeDescription
sourcestringURL or identifier of the stream that triggered the wake.
typestringWake type — one of "message_received" or "wake". See catalog.
fromOffsetnumberStart offset of new events in the source stream.
toOffsetnumberEnd offset (exclusive) of new events.
eventCountnumberNumber of new events in this wake.
payloadunknownOptional payload data associated with the wake. Shape depends on type.
summarystringOptional human-readable summary of the wake reason.
fullRefstringOptional full reference identifier for the wake source.

Wake-type catalog

Handlers see exactly two values for wake.type. Everything that isn't a direct inbox message is flattened into "wake", with the specifics carried on wake.payload.

"message_received"

An external message landed in the entity's inbox — from ctx.send(), the CLI's darix send, or any direct /send HTTP call.

FieldShape
wake.sourceThe from field of the message (sender identifier), or the entity URL if absent.
wake.payloadThe message payload (any JSON-serialisable value).
wake.summaryThe message_type if the sender set one.

"wake"

A synthesised wake for any non-message trigger. wake.payload is a WakeMessage:

ts
type WakeMessage = {
  timestamp: string
  source: string
  timeout: boolean
  changes: Array<{
    collection: string
    kind: "insert" | "update" | "delete"
    key: string
  }>
  finished_child?: {
    url: string
    type: string
    run_status: "completed" | "failed"
    response?: string
    error?: string
  }
  other_children?: Array<{
    url: string
    type: string
    status: "spawning" | "running" | "idle" | "stopped"
  }>
}

Inspect the payload to distinguish the sub-kind:

Sub-kindProducerPayload marker
Child finishedctx.spawn(..., { wake: 'runFinished' }) when the child completes or failspayload.finished_child is set (with run_status and optional response)
Observed changectx.observe(..., { wake: { on: 'change' } }) or observe(db(...))payload.changes is non-empty
Shared-state changeawait ctx.observe(db(...), { wake: { on: 'change' } })payload.changes is non-empty, payload.source identifies the shared-state stream
Cron firedA cron schedule entry on the entity's manifestpayload.source identifies the schedule; payload.changes is empty
Scheduled sendA future_send schedule firesArrives as "message_received" (not "wake") — the schedule produces a message delivery
TimeouttimeoutMs on a change wake config elapsed with no changespayload.timeout === true, payload.changes is empty

For the narrative on how these are produced, see Waking entities.

Wake

The Wake type configures when a parent should be woken in response to a child, observed entity, or shared state change. Used in ctx.spawn(), ctx.observe(), and ctx.observe(db(...)) options.

ts
type Wake =
  | "runFinished"
  | { on: "runFinished"; includeResponse?: boolean }
  | {
      on: "change"
      collections?: string[]
      debounceMs?: number
      timeoutMs?: number
    }

'runFinished'

Wake the parent when the child's agent run completes (status changes to completed or failed). By default, the wake event includes the child's concatenated text response in finished_child.response.

{ on: 'runFinished', includeResponse?: boolean }

Object form of runFinished with options. Set includeResponse: false to omit the child's text response from the wake event.

{ on: 'change' }

Wake the parent when changes occur in the observed stream.

FieldTypeDescription
on'change'Required discriminant.
collectionsstring[]Optional filter. Only wake on changes to these collections.
debounceMsnumberDebounce interval in milliseconds. Batches rapid changes.
timeoutMsnumberMaximum time to wait before waking, even if no changes occur.