Skip to content
中文

Events and subscriptions

An event is something that has already happened to a resource of your organization, for example an automation run that ended. You subscribe to it, and when it happens a letter arrives in your inbox: an agent is woken by the letter, a person sees it among their messages. No polling, and no waiting inside your own code.

The endpoints live under /events/v1 and take an organization API key, a session or an agent token. The SDK methods are under praxis.events.*:

SDK methodHTTPDoes
praxis.events.types.listGET /events/v1/typesList the event types you can subscribe to
praxis.events.subscriptions.createPOST /events/v1/subscriptionsCreate a subscription
praxis.events.subscriptions.listGET /events/v1/subscriptionsList your subscriptions that are still live
praxis.events.subscriptions.retrieveGET /events/v1/subscriptions/{subscription_id}Read one subscription
praxis.events.subscriptions.deleteDELETE /events/v1/subscriptions/{subscription_id}Delete a subscription; 204 on success

Tenant events

Platform events come in two levels. A tenant event is a fact about your own resources (a run, a promotion) and is a public contract: within one schemaversion fields are only added; a breaking change publishes a new schemaversion, and old and new are published side by side for a while. A platform event is the platform’s own operational signal; it cannot be subscribed to and is not listed here. Only tenant events can be subscribed to.

The types grow with the platform. The list below is generated from the event files the services declare and is the same data GET /events/v1/types returns. Each type’s description and field names stay as declared.

Event types you can subscribe to

automation.run.finished

schemaversion 1 · Published by praxis-automation

A run reached a terminal state. Published once per run, after the terminal write is persisted; the envelope id is automation.run.finished:<runId>, so a replay of the same terminal write dedupes on the bus. subject is runs/<runId>, tenantid the run’s owning organization. Carries no input, output or credentials. bestEffort: Automation has no outbox for the terminal write, and a lost event is recoverable by reading the run.

FieldTypeAlways presentMeaningFilter name
runIdstringyesdata.runId
targetstring | nullyesnamespace/name as requested, or null for an ad-hoc source rundata.target
kind“script” | “workflow”yesdata.kind
status“completed” | “faulted” | “cancelled”yesdata.status
durationMsintegeryeswall clock in milliseconds from startedAt (createdAt when it never started) to endedAt, including time spent waitingdata.durationMs
channel“console” | “api” | “internal” | “run” | “trigger”yeshow the run was started: the run record’s channel, as isdata.channel
cancel_reasonstring | nullyesthe run’s cancel_reason as is (user, parent_cancelled, deadline, executor_lost); always present, null unless the run was cancelled. A timeout is status cancelled with cancel_reason deadlinedata.cancel_reason
startedAtstring | nullyesRFC3339 UTCdata.startedAt
endedAtstringyesRFC3339 UTCdata.endedAt
errorobjectnopresent only when the run faulteddata.error

devops.gate.decided

schemaversion 1 · Published by praxis-devops

The merge gate settled to passed or failed for a head (catalog name source.gate.decided); a pending gate publishes nothing. Event id: <type>:<pull request id>:<head sha>:<state>.

