Triggers and webhooks

Since 0.8.0 the engine can drive a pipeline’s runs itself. You start a run by hand, on a schedule or from another system through a signed webhook. This guide covers run control, schedules and webhooks. For the definition syntax, see Pipelines and packs. For a worked example, see the Impulse coaching pack.

Run control applies to engine-controlled pipelines, such as impulse-coach. The SDLC is host-controlled: its runs still move through the project pages, and these endpoints refuse it with 409 RUN_CONTROLLED_BY_HOST.

The examples assume $TEVRIN is your base URL and $PID is the project id. Add your sign-in credentials (a session or an API token) to each call.

Who can do what

Action Who
Start a run, submit an input, retry a failed stage Contributor and up
Cancel or roll back a run Owner
Create, change or delete a schedule; create, rotate or delete a webhook Owner
Decide a tool_approval or external_action gate Owner
Read runs, timelines and schedules (not webhook secrets) Viewer and up
Call a webhook Anyone with the webhook URL and a valid signature. No sign-in

A Contributor who calls an Owner action gets 403 FORBIDDEN. A project you can’t see gives 404 NOT_FOUND.

Run control

Action Endpoint Notes
Start POST /api/projects/{id}/pipeline-runs Body { pipelineId, approvalMode?, inputs? }. inputs maps input artifact keys to JSON
Submit an input POST /api/pipeline-runs/{runId}/inputs/{artifactKey} The JSON body is a new version of an input artifact
Retry POST /api/pipeline-runs/{runId}/retry Re-queues the failed stage. Refused (409 CONFLICT) while a gate is pending or the stage is still running
Cancel POST /api/pipeline-runs/{runId}/cancel Ends the run cancelled and cancels its queued jobs
Roll back POST /api/pipeline-runs/{runId}/rollback Body { targetCheckpoint, reason }. Applies the engine rollback rules

A start creates the run at its start stage, pinned to the pipeline’s current definition. Each input is stored as version 1, checked against its schema. The approval mode defaults to the project’s.

By default a project has one active run of a pipeline. A second start gives 409 RUN_ALREADY_ACTIVE, unless the definition says concurrency: { runs: many }. A pipeline that needs a project-wide artifact, such as the coach’s athlete_profile, needs a locked version first, or the start gives 409 SOURCE_ARTIFACT_MISSING.

curl -X POST "$TEVRIN/api/projects/$PID/pipeline-runs" \
  -H 'Content-Type: application/json' \
  -d '{ "pipelineId": "impulse-coach", "inputs": { "session_log": { "sessions": [] } } }'

When a stage needs an input that isn’t there yet (requires: [{ input: <key> }]), the run is waiting_on_input. Submit the input and the run continues. A body that fails the schema gives 400 INPUT_INVALID with the failing paths.

A run moves one stage at a time. It stops at a gate (waiting_on_gate), at a missing input, or when a stage fails. A failed stage leaves the run active, so you can retry it.

From the UI

Open the project’s Pipeline tab.

  1. Select Start run (Contributor and up; a Viewer doesn’t see it).
  2. Pick the pipeline and, if the definition offers a choice, the approval mode.
  3. Fill in each input. The editor comes from the input’s schema: a form for flat objects, otherwise a JSON editor with schema errors shown inline. You can also upload a JSON file.
  4. Select Start run. A valid submit opens the new run.

A run that waits on input shows Submit input, with the same editor. Cancel, roll back and retry are on the run for the roles in the table above.

Schedules

A pipeline whose definition declares trigger: { kind: schedule } (or lists it under triggers:) can be scheduled per project. Each fire starts a run, with the schedule’s inputs if it has any.

curl -X POST "$TEVRIN/api/projects/$PID/pipeline-schedules" \
  -H 'Content-Type: application/json' \
  -d '{ "pipelineId": "impulse-coach", "cron": "0 6 * * 1", "timezone": "Europe/London" }'
Field Meaning
cron Five fields: minute, hour, day of month, month, day of week
timezone An IANA name, such as Europe/London
inputs Optional input artifacts each fire starts its run with

The example fires every Monday at 06:00 London time: 06:00 UTC in winter and 05:00 UTC in summer.

  • Daylight saving: a local time that doesn’t exist fires at the next valid minute. A time that occurs twice fires once, at the first.
  • Downtime: missed fires run once, then the schedule resumes.
  • A run is still active: the fire is skipped and recorded, unless the definition has on_active: submit and the schedule has an input to submit. Then the input goes to the active run.
  • Record: every fire writes a SCHEDULE_FIRED event with its outcome: started, skipped, submitted or failed.
  • Several API instances: each due schedule fires once.

