pipeline-executions
What it does
CRUD and lifecycle surface for public.pipeline_executions — the durable ledger of pipeline runs. One row per run carries pipeline_id, status, trigger_data, result, error_message, started_at, completed_at, and duration_ms. The pipeline runner writes most transitions itself; this endpoint is how operators and the admin UI read run history and how scripts create, start, complete, cancel, or prune rows.
Route and methods
/.netlify/functions/pipeline-executions — also reachable as /api/pipeline-executions (/api/* → /.netlify/functions/:splat in .framework/public/_redirects; same rewrite in the dev proxy, config/vite.config.ts).
Dispatch is by ?action= query parameter plus HTTP method (the middleware copies event.httpMethod into ctx.query.method):
| Call | Handler |
|---|---|
GET (no action, no id) | list |
GET&id= | get — single row by id |
GET?action=list | list |
GET?action=running | getRunning — status = 'running' rows |
GET?action=stats | getStats — status counts |
POST (no action) | create — insert a pending execution |
POST?action=cleanup | cleanup — delete old rows |
PATCH?action=start | start — set running + started_at |
PATCH?action=complete | complete — set terminal status |
PATCH?action=cancel | cancel — set cancelled |
Any other action/method combination throws Invalid action or method.
Authentication
Wrapped in createHandler, so the request must resolve to a non-anonymous principal — Bearer JWT (human), x-api-key (machine), or x-internal-secret (internal) per resolvePrincipal. Anonymous requests get 401 before the handler runs.
System admins (roles contains system_admin) read through adminDb across all accounts. Everyone else reads through their scoped ctx.db and must have an account context — list, running, and stats throw Account context required without one.
Request contract
Query parameters:
id— execution UUID.getrequires it; the middleware also copies it intobody.idfor write actions.pipeline_id— filter forlist,running,stats.status— filter forlist.date_from,date_to—created_atbounds forstats.limit(default 100),offset(default 0) —listpagination.
Body fields:
create:pipeline_id(required),trigger_data(optional object).start/cancel:id(required).complete:id(required),output_data,error_message. A non-emptyerror_messagemakes the final statusfailed; otherwisecompleted.cleanup:days_to_keep(default 30),status_filter(optional) — deletes rows withcreated_atolder than the cutoff.
Response contract
All successful returns are wrapped by the middleware in { data, error: null, meta: { requestId, duration } }.
list/running— array ofpipeline_executionsrows, newest first (listbycreated_at,runningbystarted_at).get— one row.stats—{ total, completed, failed, running }counted in memory over the filtered set.create—{ execution_id }.start/complete/cancel—{ success: true }.cleanup—{ deleted_count }.
Side effects
createinserts a row withstatus: 'pending', stamped withcreated_byandaccount_id.start/complete/cancelupdate status and timestamps;completealso writesresult,error_message, andduration_mscomputed fromstarted_at.cleanupdeletes rows permanently.- Each write emits an audit log:
pipeline_execution.created,pipeline_execution.started,pipeline_execution.completed,pipeline_execution.cancelled,pipeline_executions.cleaned.
Errors
Execution ID is required—get,start,complete,cancelwithoutid.Pipeline ID is required/Account context required—createvalidation; account check onlist,running,statsfor non-admins.Invalid action or method— unmatched action/method pair.getuses.single()— a missing id surfaces as a database error, not a clean 404.- All thrown errors become structured 500 responses unless they carry a
statusCode.
Agent notes
createhere stampsstatus: 'pending'— a different value from thequeuedrows the trigger engine creates before dispatching topipeline-runner-background. Both are non-terminal.- Rows stuck in
queuedorrunningmean dispatch or the runner died;sweepStaleExecutionsin.framework/functions/_shared/pipeline-runner.tsmarksrunning/pending/queuedrows untouched for over 10 minutes asfailed. cancelonly updates the row — nothing in this function interrupts an in-flight run.statsloads all matchingid, statusrows and counts in memory; it has nolimitguard, so very large histories are expensive.