Skip to main content

Overview

Domain events represent facts about what has happened in the system. They are the single source of truth and are persisted to the event store. The read model is derived by projecting these events.

Event Structure

All events share these base fields:
sequence
number
required
Global event sequence number (monotonically increasing)
eventId
string
required
Unique event identifier (UUID)
aggregateKind
'project' | 'thread'
required
Type of aggregate root
aggregateId
string
required
Aggregate instance identifier (projectId or threadId)
type
string
required
Event type discriminator (e.g., "project.created")
occurredAt
string
required
ISO 8601 timestamp when event occurred
commandId
string | null
required
Command that caused this event (null for spontaneous events)
causationEventId
string | null
required
Event that caused this event (for cascading effects)
correlationId
string | null
required
Original command ID for tracking related events
metadata
object
required
Additional event metadata
payload
object
required
Event-specific data

Push Event Format

Events are broadcast to clients via the orchestration.domainEvent channel:
{
  "type": "push",
  "channel": "orchestration.domainEvent",
  "data": {
    "sequence": 43,
    "eventId": "evt-abc123",
    "aggregateKind": "thread",
    "aggregateId": "thread-789",
    "type": "thread.created",
    "occurredAt": "2026-03-07T12:00:00.000Z",
    "commandId": "cmd-xyz",
    "causationEventId": null,
    "correlationId": "cmd-xyz",
    "metadata": {},
    "payload": {
      "threadId": "thread-789",
      "projectId": "proj-456",
      "title": "New conversation",
      "model": "gpt-5-codex",
      "runtimeMode": "full-access",
      "interactionMode": "default",
      "branch": null,
      "worktreePath": null,
      "createdAt": "2026-03-07T12:00:00.000Z",
      "updatedAt": "2026-03-07T12:00:00.000Z"
    }
  }
}

Project Events

project.created

A new project has been created.

project.meta-updated

Project metadata has been updated.

project.deleted

A project has been soft-deleted.

Thread Lifecycle Events

thread.created

A new thread has been created.

thread.deleted

A thread has been soft-deleted.

thread.meta-updated

Thread metadata has been updated.

thread.runtime-mode-set

Thread runtime mode has changed.

thread.interaction-mode-set

Thread interaction mode has changed.

Message Events

thread.message-sent

A message has been added to the thread.
Assistant messages may be sent incrementally with streaming: true, followed by a final event with streaming: false.

Turn Events

thread.turn-start-requested

A user has requested to start a new turn.

thread.turn-interrupt-requested

A user has requested to interrupt the active turn.

thread.turn-diff-completed

A turn has completed and its checkpoint/diff has been recorded.

Session Events

thread.session-set

Provider session state has been updated.

thread.session-stop-requested

A user has requested to stop the session.

Approval & User Input Events

thread.approval-response-requested

A user has responded to a provider approval request.

thread.user-input-response-requested

A user has responded to a provider user input request.

Checkpoint Events

thread.checkpoint-revert-requested

A user has requested to revert to a previous checkpoint.

thread.reverted

A checkpoint revert has been completed.

Activity Events

thread.activity-appended

A new activity log entry has been added to the thread.

thread.proposed-plan-upserted

A provider has proposed or updated a plan.

Event Ordering

Events are guaranteed to be:
  1. Globally ordered by sequence number
  2. Per-aggregate ordered within their stream
  3. Causally ordered via causationEventId and correlationId

Event Replay

Use the orchestration.replayEvents method to replay events:
const request = {
  id: crypto.randomUUID(),
  body: {
    _tag: 'orchestration.replayEvents',
    fromSequenceExclusive: 0, // Start from beginning
  },
};

ws.send(JSON.stringify(request));
This is useful for:
  • Building read models
  • Catching up after reconnection
  • Debugging state issues
  • Implementing event handlers

Source Code

Event schemas are defined in:
  • Contracts: packages/contracts/src/orchestration.ts:557-982
  • Event Store: apps/server/src/orchestration/Services/EventStore.ts
  • Projections: apps/server/src/orchestration/Projections/
  • Push Broadcast: apps/server/src/wsServer.ts:577-583

Next Steps

Commands

Learn about commands that generate events

Orchestration API

Explore the full orchestration API

WebSocket Protocol

Understand the transport layer

Build docs developers (and LLMs) love