Merge Checks and the Automated Gate
Follow a registry pull request from its evaluated Git diff through provenance, isolated builds and the check that authorizes a merge.
Eight checks on the same candidate
A candidate identity binds a base commit, head commit, candidate Git tree and policy digest. The provenance policy is a trusted JSON document specifying which source URLs and patch origins can count as evidence. The managed workflow evaluates the base and candidate trees with its own pinned vug and uses its own policy. Merge check contract Managed inspection
| Check | Evidence |
|---|---|
| 1. Format and evaluation | Both trees must yield valid normalized Starlark records. Changes to a shared module also select packages that import it, directly or transitively. |
| 2. Diff scope | decide-merge classifies paths, Git modes and evaluated record changes. It rejects empty diffs, duplicate paths and modes other than 100644 and 100755. |
| 3. Source origins | Each source must match a declared prefix and either the base package’s trusted prefixes or the fixed Nixpkgs mapping for a new package, with maintainer-approved additions. Matching compares parsed host, effective port and path prefix. A candidate-only declaration requires approval, and an undeclared source fails. |
| 4. Source hashes | Fetch approved sources over HTTPS, from public IP addresses, and compare SHA-256. Redirects must stay within trusted or explicitly allowed redirect prefixes. Each source may be up to 512 MiB. The verifier follows up to five redirects and gives each HTTP request 30 seconds to finish, including reading the response body. A blocked redirect or hash mismatch fails. An unavailable download leaves the check incomplete. |
| 5. Patch provenance | Compare the candidate patch bytes with a file from pinned Nixpkgs or an approved upstream raw_root plus commit and path. The upstream repository must cover a trusted source prefix. Downloads use a fixed destination, public HTTPS and an 8 MiB limit. Missing approval for an origin requires review, different bytes from a pinned file fail, and unavailable evidence leaves the check incomplete. |
| 6. Realisation and tests | Materialize the Nix outputs and verify their NAR hashes. Check each ELF program’s application binary interface (ABI) by following its interpreter and library dependencies within the closure and requiring one file per SONAME, the loader’s shared-library name, per process. Enumerate executable entries under bin/ and libexec/ and run each with --version in a Nix sandbox. A timeout, signal or missing loader or library fails the smoke test. Zero entry points yields a reported skip. |
| 7. Build-time reverse dependencies | Select packages that depend on affected packages through dependencies.build, using both trees so deleted edges still count. Build their records against changed candidate overlays. Nested scopes use overrideScope where available so siblings see the changed package. For each applicable overlay record, prove that its exact derivation appears among the dependant’s requisites and matches the derivation built by the overlay’s own check. |
| 8. Independent repeat | A separate runner realises the impacted records again and uses nix build --rebuild for each impacted derivation, including ordinary nix-output records. Both jobs must agree on output paths and NAR hashes, and the repeat must confirm the local rebuild. |
Checks 4 and 5 run after the preceding provenance check passes for that package. The build plan includes impacted packages plus build-time reverse dependencies, up to 12 packages. The managed workflow takes candidate build data as JSON, pins the Nixpkgs revision and archive hash in a trusted policy, and disables import-from-derivation. It ordinarily substitutes plain nix-output outputs from the signed official cache first and builds overlay-dependent records in the Nix sandbox. A revision missing from the trusted policy or an overlay without a fixed HTTPS source can leave isolated checks incomplete. For Check 6, PT_INTERP identifies the loader and DT_NEEDED names its required libraries. Resolution searches DT_RUNPATH or DT_RPATH (which can be inherited), then the loader directory. Even an empty DT_RUNPATH suppresses DT_RPATH. Provenance verifier Build and result processing Overlay evaluation
Request and interpret a report
vug record verify-provenance --root /path/to/repository \
--input file://candidate.json --policy file://policy.json \
--source-cache-dir verified-sources
vug record decide-merge --input file://request.json
Both requests set schema_version: 1 and supply an identity record containing base_sha, head_sha, tree_oid, and policy_digest. Each Git identifier shares one object format (40 or 64 lowercase hexadecimal digits), while policy_digest is the 64-character lowercase SHA-256 of the provenance policy bytes. The caller authenticates the candidate and the trusted policy. The verifier inspects Git objects under --root and can save verified downloads by their SHA-256.
| Field in the provenance policy | Contents |
|---|---|
schema_version | 1 |
nixpkgs_commit | Full 40-character lowercase commit for the policy’s Nixpkgs recipes and patches. |
new_package_sources | Map of package names to URL-prefix arrays derived from pinned recipes. |
approved_sources, redirect_sources | Maps of package names to extra approved source and redirect URL prefixes. |
patch_origins | Map from patch path to a pin. For kind: "nixpkgs", supply path. For kind: "upstream", supply repository, raw_root, commit and path. The maintainer associates the HTTPS raw endpoint with the upstream repository. |
Supply empty maps when there are no entries. The verifier reports SchemaVersion, Results and Findings. Its result rows can feed the decision alongside the other checks. A completed verification report returns exit 0 even if a finding blocks a merge. Invalid input, policy or Git object data returns 254. Provenance schema and result types Command status handling
Add these fields to a decide-merge request:
core_packagesis the list of package names designated by the trusted policy.changescontains one{path, before, after}per changed path. A present side carries a Gitmodeand, for regular records, the normalizedevaluatedvalue fromcheck-tree --evaluated. Usenullfor a missing side and split renames into separate deletion and addition entries.required_checkscontains objects withcheckandtarget. Include Checks 1 and 3–8 for each touched package, plus Check 1 for target.when there is a path outsidepackages/or no recognized package. Include extra targets selected by policy or provenance. Check 2 is computed fromchanges.resultscontains objects withcheck,target,identity,statusand optionaloutput_id. Status ispassed,failedorincomplete. Checks 3 and 5 can also returnrequires_approval.
record_change covers ordinary changes to recognized package paths. approval_change covers package-only changes that need review, for example a deleted version, a changed existing source, an added or changed overlay or patch, a core package, a nonstandard package path or an executable file. A provenance exception can also move a package-only candidate into this class. repository_change takes precedence for changes outside packages/, including shared helpers. Inspect Scope separately to see the diff check’s result even when a provenance exception determines the class. Decision model and output types
Decision | What the evidence supports, in precedence order |
|---|---|
reject | Scope or a check failed, or the supplied evidence was inconsistent, such as a duplicate or unexpected target, invalid check status or mismatched identity. |
incomplete | A required target is absent or its result is missing or unfinished. |
requires_approval | Required checks are complete and the scope or provenance needs review. |
auto_merge | The diff is a record change with all required checks passed. |
The JSON report echoes the identity in top-level fields BaseSha, HeadSha, TreeOid, PolicyDigest, and includes SchemaVersion, ChangeClass, Scope, Decision, AffectedPackages, Reasons and IncompleteChecks. Exit 0 means the command computed the report. Read Decision for the verdict. Malformed requests return 254.
In the walkthrough, a synthetic one-package addition supplies a passed Check 1 and deliberately leaves Checks 3–8 without results. Vug 0.2.29 produced this projection:
$ vug record decide-merge --input file://request.json | jq '{ChangeClass, Scope, Decision, missing: [.IncompleteChecks[].Check]}'
{
"ChangeClass": "record_change",
"Scope": "passed",
"Decision": "incomplete",
"missing": [
3,
4,
5,
6,
7,
8
]
}
From decision to merge
The inspection App publishes evidence. A separate merge App acts only after the Worker verifies the current candidate.
- Intake and dispatch. A GitHub App sends webhooks to a Cloudflare Worker. A Durable Object is a stateful Cloudflare component with persistent storage. The gate uses one SQLite-backed object to reserve queue slots and persist executions. Defaults allow one running and one waiting PR per author and one running PR globally. A changed head or base cancels the obsolete run before its slot is reused.
- Management identity. The Worker assigns an execution UUID and dispatches against
MANAGEMENT_REF, a mutable ref. It expects the resulting run at the deployedMANAGEMENT_SHA. A redeploy can trigger inspection again even if the policy digest stayed the same. An unconfirmed dispatch expires after 15 minutes, releases capacity and can be requeued with a new UUID. Late callbacks for the expired UUID are refused. - Authenticated callback. OIDC (OpenID Connect) supplies a short-lived GitHub Actions identity token to the callback job. The Worker checks issuer, audience, repository ID, workflow and commit, dispatch event, hosted runner, run ID and first attempt, then validates the result against the active execution and reads GitHub again before publishing a successful
vug/merge-policycheck on the inspected head. Anauto_mergedecision earns success directly. For an enabled merge target, an eligible review can also give arequires_approvalcandidate a successful check. - Verify and merge.
refs/pull/<n>/mergeis GitHub’s synthetic test merge ref for PR numbern. The Worker verifies that its parents are the inspected base and head and that its tree matches. It publishesvug/verified-merge-treefrom the inspection App on the head SHA and calls the squash-merge API using that SHA as the expected head. Strict branch protection requires the head to stay up to date with the base before merging. Pair it with the required verified-tree check from the inspection App so a base advance blocks a stale success. The separateapp/vug-mergeinstallation can merge only the repository and branch authorized byMERGE_INSTALLATION. Forrequires_approval, it needs anAPPROVEDreview of the current head from a non-author administrator, or a non-author inAPPROVER_USER_IDSwith write, maintain or admin permission. - Halt and recover. Before the API call the queue persists the attempt. It verifies that the squash commit has the inspected base as its sole parent and the inspected tree. After an ambiguous response it reads GitHub to identify the resulting commit, using the merged issue event if the PR has no merge commit SHA. A mismatch, an unidentifiable merge commit for a merged PR, or five failed reads sets
merge_halted, a durable flag that immediately blocks further merge calls. Check revocation happens asynchronously for runs the queue still tracks. After investigating, clear themerge_haltedrow from the Durable Object’sstatetable to resume.
Before a merge call, the Worker rechecks success of both App checks, the current candidate identity and the test merge tree. Gate architecture and deployment Queue and merge state Callback workflow GitHub merge verification
Smoke and acceptance trials
From the management repository, supply a known merged package commit and its parent. This manual smoke run prints a decision in Actions and skips the callback.
gh workflow run merge-policy.yml \
-f candidate='{"repo":"OWNER/REPO","base_sha":"PARENT_SHA","head_sha":"COMMIT_SHA"}'
Use an isolated sandbox repository to exercise webhook delivery and merge protections. Submit a clean version addition, then a candidate that also changes its own workflow, and verify that only the managed job can earn the inspection check. Change a PR head or move the base during a run and verify replacement of the old execution. Test queue limits with multiple PRs from one author and another author, including webhook redelivery. With merge enabled on the sandbox, compare the resulting parent and tree with the inspected identity, and test that a base advance blocks merging from an old head check. Smoke and sandbox instructions