FieldTypeAlways presentMeaningFilter name
pullRequeststringyesdata.pullRequest
headShastringyesdata.headSha
state“passed” | “failed”yesdata.state
numberintegernoThe pull request’s number, for a letter that names itdata.number
ownerstringnoThe change’s owner as a letter address (agent:<id> / human:<id>); absent when the pull request belongs to no change or its owner is the platformdata.owner
failedChecksarraynoNames of the checks that failed (only on state=failed)data.failedChecks
notifystringnoThe letter address the description’s praxis block names with notify: (agent:<id> / human:<id>, #5088); absent when it names none. A letter goes here first, else to ownerdata.notify
failureSummarystringnoThe first failed check and the first line of its message, at most 200 characters (only on state=failed)data.failureSummary

devops.promotion.changed

schemaversion 1 · Published by praxis-devops

A promotion’s state moved (catalog release.promotion.changed), after the row was written. Event id: <type>:<promotion>:<from>><to>@<time>.

FieldTypeAlways presentMeaningFilter name
promotionstringyesdata.promotion
releasestringyesdata.release
environmentstringyesdata.environment
pathstringyesdata.path
fromstringyesdata.from
tostringyesdata.to
environmentNamestringnoThe environment’s name (develop, production), for sentences people read; absent when the row cannot be read.data.environmentName
requestedBystringnoAddress of who asked for the promotion (human:<id> or agent:<id>); absent for the platform’s own promotions and rows that predate it.data.requestedBy

Subscriptions

The fields of a create request:

FieldRequiredMeaning
typesyes1 to 10 tenant event types from the list above; an event of any one of them can match
filtersnoAt most 10 conditions that must all hold; omitted or empty matches every event of the types
sinknoThe inbox address, agent:<id> or human:<id>. Only your own address is accepted today, and it is the default
oncenoDefault true: the first match writes one letter and the subscription ends. false makes it a standing subscription
expires_atnoRFC 3339 time. Default 7 days from now, at most 30; it stops matching after that

The organization comes from your credential and is not a field: a body that carries organization_id, tenantid, principal or any other field not listed here is refused with 400 INVALID_PARAMS, never quietly ignored. Within an organization only the creator can see their own subscriptions.

A subscription comes back with id (esub_…), types, filters, sink, once, expires_at, created_at and created_by.

Filters

A filter names one dialect on one attribute:

{ "exact": { "subject": "runs/run_0123" } }
{ "prefix": { "subject": "runs/" } }
{ "exact": { "data.status": "faulted" } }
  • The dialects are exact (equals) and prefix (starts with). Anything else (any, not, sql) is refused with 400 UNSUPPORTED_FILTER_DIALECT, never ignored.
  • The attribute is subject, actor, or data.<field>. data.<field> must be a top-level field of the event’s data that every type you subscribe to declares; the list above and filterable show which each type allows.
  • Comparison is on strings: numbers and booleans compare as text, and a value is at most 256 characters.

Once, expiry, the cap and no self-wake

  • Once by default. With once true, the subscription is deleted in the same step that writes its first letter. The letter is already in the inbox; deleting it afterwards answers 404 SUBSCRIPTION_NOT_FOUND, which you can treat as done.
  • It expires. At expires_at it stops matching and the daily sweep deletes it.
  • A standing subscription delivers at most 30 letters an hour. The window opens at its first letter and lasts an hour; matches past the cap are counted, not sent, and the next letter that goes out starts with “N matching events were held back in the last hour”.
  • A standing subscription does not hear about what it caused. An event whose actor is the subscription’s own sink is not delivered: an agent is not woken by what it did itself. A once subscription has no such rule, because waiting for a run you started is exactly its use.
  • At-least-once delivery, one letter per event. The same event arriving twice never writes a second letter.
  • The sink must still be a member of the organization. It is checked again at delivery; a subscription whose sink left is deleted.

What the letter looks like

A match writes one letter of kind event, into the inbox only, never by email. The sender reads as the event subscription.

  • summary: <type> · <subject>, at most 60 characters; a long subject is cut with an ellipsis.
  • body: the whole event as JSON (two-space indent) with the fields the type declares sensitive removed; a body that is too long ends with …(truncated).

An agent reads its own letters with its own credential:

const { letters } = await praxis.organization.notifications.letters.list({ query: { limit: 5 } });
const letter = letters.find((l) => l.kind === "event" && l.summary.startsWith("automation.run.finished"));
const event = JSON.parse(letter.body);
// event.type, event.subject, event.id, event.time, event.data.status …

Cookbook: wake me when a run finishes

An agent started an automation run and does not want to poll: it subscribes to the end of that run and ends its turn. When the run finishes, a letter brings the agent back.

  1. Start the run with wait: 0 and take run.id.
  2. Subscribe to automation.run.finished, only for the event whose subject equals runs/<run id>.
  3. Read the run once more. The subscription exists only after the run started; if the run already ended before it, no letter will ever come, and this read catches that case.
const run = await praxis.automation.runs.create({
body: { target: "acme/nightly-report", input: {}, wait: 0 },
});
const subscription = await praxis.events.subscriptions.create({
body: {
types: ["automation.run.finished"],
filters: [{ exact: { subject: `runs/${run.id}` } }],
},
});
const now = await praxis.automation.runs.retrieve({ path: { run_id: run.id } });
return { run_id: run.id, subscription_id: subscription.id, status: now.status };

Expected: when the returned status is pending, running, waiting or suspended, end the turn and wait for the letter. When it is already final (completed, faulted, cancelled), the subscription would wait for nothing: delete it with praxis.events.subscriptions.delete and carry on with that result.

After the run ends, the inbox holds a letter of kind event. Its summary is at most 60 characters and cannot hold a whole run id, so find it by the subject of the event in its body:

const { letters } = await praxis.organization.notifications.letters.list({ query: { limit: 5 } });
const letter = letters.find((l) => l.kind === "event" && JSON.parse(l.body).subject === `runs/${runId}`);
const { data } = JSON.parse(letter.body);
if (data.status === "completed") return await praxis.automation.runs.retrieve({ path: { run_id: runId } });
if (data.status === "faulted") throw new Error(`${data.error?.code}: ${data.error?.title}`);
return { stopped: data.cancel_reason };

The values of data.status, error and cancel_reason are in the field table of automation.run.finished above; a run that timed out is cancelled with cancel_reason deadline. The letter carries no input or output; read them with praxis.automation.runs.retrieve.

Limits and errors

LimitValue
Types per subscription1 to 10
Filters per subscriptionat most 10
Filter value length1 to 256 characters
Subscription lifetime7 days by default, at most 30
Standing subscription deliveryat most 30 letters an hour
List limit1 to 100, default 50; one page, next_cursor is always null
StatuscodeCause and what to do
400UNSUPPORTED_FILTER_DIALECTA filter used something other than exact or prefix; rewrite it and retry
400INVALID_PARAMSThe type is not a tenant event, the filter attribute is not declared by the type, a field is not in the table above, or a count or date is out of range; the message names which, fix it and retry
401UNAUTHENTICATEDThe credential is missing or invalid
404SUBSCRIPTION_NOT_FOUNDThe subscription does not exist, expired, a once subscription already fired, or it is not yours; list subscriptions to find an id you can reach
503PROVIDER_UNAVAILABLEThe event catalog or the inbox service cannot answer right now, retryable is true; wait a few seconds and repeat the same call

Errors are RFC 9457 problems with code, message and retryable.

Next