ADR 0017 — CI results by webhook: GitHub and a generic signed shape ​
- Status: accepted (2026-09-30). Built (2026-09-30): MVP slice 6 (the generic route,
SurfaceRoutes::machine, the CI source in the gate), slice 7 (the AG-UI card), slice 8 (the web's card, 2026-09-30) and slice 9 (the GitHub adapter); see Built (slice 6), Built (slice 7) and Built (slice 9). The web draws the card asweb/README.mdsays (mvp.md). Uses the inbox of ADR 0016; feeds the gate of ADR 0018. The wire contract isapi/webhooks.md. Amended 2026-09-30 (review of slices 6, 7 and 9): "the first completed report decides" is gone,check_suiteis not accepted, the idempotency keys come from the signed content and not from delivery ids, the AG-UI card id is unique per report, and a few limits were added. The text of the Decision and of the Built sections below is kept as it was written; the status note says what replaced what.
Context ​
MVP step 2 ends a job as "a pushed branch plus a CI result card". The agent pushes the branch (adam-coder emits a branch artifact); the CI result is somebody else's fact and reaches the orchestrator from outside. The owner decided on 2026-09-30 to accept both a GitHub adapter (HMAC on the raw body) and a generic signed shape, so that a CI that is not GitHub Actions can report without pretending to be GitHub.
ADR 0002 says quality is decided by an external judge and that a job is never "done" while its checks are red. CI is that judge; this ADR is how its verdict arrives.
Decision ​
A new crate, orch-surface-webhook, implements two inbound surfaces. ORCH_SURFACES gains two names, and the binary gains the Cargo feature surface-webhook, on by default:
| Surface name | Route | Authenticates with |
|---|---|---|
webhook-github | POST /webhooks/github | X-Hub-Signature-256, HMAC-SHA-256 of the raw body |
webhook-generic | POST /webhooks/ci | X-Vymalo-Signature-256, HMAC-SHA-256 of "<ts>.<body>" |
Both are machine routes (ADR 0016, decision 5): mounted outside the identity layer, never reading X-Auth-Request-Email. Each does the same three things, in this order: check the HMAC on the raw body before any write; normalise the payload to a CiReport; hand it to App::receive, which stores an inbox row and answers 202.
GitHub ​
X-Hub-Signature-256is checked on the raw body. Missing or bad: 401, and nothing is stored.pinganswers 204.check_suite,check_runandworkflow_runwithaction = completedbecome aCiReport { provider, repo_key, sha, branch, name, conclusion, url, summary }, whererepo_keycomes fromrepository.html_url,shafromhead_sha,branchfromhead_branch, andnamefromapp.slug(suite), the check name (run) or the workflow name (workflow run).- Any other event answers 202 and is not stored.
- Idempotency key:
github:<X-GitHub-Delivery>.
Generic ​
- Headers:
X-Vymalo-Delivery(a UUID, the idempotency key);X-Vymalo-Timestamp(Unix seconds, within plus or minusWEBHOOK_GENERIC_MAX_SKEW_SECS);X-Vymalo-Signature-256(sha256=+ hexHMAC(secret, "<ts>.<body>")). - Body:
{version: 1, repository: <url>, sha: <40 hex>, branch?, name, conclusion, url?, summary?}. - The signed timestamp bounds replay; the delivery id makes a replay inside the window harmless.
- The full contract, with a worked signature, is
api/webhooks.md.
Common rules ​
- Conclusions are a closed enum (ADR 0004).
success,neutralandskippedpass; everything else fails. - Which reports count. When
CiPolicy.required(a list of check names, from the target'sgate.ci.required) is set, only reports with those names count and all of them must pass. Otherwise the first completed report decides. Every report gets a card in the chat, counted or not. - Matching is by watch, not by branch. A report is applied to the thread that holds
Watch { ci:<repo-key>@<sha> }, set when the agent'sbranchartifact was applied. A report for an unknown key is parked, and applied when the watch appears. - Timeout. After
ORCH_CI_TIMEOUT_SECSwith the required reports missing, the thread goes toBlockedwith interrupt reasonci_timeout. It does not spend an attempt; the user can answer, or cancel. - Secrets.
WEBHOOK_GITHUB_SECRETSandWEBHOOK_GENERIC_SECRETSeach hold at most two comma-separated secrets, so a secret can be rotated without a gap: a signature is good if either matches. A secret variable is required when its surface is mounted; otherwise the process exits 78 (ConfigError), as for anORCH_SURFACESname without its feature. - Body limits. 5 MiB for GitHub, 256 KiB for generic; over the limit answers 413.
Configuration ​
| Variable | Default | Meaning |
|---|---|---|
ORCH_SURFACES | agui | add webhook-github and/or webhook-generic to mount them |
WEBHOOK_GITHUB_SECRETS | none | one or two comma-separated secrets; required with webhook-github |
WEBHOOK_GENERIC_SECRETS | none | one or two comma-separated secrets; required with webhook-generic |
WEBHOOK_GENERIC_MAX_SKEW_SECS | 300 | accepted difference between X-Vymalo-Timestamp and the clock |
ORCH_CI_TIMEOUT_SECS | 3600 | how long a job waits for CI before Blocked (ci_timeout); a target's gate.ci.timeoutSecs overrides it |
INBOX_PARKED_TTL_SECS | 86400 | how long an unmatched report waits (ADR 0016) |
One deployment-wide secret per surface, with rotation, is the default chosen; per-repository secrets are not part of this decision.
Diagrams ​
The path of a report, including one that beats its watch (parked, then re-armed):
sequenceDiagram
participant CI as CI system
participant E as Edge (Caddy, oauth2-proxy)
participant S as orch-surface-webhook
participant DB as Postgres
participant W as InboxWorker
participant A as App and transition (pure)
CI->>E: POST /webhooks/ci or /webhooks/github
E->>S: passes /webhooks/*, strips X-Auth-Request-Email
S->>S: HMAC over the raw body, before any write
alt bad or missing signature
S-->>CI: 401, nothing stored
else valid
S->>S: normalise to CiReport
S->>DB: App::receive: INSERT inbox (source, idempotency_key), 202 also for a duplicate
S-->>CI: 202
end
W->>DB: claim row (SKIP LOCKED), resolve correlation through watches
alt a watch matches
W->>A: apply(thread, CiReported, key inbox:id)
A->>DB: ONE txn: state + job (CAS), ci_result and check_result events, row applied
else no watch yet
W->>DB: park the row
Note over A,DB: later, the agent's branch artifact commits Watch{key}
A->>DB: same txn as that commit: INSERT watches, re-arm parked rows with the key (pending)
W->>DB: claim the re-armed row, apply as above
endThe state of one inbox row:
stateDiagram-v2
[*] --> Pending: App receive stores the row
Pending --> Inflight: claimed (SKIP LOCKED), lease
Inflight --> Inflight: lease expired, another replica re-claims
Inflight --> Applied: watch found, Input applied in the thread's commit
Inflight --> Parked: no watch for the correlation key
Parked --> Pending: a commit carrying Watch{key} re-arms it, same transaction
Parked --> Expired: INBOX_PARKED_TTL_SECS elapsed
Inflight --> Pending: transient error, backoff
Inflight --> Dead: permanent error, attempts exhausted
Applied --> [*]
Expired --> [*]
Dead --> [*]Built (slice 6) ​
2026-09-30. The generic route, SurfaceRoutes::machine, the CI source of the gate and ORCH_CI_TIMEOUT_SECS are built and checked against the code (orchestrator/crates/surface-webhook, api, app, core; the binary). The GitHub route is slice 9 (below). Where the build differs from, or fixes, the text above:
- The guard is the signature check.
SurfaceRoutes::machine(routes, guard)mounts routes outside the identity layer and outside the request timeout, and takes the guard as a required argument, so a machine route cannot be added without one. The webhook's guard is a middleware that reads the body up to the route's limit, checks the headers, the timestamp and the HMAC, and only then hands the handler the verified bytes in a request extension; a handler that finds none refuses. The order is: the three headers (401), the timestamp is plain digits and within the skew (401), the body within 256 KiB (413), the HMAC (401). Nothing is written before the HMAC is good, and the handler cannot be reached without it. - The clock is the application's. The skew is judged against
App's injected clock, so a test that holds the clock sees the same window the route does. - Delivery ids are UUIDs.
X-Vymalo-Deliverymust parse as a UUID (else 400, after the signature). It is stored in its hyphenated lower-case form, so the two spellings of one UUID are one delivery. The inboxsourceisgeneric. - The timestamp is
[0-9]{1,12}. A sign, a blank or a fraction is a 401. This keeps the signed string"<ts>.<body>"unambiguous (a timestamp with a full stop could trade bytes with the body). - The conclusions of the generic body are the eight of
api/webhooks.md. The core's enum also hasstartup_failure(GitHub'sworkflow_runcan say it); slice 9 maps it, the generic body refuses it with a 400. - Only
httpandhttpslinks are kept, and a summary is cut to 16 KiB at a character boundary. ORCH_CI_TIMEOUT_SECSis read (default 3600, at least 1) as the deployment'sci.timeout; anAGENTS_FILEentry'sgate.ci.timeoutSecsoverrides it for that agent. A gate that requiresciwhile no webhook surface is mounted on a control plane logs a warning at startup; its jobs endBlocked(ci_timeout), neverDone.- Secrets are required by the role that serves the route.
WEBHOOK_GENERIC_SECRETSunset whileORCH_SURFACESnameswebhook-genericis exit 78 forallandcontrol-plane; aworkerserves no routes and does not need it (a value that is set is validated in every role). More than two secrets is exit 78 too. The variable is redacted in--helpand inDebug, and the value is never in a message or a log. pingand the GitHub events are slice 9, below.- The gate honours
ci.pending_reason(Ci)isNone; theciandci:settings are accepted in a deployment or anAGENTS_FILEentry (never per thread);verifieris still refused until slice 10 (ADR 0018). - The core needed no change.
ci_resultcards, the CI source and the CI deadline toBlocked(no attempt spent) were built in slices 2 and 5; the slice's end-to-end tests (orch-e2ewebhook.rs, both stores, a clock the test holds) drive them through the real route: a report that beats its watch is parked, matched and the job done; a red report reworks with the report in the findings, and a report about the old commit changes nothing; with no report the deadline blocks the thread; a refused delivery changes nothing. - Reproducing the vectors. The known-answer vectors are in
api/webhooks.mdand in the unit tests ofsignature.rs.
Built (slice 7) ​
2026-09-30. Every ci_result event is the AG-UI activity vymalo.ci (orch-agui-projection, api/agui.md); the TODO of slice 3 is gone.
- The id is
ci-<sha>-<name>, not per attempt. The text above leaves the id to the slice. A report is about a commit and a check, so its id depends on those and on nothing the projector has folded: the same log gives the same ids to every viewer and replay, a check that runs again on the same commit replaces its card (replace: true), and a report about the old commit (which the gate ignores) is a card of its own. (Superseded on 2026-09-30, see the status note: the id is nowci-<provider>-<sha>-<name>-<seq>and nothing is replaced.) A per-attempt id would have tied the card to the fold state, and a late report about attempt 1's commit would have landed on attempt 2's card. - The content is the report plus what a renderer would otherwise have to compute:
passed(from the closed conclusion enum),shortSha.name,branchandsummaryare untrusted text;urlis passed on only when it ishttp(s)(checked again in the projection: the log is data). - Golden
ci(ci.events.json,ci.agui.json,run-ci,connect-ci, and the reference client's expectations): the fake agent'sverify-ci, a redci/buildfor the first commit, a green one for the second. The web's mock replays it (verify-ci), and the web renders the card (slice 8).
Built (slice 9) ​
2026-09-30. POST /webhooks/github (ORCH_SURFACES name webhook-github, secret WEBHOOK_GITHUB_SECRETS, same feature surface-webhook) is built; contract in api/webhooks.md.
pinganswers 204, as this ADR says. (The slice's brief said 200; the ADR and the contract page say 204, the ADR wins, and GitHub accepts any 2xx.)pingis not parsed.- Order and codes. The guard checks the signature header (401), the size (413, 5 MiB) and the HMAC (401) before anything else; the handler then needs
X-GitHub-Event(400 without) and answers:ping204; the three events withaction=completedare stored undergithub:<X-GitHub-Delivery>and 202 (a delivery id is required for those, 400 without); every other event or action is 202 and not stored, and not parsed, so GitHub neither retries nor flags them. - What
summary,urlandnameare per event is fixed (table inapi/webhooks.md): a check suite has a name (app.slug) but neither link nor summary; a check run has itshtml_urlandoutput.summary; a workflow run has itshtml_urland a name that may benull(thenworkflow).startup_failureis kept as a conclusion of its own (it fails); anything else outside the closed list, andnull, isfailure. - The fixtures are synthetic, not recorded. No real delivery was available, so the payloads in
crates/surface-webhook/testdata/githubwere written by hand after the documented schemas and say so (their README). What the docs do say was read on 2026-09-30 and is marked in the Verified section below; what they do not (the members ofcheck_suiteandcheck_runpayloads) stays unverified until a real delivery replaces a fixture. - Dev stack.
mock-ci(dev/mock-ci, alpine with git, curl and openssl, pinned by tag and digest) pollsgit ls-remoteongit-serverforagent/*and posts a signedcheck_suitethrough the edge (success, orfailurewhen the commit message containsCI_FAIL;MOCK_CI_SHAPE=genericfor the generic body); its delivery ids are derived from repository and commit, so a restart sends repeats, not new reports. The coder is gated on CI (gate: {require: [ci]}), anddev/coder-e2e.shasserts the job's gate and thevymalo.cicard. Not run here: it needs Docker; theCoder E2Eworkflow is its first run.
Status note (2026-09-30): review fixes ​
A review of the three slices found that a red commit could pass, that a captured delivery could be replayed, and a few smaller faults. What changed, and which sentence above it replaces:
- A gate that requires
cinames its checks. Replaces "Otherwise the first completed report decides" (Common rules) and the "first report decides" path of the core. With no names, the first report for a commit decided, so askippedreport of another check, another workflow's, or a fork's, could pass a red commit. Nowci.requiredmust name at least one check wherever the resolved policy requiresci: the deployment (ORCH_CI_REQUIRED) and everyAGENTS_FILEentry are refused at startup (exit 78), a per-thread request that addscion a policy with none is a 400 or a tool error, and the core, should such a gate get through, lets nothing pass (the CI deadline blocks the job). Only a named check decides; every other report is a card. (ADR 0018.) ciis honoured only where a report can arrive. A process that serves routes and mounts neitherwebhook-genericnorwebhook-githubrefusesciin every layer, per-thread requests included, with "no CI webhook surface is mounted (ORCH_SURFACES)". This replaces the startup warning of slice 6. Aworkerserves no routes and cannot tell.check_suiteis dropped from the GitHub adapter. A suite is named by its app (github-actions), so every check of that app would have the same name and none could be required by name.check_run(named by the check) andworkflow_run(named by the workflow; anullor blank name is ignored: 202, not stored) remain. Replaces the GitHub list of the Decision and the "three events" of Built (slice 9).- A fork's run does not count. A
workflow_runwhosehead_repositoryis not the repository (or is missing), and acheck_runwith a pull request whose head repository is not the repository, is acknowledged (202) and not stored. The fork chooses its own workflow names; its commit is not one the agent pushed. - Idempotency comes from what is signed.
X-GitHub-DeliveryandX-Vymalo-Deliveryare not signed, so a captured request could be replayed under a new id and stored again. Replaces "Idempotency key:github:<X-GitHub-Delivery>" and "X-Vymalo-Delivery(a UUID, the idempotency key)". GitHub:check_run:<id>:<completed_at>andworkflow_run:<id>:<run_attempt>. Generic: the SHA-256 of the signed string"<ts>.<body>", so the same timestamp and body are one delivery. The delivery-id headers are optional and only logged. An event whose signedcompleted_at(updated_atfor a workflow run) is older thanWEBHOOK_GITHUB_MAX_AGE_SECS(default 86400) is acknowledged and not stored, so a captured GitHub delivery is not replayable for ever (the generic route already had its skew window). X-GitHub-Eventis not signed. It only selects which parser reads the signed body, and the body must be what that parser demands (acheck_runheader over aworkflow_runbody is a 400). It cannot make a body mean something else.- Reading is bounded. The body buffer is not sized from
Content-Length(a declared 5 MiB with no bytes held 5 MiB per connection); it grows with what arrives, up to the limit. Each webhook route gives up on a request after 10 seconds (408), inside the route's guard and not onSurfaceRoutes::machineas a whole (an MCP wait is long). The refusal log is onewarnper route per 30 seconds, with the count of the ones held back, anddebugfor the rest. - The AG-UI card id is unique per report (see the note under Built (slice 7)).
- Secrets are at least 32 bytes, trimmed, and a blank one is nothing.
X-GitHub-Event,X-Vymalo-DeliveryandX-GitHub-Deliveryare never trusted for a decision. - Both sides of a match log the same key. When a job's push starts a CI watch, and when a report is received, the watch key (
ci:<repository key>@<sha>) is logged at info with the repository key and the short sha, so a mismatch of spelling shows by eye.
Still open: what a real GitHub delivery carries (all fixtures are synthetic; every member read is unverified as listed in the Verified section), and per-repository secrets.
Security notes ​
- Verify before any write. The HMAC is over the raw bytes as received, not a re-serialised body. A missing or wrong signature is 401 and touches no table.
- Constant-time comparison through the HMAC library's verify function; never
==on hex. - Replay. The generic shape signs a timestamp, rejects one outside the skew window, and is one delivery by its timestamp and body; GitHub's key comes from the signed body and an event older than the maximum age is not stored. A delivery-id header is never a key: it is not signed (status note above).
- Untrusted text.
summaryandnamecome from the outside. They are shown in a card, and they flow into a rework prompt only as quoted, untrusted data (ADR 0018). A report can fail a check or pass it; it cannot start a job, approve a review or merge. - Edge. The edge must route
/webhooks/*to the orchestrator without an identity header: the compose stand-in usesheader_up -X-Auth-Request-Email. Production routing (oauth2-proxyskip_auth_routes) is unverified and checked in slice 6. - The GitHub relay. For a local stack, an opt-in relay (smee.io) is a third party that sees the payloads; it is off unless configured and is told to the owner (slice 13).
- Secrets are
SecretString, redacted inDebug, absent from logs.
Consequences ​
Easier
- Any CI can report with a small signed POST; GitHub Actions needs only a webhook.
- A duplicate delivery, an early report and a slow worker are all harmless.
- The chat shows every report as a card, whether or not it decides the gate.
Harder
- A report cannot be matched without the agent's
branchartifact: a coder that pushes without emitting one leaves reports parked until they expire. The watch key is the commit, not the branch. - The orchestrator must be reachable from the CI system (a public route, or a relay). The webhook is inbound.
- Two secret variables and two body schemas to keep in step with
api/webhooks.md. - GitHub webhook payloads are assumed to match the REST schemas' field names. Slice 9 meant to settle it with recorded deliveries and could not (none was available): its fixtures are synthetic, and the question is still open (status note of 2026-09-30, Built (slice 9)).
Alternatives considered ​
- Polling the checks API. Rejected: it needs an outbound GitHub credential per repository and a poll loop with backoff, ties the orchestrator to one provider, and is slower than a push.
- Matching a report to a thread by branch name. Rejected: branches are reused and force-pushed; a report for an older commit of the same branch would be applied to a newer attempt. The commit SHA is the identity; a stale SHA is recorded and changes nothing.
- Applying the report synchronously in the request. Rejected: GitHub's 10 s deadline, CAS conflicts, and no place for a report that arrives before its watch. See ADR 0016.
- Only a GitHub adapter, or only the generic shape. Rejected by the owner's choice of both: GitHub is the common case and its signature is fixed; the generic shape covers everything else with a body we control.
- One secret per repository. Not chosen; a deployment-wide secret with rotation is the default. Revisit if a deployment serves mutually distrusting repositories.
Hard to reverse ​
- The route paths and the header names (
/webhooks/github,/webhooks/ci,X-Vymalo-*): CI configurations elsewhere will hold them. - The generic body schema,
version: 1, and the signed string"<ts>.<body>". A change is aversion: 2with its own route or negotiation, never an edit. - The idempotency key formats (
github:<delivery>, the generic delivery UUID). - The conclusion enum.
Easy to reverse: limits, the skew window, the timeout and the TTL.
Verified ​
- Verified 2026-09-30:
X-Hub-Signature-256issha256=plus the hex HMAC-SHA-256 of the raw payload, compared in constant time. Source: https://docs.github.com/en/webhooks/using-webhooks/validating-webhook-deliveries. - Verified 2026-09-30: the headers
X-GitHub-EventandX-GitHub-Delivery, the 25 MB payload cap and the event actions. Source: https://docs.github.com/en/webhooks/webhook-events-and-payloads. (The 25 MB cap is why the GitHub body limit here, 5 MiB, is a choice, not GitHub's.) - Verified 2026-09-30: the check run
conclusionvalues aresuccess,failure,neutral,cancelled,skipped,timed_out,action_required,stale(and null while running). Source: https://docs.github.com/en/rest/checks/runs. - Verified 2026-09-30 in the REST schemas (check suites, workflow runs):
head_sha,head_branch,conclusion,repository.html_url. That the webhook payloads are identical to the REST ones is unverified, and still is after slice 9, whose fixtures are synthetic (status note of 2026-09-30). Whetherworkflow_runcan carry a conclusion outside the list above (for examplestartup_failure) is unverified;startup_failureis mapped to its own failing conclusion, any other such value fails closed asfailure. - Verified 2026-09-30 (adam-rs
882e239):adam-coderemitsbranch {repository, branch, base_branch, commit}andpull_request {…}artifacts, so the watch key can be built from it. - Verified 2026-09-30 (slice 9): GitHub's documented signature vector (secret
It's a Secret to Everybody, payloadHello, World!,sha256=757107ea0eb2509fc211221cce984b8a37570b6d7586c22c46f4379c8b043e17), the REST fields of a workflow run (html_url,head_sha,head_branchandnamenullable,conclusionnullable, no list of values, nostartup_failure), and thepingpayload (zen,hook_id,hook). Sources: the pages named inapi/webhooks.md. Still unverified: the members of thecheck_suiteandcheck_runwebhook payloads beyond the REST schemas, and that GitHub sendsstartup_failure. The slice's fixtures are synthetic, not recorded deliveries. - Verified 2026-09-30 (slice 6), reading the source:
verify_sliceofdigest'sMacchecks the length and then compares withsubtle'sct_eq. It is constant-time in the tag; the length of a tag is public. (Re-read for the versions the crate now uses,hmac0.12.1 overdigest0.10.7,digest-0.10.7/src/mac.rs,verify_slice; the crate uses those, the versions the MCP tokens'sha20.10 shares, and no longerhmac0.13.) - Verified 2026-09-30: oauth2-proxy has the option
--skip-auth-route/skip_auth_routes("bypass authentication for requests that match the method & path. Format: method=path_regex OR method!=path_regex. For all methods: path_regex OR !=path_regex"). https://oauth2-proxy.github.io/oauth2-proxy/configuration/overview. Unverified: that oauth2-proxy strips a client-suppliedX-Auth-Request-Emailon a skipped route. It does not matter to the webhooks, which never read it, and the compose edge deletes it (header_up -X-Auth-Request-Email).