A Workflow run can start without anyone calling workflow_<name>: a Workflow
in an organization's namespace subscribes to MCP events with subscriptions,
and each new occurrence starts a run, acting as the organization's principal.
A run can wait for an event, and be cancelled by one. concurrency limits how
many runs of a Workflow run at once, whatever started them. All of it runs on the same
engine and run store as every other run (see Workflows).
muster reads Workflows in its own namespace and, in Kubernetes mode, in every
namespace that has an organization principal (organizationPrincipals in the
OAuth server's configuration). A Workflow of an organization's namespace:
- is seen by whoever sees the MCPServers of that namespace: the principal of
the organization, and a person whom Kubernetes RBAC lets list
mcpserversthere (when muster serves the MCPServers of every namespace).core_workflow_listshows itsnamespace;core_workflow_gettakes one. - has its runs in that namespace, seen by the same callers in
core_workflow_run_list,_get,_cancel,_retryand_signal. - starts children of its namespace's Workflows with
workflow:steps. - is no
workflow_<name>tool: the core catalogue serves the Workflows of muster's namespace. An organization's Workflows are started by theirsubscriptionsand by the runs of their namespace.
subscriptions are valid only in such a namespace. Elsewhere -- muster's own
namespace, or any Workflow in filesystem mode -- the Workflow's status says
subscriptions are valid only in a namespace with an organization principal, which muster subscribes and runs as, and it subscribes to nothing.
core_workflow_create, _update and _validate, which are for muster's
namespace, refuse them.
apiVersion: muster.giantswarm.io/v1alpha1
kind: Workflow
metadata: { name: sdlc, namespace: org-acme }
spec:
args:
item: { type: string, required: true }
subscriptions:
- event: core_tool_changed # as events/list names it for the principal
arguments: { tool: x_org-acme_pro_list_items, items: ".items", key: ".id", version: ".status" }
when: '{{ eq .event.data.item.status "Up Next" }}' # optional filter
subject: '{{ .event.data.key }}' # one open run per (workflow, subject)
args: { item: '{{ .event.data.item.url }}' }
steps: [...]eventandargumentsname an event type asevents/listshows it to the namespace's principal: a server's (x_<prefix>_<event>, for a server of the namespace the principal holds aserver:<name>grant for) or one of muster's own (core_schedule,core_tool_changed,core_workflow_run). See MCP events.when,subjectandargsare templates over.event:eventId,name,timestampanddata. Every occurrence starts a run withoutwhen.- An occurrence whose
subjectan open run of the Workflow has is delivered to that run, as adeliveredrun event, and starts none: one open run per subject (an open dry run counts for dry runs only, a live one for live runs). Without a subject, every occurrence starts a run. - A run started by an occurrence is queued with
argsas its input and the subject, acts as the namespace's principal, and gets the occurrence as its firstdeliveredrun event.
A subscription is a row of the run store, shared by everyone who names the
same event type with the same arguments in the same namespace as the same
principal: one per key, however many Workflows and waiting runs use it. The
subscriptions of a dry Workflow subscribe apart
from a live one's; waits and cancelWhen, which only read, share either.
-
Each replica reads the Workflows'
subscriptionsat start, whenever a Workflow changes, and every 30 s, and makes the subscriptions they need. -
A replica claims a due subscription with a row lease, as it claims a due run, and polls it with
events/pollas its principal, through the same path a client's poll takes: muster's own event types and the servers', with the principal's visibility. No push (events/stream) and no webhooks. -
The server paces the polls: its
nextPollMs, kept within [1 s, 10 min], 30 s without one, give or take a tenth. A poll withhasMorepolls again at once. The first poll of a subscription asks for the occurrences since it was made (maxAgeMs), so a server that replays gives the ones between the Workflow's change and the first poll. -
Each occurrence is recorded once per subscription (by
eventId) in the same transaction as the cursor that moves past it, with the runs it starts and the deliveries it makes. A repeated occurrence, or a replica that crashed after the poll, starts nothing twice; a restart goes on from the cursor. -
The subscription's condition says how well it is observed:
observing: its last poll succeeded;unobserved(since, reason): its polls fail -- the principal may not see the event type, the server is down. Polls back off from 5 s, doubling, up to 10 min;gap(since): a poll came backtruncated: the server lost occurrences since the cursor. Polling goes on from where the server resumed, andmuster_workflow_subscription_gaps_totalcounts it.
core_workflow_getshows the subscription of each entry ofsubscriptions: its condition, since when, why, its last success and its next poll. -
A subscription no Workflow uses, and that no open run waits on, is dropped after an hour.
-
Going live. A dry Workflow's
subscriptionsstart dry runs. Removing itsspec.dryRunmakes its entries subscribe afresh, with cursors of their own: a source that fires for what is there already --core_tool_changedwithincludeExisting-- fires again for every item and starts live runs for them, though dry runs of the same subjects may still be open. Those stay dry; the dry subscription, which no Workflow uses any more, is dropped after an hour.
Without Postgres (the memory store), every replica keeps its own subscriptions and polls them: a muster with more than one replica needs Postgres, or each replica starts the runs of every occurrence.
spec:
concurrency:
- { key: '{{ .input.owner }}', max: 2 }
- { key: '{{ .input.repo }}', max: 1 }-
Each key renders from a run's input (with its defaults) when the run is created, whoever starts it: a call, an event, a parent's
workflow:step. A key that renders empty does not limit. A key that does not render (a missing field: use{{ get .input "owner" }}for an optional one) fails the run. -
At most
maxruns of the Workflow (in its namespace) that share a key run at once: a run counts from its admission until it ends, waiting included. -
A run a limit holds is created
queued, with the reason (concurrency alice 2/2) as itsheld, in itswaiting.forand in aheldrun event. No replica claims it. -
When an admitted run ends, the held runs that share one of its keys are admitted, oldest first, each whose limits all have room. An admitted run is due at once.
-
A
workflow_<name>call whose run is held answers at once, like a call whose run waits:{"run_id": "0b5c...", "status": "queued", "waiting": {"for": "concurrency alice 2/2"}}A task-augmented call's task is
working, its status message the reason. -
A failed run retried is admitted again, or held.
-
Dry runs count against the limits as live ones do: admission is muster's own write, which a dry run makes for real.
Postgres serializes the admission of one Workflow's runs with a transaction lock, counts the admitted runs of a key through an index over the runs' keys, and finds held runs by an index of their own: admitting costs the runs that share a key, not every run.
steps:
- id: ci
wait:
event: { name: x_github_check_suite_completed, arguments: { pr: '{{ .input.pr }}' } }
until: '{{ eq .event.data.conclusion "success" }}'
timeout: 72h
cancelWhen:
event: { name: x_github_issue_closed, arguments: { issue: '{{ .input.issue }}' } }
until: 'true'- A wait on an event subscribes to it, as whoever started the run, with
argumentsrendered from the run's state when the wait begins. It is over when an occurrence delivered since it began holdsuntil, which sees it as.event(any occurrence withoutuntil); its result is{satisfied, timedOut, checks, since, event},eventthe occurrence that ended it. It times out as any wait. It has nosteps,everyorsignal. cancelWhenwith aneventsubscribes when the run is created, withargumentsrendered from its input, and checksuntilfor each occurrence delivered since. It has nostepsorevery.- Each occurrence of a subscription is appended as a
deliveredrun event to every open run subscribed to it, and wakes those that wait; a run reads them in order, as it reads its signals. core_workflow_run_getshows a wait on an event aswaiting: {step, for, event, deadline}.
| Metric | Labels | Counts |
|---|---|---|
muster_workflow_subscriptions (gauge) |
condition |
subscriptions, as last counted |
muster_workflow_subscription_occurrences_total |
event |
new occurrences the subscriptions received |
muster_workflow_subscription_gaps_total |
event |
polls that came back truncated |
muster_workflow_runs_started_by_events_total |
workflow |
runs occurrences started |
muster_workflow_run_deliveries_total |
event |
occurrences delivered to open runs |
muster_workflow_runs_held_total |
workflow |
runs a concurrency limit held when they were created |