Manage schedules at /api/projects/{id}/pipeline-schedules. GET lists them, PATCH .../{scheduleId} pauses, resumes or changes one (paused, cron, timezone, inputs), and DELETE removes it. To see the next three fire times before saving, call GET /api/projects/{id}/pipeline-schedules/preview?cron=...&timezone=....

An invalid cron or timezone gives 400 SCHEDULE_INVALID. A pipeline that doesn’t declare a schedule trigger gives 409 TRIGGER_NOT_SUPPORTED.

In the UI, an Owner opens Triggers on the Pipeline tab, selects Add schedule, and sees the Next fire times in the schedule’s timezone before saving.

Webhooks

A pipeline whose definition declares trigger: { kind: webhook, input: <artifact> } accepts signed calls. The JSON body becomes the input artifact.

Create a webhook

An Owner creates it. The response has the url to call and the secret. The secret is shown once, so store it.

curl -X POST "$TEVRIN/api/projects/$PID/pipeline-webhooks" \
  -H 'Content-Type: application/json' \
  -d '{ "pipelineId": "impulse-coach" }'

Reloading the page or listing webhooks never shows the secret again. To replace it, rotate it: POST /api/projects/{id}/pipeline-webhooks/{webhookId}/rotate returns a new secret. The old secret stays valid for 24 hours so the sender can switch over. DELETE .../{webhookId} removes the webhook.

In the UI, an Owner opens Triggers on the Pipeline tab and selects Create webhook. The new secret shows once, with Copy secret and a signing example. Rotate secret asks for confirmation first.

Call it

Send POST /api/hooks/pipelines/{webhookId} with the JSON body and two headers.

Header Value
X-Tevrin-Signature t=<unix seconds>,v1=<hex>, where the hex is HMAC-SHA256(secret, "<t>.<raw body>")
X-Tevrin-Delivery A unique UUID for this delivery

Sign the exact bytes you send. The signature is the lowercase hex of the HMAC-SHA256 of the timestamp, a dot and the raw body.

SECRET='whsec_test'
T=1764590400                      # use $(date +%s) for a real call
BODY='{"a":1}'                    # the exact bytes you send
SIG=$(printf '%s' "$T.$BODY" | openssl dgst -sha256 -hmac "$SECRET" | awk '{print $NF}')

curl -X POST "$TEVRIN/api/hooks/pipelines/$WEBHOOK_ID" \
  -H 'Content-Type: application/json' \
  -H "X-Tevrin-Signature: t=$T,v1=$SIG" \
  -H "X-Tevrin-Delivery: $(uuidgen)" \
  --data-binary "$BODY"

Test vector: secret whsec_test, t = 1764590400, body {"a":1} gives v1=54fe8ee64e5499df7c6cee87b1b22c2800b3fbfed80e088b818a25b927713fb0. The timestamp must be within 300 seconds of the server clock, so the fixed t is only a test vector.

Rules:

  • The raw body is at most 256 KB.
  • The compare is constant-time, and both the current and the previous secret are accepted during a rotation.
  • A delivery id seen in the last 24 hours is a replay.
  • An unknown, deleted or malformed webhook id gets the same 401 as a bad signature.
  • The body must pass the input’s schema.

What happens to the payload

State on_active: skip (default) on_active: submit
No active run A run starts, with the body as the input A run starts, with the body as the input
A run is active 409 RUN_ALREADY_ACTIVE The body is a new version of the input on the active run

A success is 202 with { runId }. The engine logs each delivery (id, status and run) for 30 days.

Response Meaning
202 { runId } A run started, or the active run received the input
401 WEBHOOK_SIGNATURE_INVALID Bad or missing signature, a timestamp more than 300 seconds off, or an unknown webhook
409 WEBHOOK_REPLAY That delivery id was seen in the last 24 hours
409 RUN_ALREADY_ACTIVE A run is active and on_active is skip
400 INPUT_INVALID The body fails the input’s schema
400 VALIDATION The X-Tevrin-Delivery header is missing or isn’t a UUID
413 VALIDATION The body is over 256 KB

Error codes

Code Status Meaning
RUN_CONTROLLED_BY_HOST 409 This pipeline’s runs are started from its own pages
RUN_ALREADY_ACTIVE 409 The project already has an active run of this pipeline
RUN_NOT_ACTIVE 409 The run has finished
INVALID_TARGET_VERSION 400 The rollback checkpoint isn’t valid
INPUT_INVALID 400 An input doesn’t match its schema. The details list the paths
SOURCE_ARTIFACT_MISSING 409 A project-wide artifact the run needs has no locked version
SCHEDULE_INVALID 400 Bad cron or timezone
TRIGGER_NOT_SUPPORTED 409 The pipeline doesn’t declare that trigger
WEBHOOK_SIGNATURE_INVALID 401 Bad, missing or stale signature
WEBHOOK_REPLAY 409 The delivery id was already received

See also Error codes.