Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Events API

Canonical reference: docs/api-reference.md (generated endpoint directory) — this page is a task-oriented summary.

Sol uses a Mnesia-backed event sourcing system as its orchestration backbone. The Events API provides read access to the event stream and real-time SSE subscriptions.

List Events

GET /api/v1/events

Query the event store with filters and pagination.

curl -H "Authorization: Bearer $TOKEN" \
  "https://sol.example.com/api/v1/events?aggregate=task-123&limit=20"

Query Parameters

ParameterTypeDefaultDescription
aggregatestring—Aggregate ID to read
user_uuidstring—Admin selector for that user’s events (a non-admin is always scoped to their own user_uuid)
sinceinteger0Unix-ms timestamp cursor — only events with timestamp > since (per-user/global reads)
since_idstring—Tuple-cursor tiebreak for since (see below)
from_seqinteger0Inclusive aggregate replay cursor (seq >= from_seq; seq 0 included)
cursorstring—Aggregate page cursor "<seq>:<event_id>" from next_cursor; resumes strictly after that row. Do not combine with offset or from_seq (typed 400)
limitinteger50Maximum events to return (clamped 1..500)
offsetinteger0Pagination offset (aggregate reads: max 10001)

Response:

{
  "items": [
    {
      "id": "evt-1744730000000",
      "type": "task.completed",
      "aggregate_id": "task-123",
      "seq": 42,
      "timestamp": 1744730000000,
      "data": {
        "task_id": "task-123",
        "worker_id": "luna-01",
        "status": "ok",
        "duration_ms": 3200
      }
    }
  ],
  "limit": 50,
  "offset": 0,
  "page": 1,
  "has_more": true,
  "next_cursor": "42:evt-1744730000000"
}

Aggregate reads carry no total/total_pages — an aggregate count would require walking the whole aggregate, which the indexed read deliberately avoids. next_cursor is the exact {seq, event_id} pair of the last row; pass it back as ?cursor=<seq>:<event_id> (offset and from_seq must be omitted — combining them is a typed 400). This keeps duplicate-seq rows reachable. A caller-scoped read that would scan past the server’s bounded index-row cap answers 400 aggregate_scan_limit_exceeded.

The per-user/global (no ?aggregate) reads keep the pagination envelope with total, total_pages, newest_timestamp and newest_id; pass newest_timestamp + newest_id back as the next since + since_id.

Tuple cursor: pass since_id=<seq> to get an id-tiebreak cursor — events sharing the same millisecond are never skipped or duplicated at page boundaries. Poll with BOTH since + since_id and use newest_timestamp + newest_id for the next iteration.

Event Structure

Every event in the store follows a consistent schema:

FieldTypeDescription
idstringUnique event identifier
typestringEvent type (see below)
aggregate_idstringAggregate root identifier
seqintegerMonotonic sequence within aggregate
timestampintegerUnix timestamp (milliseconds)
dataobjectEvent payload

Event Types

Sol defines 102 event types (machine-derived census) across the categories below. Each validated type is versioned and checked at ingestion (sol_event_validator). The list here is the common set, not the exhaustive catalog — the sync stream also carries channel.message_sent, circuit.*, cluster.*, provider.*, session.* (checkpoint/branch lifecycle), worker.connected/worker.disconnected, task.assigned/ task.dropped, and workflow.branch_created/workflow.compensation* events.

Task Events

TypeAggregateDescription
task.createdtask_idNew task submitted
task.startedtask_idTask began executing
task.completedtask_idTask finished successfully
task.failedtask_idTask execution failed
task.dispatchedtask_idTask sent to a worker

Model Events

TypeAggregateDescription
model.startedmodel_nameInference instance started
model.stoppedmodel_nameInference instance stopped
model.failedmodel_nameInference startup failed
model.discoveredmodel_nameModel found during discovery
model.preparingmodel_namePrepare accepted, rsync running (async)
model.preparedmodel_nameModel files prepared
model.prepare_failedmodel_namePrepare failed (row reverts to discovered)
model.start_failedmodel_nameModel failed to start

Worker Events

TypeAggregateDescription
worker.spawnedworker_idWorker process created
worker.crashedworker_idWorker process crashed
worker.readyworker_idWorker announced readiness
worker.statusworker_idWorker status change (idle/busy/…)
worker.task_startedtask_idWorker began a task
worker.task_completedtask_idWorker finished a task
worker.task_failedtask_idWorker task failed
worker.spawn_failedworker_idWorker spawn failed
worker.killedworker_idWorker killed by operator

Inference Events

TypeAggregateDescription
inference.requestrequest_idInference request received
inference.completerequest_idInference completed
inference.errorrequest_idInference error
inference.interruptedrequest_idInference interrupted

Scheduler Events

TypeAggregateDescription
scheduler.job_createdjob_idScheduled job created
scheduler.job_executedjob_idJob executed
scheduler.task_dispatchedjob_idJob dispatched a task

Workflow Events

TypeAggregateDescription
workflow.startedworkflow_idWorkflow began
workflow.completedworkflow_idWorkflow finished
workflow.failedworkflow_idWorkflow failed
workflow.step_startedworkflow_idWorkflow step started
workflow.compensation_failedworkflow_idCompensation step failed

Agent Events

TypeAggregateDescription
agent.turn_startedtask_idAgent turn began
agent.turn_completedtask_idAgent turn completed
agent.context_overflowtask_idContext exceeded limits
agent.diagnostictask_idAgent diagnostic event
agent.loop_warningtask_idPossible agent loop detected
agent.loop_detectedtask_idAgent loop confirmed

Team Events

TypeAggregateDescription
team.createdteam_idTeam created
team.member_joinedteam_idMember joined team
team.member_leftteam_idMember left team
team.mail_sentteam_idTeam mail sent
team.mail_expiredteam_idTeam mail row expired (TTL)
team.destroyedteam_idTeam destroyed

Memory Events

TypeAggregateDescription
memory.decayedagent_idMemory importance decayed
memory.reflectedagent_idMemory reflection triggered

Note: there are no memory.stored / memory.accessed / memory.forgotten sync events, and no audit.* sync events — the audit trail is the append-only JSONL log (sol_audit_log), not the sync-event store. See Audit.

SSE Streaming

Real-time event streaming via Server-Sent Events:

GET /api/v1/sync-events
curl -N -H "Authorization: Bearer $TOKEN" \
  https://sol.example.com/api/v1/sync-events

SSE event format:

event: sync_event
data: {"id":"evt-1744730001","aggregate_id":"task-456","seq":7,"type":"task.completed","data":{"task_id":"t-456","status":"ok"},"timestamp":1744730001000}

event: sync_event
data: {"id":"evt-1744730002","aggregate_id":"worker-luna-02","seq":1,"type":"worker.ready","data":{"worker_id":"luna-02"},"timestamp":1744730002000}

Every event is emitted under a single event: sync_event line; the event’s own type (e.g. task.completed, worker.ready) is carried inside the JSON data. Use the categories query parameter to filter which event types you receive. A keep-alive comment (: ping) is sent every 15 seconds.

Event Hooks

Events support pre-commit and post-commit hooks. Hooks are registered programmatically:

Pre-commit hooks can validate or enrich event data before persistence Post-commit hooks trigger side effects (notifications, projections, ZMQ broadcasts)

Event Store

The event store is backed by Mnesia with automatic sequence numbering per aggregate. Key properties:

Events are append-only and immutable Each aggregate maintains a monotonic sequence counter Events are replayable for state reconstruction Projections can be registered for materialized views