Skip to main content

Workflow event ingestion — GitHub and Alertmanager → agents+gates runs

Issue: core#4429 (tracker core#4419, plan workstream E). Code: internal/workflow/eventingest.

An agents+gates workflow whose definition declares an event trigger starts a run when its provider delivers a matching event. This runbook covers turning the route on, creating an endpoint, and configuring the provider.

What is live, and what is not​

PieceState
WorkflowEventService (create / list / revoke endpoints)Mounted on context-engine wherever it runs. Clearance 4.
Public route POST /webhooks/workflow-events/{org_id}/{endpoint_id}Mounted only when WORKFLOW_EVENT_INGESTION_ENABLED=true and VAULT_PASSPHRASE is set. The boot log says which: workflow event ingestion route mounted or ... NOT mounted with the reason.
Edge routing (Envoy) to that pathNot configured by #4429. No Envoy config in this repo routes /webhooks/workflow-events/ yet. Exposing it is a separate edge change and a go-live decision.
Runs actually startingThrough WorkflowService.TriggerWorkflow, with idempotency_key and trigger_key = event:<provider>.<kind>. TriggerWorkflow reads the typed idempotency_key (the idempotency-key header is the fallback) and the run store enforces (workflow_id, idempotency_key), so a delivery replayed after the receipt ledger's 7 days returns the FIRST run, not a second one. It refuses a trigger_key the definition does not declare (InvalidArgument, settled by the adapter) and records it on the run (workflow_runs.trigger_key). Turning WORKFLOW_EVENT_INGESTION_ENABLED on in any deployment is a go-live decision tracked on #4471.

1. Create an endpoint​

Call upsquad.workflow.v1.WorkflowEventService/CreateEventEndpoint as a clearance-4 member, with provider set to github or alertmanager. The response carries endpoint.path and secret. The secret is returned once. It is stored only in the vault, under provider_keys provider workflow_event_secret_<endpoint id>. An organization can hold at most 25 active endpoints.

2. Configure the provider​

GitHub (repository or organization webhook):

  • Payload URL: the public origin followed by endpoint.path.
  • Content type: application/json. A form-encoded delivery is refused as malformed_body.
  • Secret: the secret. GitHub signs each delivery with it (X-Hub-Signature-256).
  • Events: the ones your triggers name. ping and any event outside the catalogue are accepted and recorded, and they start nothing.

Alertmanager (webhook_configs). Alertmanager cannot sign a body, so the secret is sent as a bearer credential:

receivers:
- name: upsquad-triage
webhook_configs:
- url: https://<public origin>/webhooks/workflow-events/<org_id>/<endpoint_id>
http_config:
authorization:
type: Bearer
credentials: <secret>

3. Declare the trigger on the workflow​

The provider, the kinds and the payload fields a trigger may name come from a closed catalogue: internal/workflow/agentsgates/eventcatalog.go. The validator refuses anything outside it. It also requires every required input to be mapped, and each mapped field's type to equal its input's type. Example:

{"event": {"provider": "github", "kind": "pull_request.opened",
"filters": [{"field": "repository.full_name", "any_of": ["acme/widgets"]}],
"inputs": [{"input": "repo", "field": "repository.full_name"},
{"input": "pr_number", "field": "pull_request.number"}]}}

An event-started run's requester is the workflow's owner (workflows.created_by). If the owner is not an active member of the same organization, the workflow is refused for that event (owner_unresolved) and no run starts.

Mapped inputs are untrusted data. Anyone who can open a pull request or an issue on a subscribed repository chooses pull_request.title, pull_request.body, issue.body, label.name (and an Alertmanager sender chooses its annotations). The run executes as the owner at the owner's clearance. Each value is bounded only by the 2 MiB body cap; treating them as data with no instruction authority, and bounding string inputs, is tracked on #4419. On a public repository, add a sender.login (or pull_request.user.login) any_of filter naming the people whose events may start runs:

"filters": [{"field": "sender.login", "any_of": ["alice", "bob"]}]

4. Read what happened​

Each delivery whose endpoint lookup succeeds writes exactly one agent_audit_log row, including the platform's own failures after that point:

  • workflow_event_accepted: the detail lists every candidate workflow with its outcome: started (with run_id), filtered, refused (with a reason), or failed (transient; the provider was answered 503).
  • workflow_event_rejected: the detail carries the reason, one of signature_missing, signature_invalid, endpoint_revoked, secret_unavailable, body_too_large, unreadable_body, malformed_body, delivery_id_invalid, event_invalid, replayed, in_flight (another delivery of the same id is being processed; answered 503 with Retry-After) or platform_unavailable (the vault, the receipt ledger or the subscription read failed; answered 503).

Some requests write no row: an unknown endpoint id (there is no tenant to attribute it to), a failed endpoint lookup, a non-POST request, and a rate-limited request (20/s per endpoint, 50/s per org, 500/s per process). These are logged only, at most one line per org per minute for the rate-limited and unknown-endpoint cases (the next line reports how many were suppressed).

Replay protection: a delivery id (GitHub X-GitHub-Delivery; for Alertmanager, a digest of the group key, the status and each alert's fingerprint, status and start time) is remembered for 7 days in workflow_event_receipts. Within that window a redelivery is answered 200 {"status":"duplicate"} and starts nothing. A delivery claims its receipt with a lease (60 s) committed before any run starts, so a concurrent duplicate is answered 503 in_flight at once rather than waiting. A redelivery of a delivery that was answered 503 retries only the workflows that had not settled. Every delivery is bounded by a 30 s deadline. Run starts are admitted at most MaxConns/4 at a time (at least one) per process, shared across organizations: with a pool of fewer than 8 connections that is a single slot, so one organization's slow starts delay every organization's. Per-organization fairness is a recorded follow-up.

5. Revoke​

RevokeEventEndpoint marks the row revoked and deletes the vault secret. Every later delivery is refused with endpoint_revoked. If the secret deletion fails, the RPC returns Unavailable; call it again.