← Docs

CI

Check every pull request against the guarantees on its base branch with GitHub Actions, and post the certificate on the pull request.

CI is where verdicts count. The agent's checks while it works are there to help it fix the code. The verdict that decides a merge comes from CI, which checks the pull request's (PR's) head code against the guarantees and checks on the base branch, and posts a certificate on the PR like any other status check.

Why the base branch

A PR can change code and guarantees at the same time. If CI read the guarantees from the PR, an agent could pass by weakening the sentence it was asked to keep. So it does not:

  • Guarantees and checks are read at the base commit (main, or whatever the PR targets).
  • Code is the PR's head commit.
  • Guarantee changes in the PR are described on the certificate in plain words and need a code owner's approval, but they do not apply to this PR's verdict. They apply to the next PR, once merged.
  • Check changes in the PR are listed for review and decide nothing for this PR either.

Set it up

Two workflows, as InputLayer's CI guide has them. The first checks the pull request. The second, which runs after it from your default branch and none of the pull request's code, checks the code owners' approval and posts the certificate on the pull request.

The Install il steps are placeholders: il's public install is not available yet, so the workflows do not run as shown until those steps install il.

Add .github/workflows/inputlayer.yml:

yaml
name: InputLayer check

on:
  pull_request:
  # A new review runs it again, and so the code owners' check after it (below).
  pull_request_review:
    types: [submitted, dismissed]
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  guarantees:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          # A pull request's own head commit, not GitHub's merge of it: the certificate is of the
          # commit the pull request shows, and its comment is posted only for that commit.
          ref: ${{ github.event.pull_request.head.sha || github.sha }}
          # The history, so il ci can compare each model with the code it watches.
          fetch-depth: 0
          # No token left in .git/config: il ci runs the pull request's code, and needs none.
          persist-credentials: false

      # A placeholder: il's public install is not available yet (see the note below).
      - name: Install il
        run: |
          # install il (public install not yet available)

      # Your tests' own setup, as your other CI has it (here: Python and pytest). With
      # --certificate, il ci replays a break as a test on your code: without what your tests
      # need, the test cannot run, and no break is ever reproduced.
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: python -m pip install pytest

      - name: Check the guarantees
        run: |
          case "$GITHUB_EVENT_NAME" in
            pull_request*)
              # Also the pull request's certificate, for the comment the code owners' workflow
              # posts, with the summary this step wrote (each step has its own summary file).
              mkdir -p "$RUNNER_TEMP/inputlayer"
              set +e
              il ci --github --certificate "$RUNNER_TEMP/inputlayer/certificate.json"
              code=$?
              cp "$GITHUB_STEP_SUMMARY" "$RUNNER_TEMP/inputlayer/summary.md"
              exit "$code" ;;
            *) il ci --github ;;
          esac

      # The certificate, the comment's file beside it (both for the comment, below) and the check's
      # summary, kept when the check fails.
      - if: always() && startsWith(github.event_name, 'pull_request')
        uses: actions/upload-artifact@v4
        with:
          name: inputlayer-certificate
          path: ${{ runner.temp }}/inputlayer/
          if-no-files-found: ignore
  • The check: il ci --github checks each guarantee cold, on one private engine for the whole run (or the engine --server names). It prints one line per guarantee, with the finding under it, adds an annotation on the model file for each finding, and a table in the job's summary.
  • The certificate: in a pull request's job, il ci also replays each break on the code, tells whether this change brought it, and writes the pull request's certificate. The last step keeps it, with the check's summary, as the artifact inputlayer-certificate.
  • Your tests' own setup: with --certificate, il ci replays a break as a test on your code, so the job needs what your tests need.
  • fetch-depth: 0: without the history, il ci cannot tell whether a model is older than the code it watches.
  • persist-credentials: false: il ci runs the pull request's code and needs no token, so none is left in .git/config.

Add .github/workflows/inputlayer-code-owners.yml:

yaml
name: InputLayer code owners

on:
  workflow_run:
    workflows: [InputLayer check]
    types: [completed]
  # A person's override of the pull request's breaks: a comment whose first line is
  # "/inputlayer override <reason>". Any new, edited or deleted one reads every comment again.
  issue_comment:
    types: [created, edited, deleted]

permissions:
  contents: read
  # Writes the comment with the pull request's certificate.
  pull-requests: write
  statuses: write
  # Posts the check run "InputLayer guarantees", the one to require.
  checks: write
  # Reads the pull request's comments, for an override.
  issues: read
  # Reads the certificate the run above kept.
  actions: read

jobs:
  code-owners:
    # The check above finished, or a comment on a pull request that is, or was before an edit, an
    # override. The comment's text is only tested here; il reads it again from the API.
    # A workflow_run is matched by the workflow's name, which a pull request's own new workflow can
    # also have: only a run of the check's file counts (keep it named inputlayer.yml, or change it
    # here too).
    if: >-
      (github.event_name == 'workflow_run' &&
       github.event.workflow_run.path == '.github/workflows/inputlayer.yml') ||
      (github.event.issue.pull_request &&
       (startsWith(github.event.comment.body, '/inputlayer override ') ||
        startsWith(github.event.changes.body.from, '/inputlayer override ')))
    runs-on: ubuntu-latest
    # One run at a time per pull request, the newest waiting. A pull request from a fork names no
    # pull request in its check's run, so that run keys on the head commit while a comment keys on
    # the number, and the two can run at once: the newest reading wins, not the last to finish.
    # Each run posts the check with when it read the comments, and posts neither the check nor
    # the comment when a check of a later reading is already there. Readings are ordered by each
    # runner's own clock, which GitHub keeps in time: two runs a moment apart may still be ordered
    # the wrong way round.
    concurrency:
      group: inputlayer-code-owners-${{ github.event.issue.number || github.event.workflow_run.pull_requests[0].number || github.event.workflow_run.head_sha }}
      cancel-in-progress: false
    env:
      GH_TOKEN: ${{ github.token }}
      GITHUB_TOKEN: ${{ github.token }}
      REPO: ${{ github.repository }}
      EVENT: ${{ github.event_name }}
      HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
      CHECK_RUN: ${{ github.event.workflow_run.id }}
      COMMENTED_ON: ${{ github.event.issue.number }}
    steps:
      # The pull request, its number, its head and its current base, from the API: never from the
      # run above, which ran the pull request's own copy of its workflow. After the check it is
      # looked up by its head commit (the event names no pull request for one from a fork); after
      # a comment, by the pull request the comment is on, and its check is the newest finished
      # run of the check workflow for its head.
      - id: pr
        run: |
          if [ "$EVENT" = issue_comment ]; then
            numbers=$(gh api "repos/$REPO/pulls/$COMMENTED_ON" --jq 'select(.state == "open") | .number')
            HEAD_SHA=$(gh api "repos/$REPO/pulls/$COMMENTED_ON" --jq .head.sha)
            # The check workflow's file: keep it named inputlayer.yml, or change it here too.
            CHECK_RUN=$(gh api "repos/$REPO/actions/workflows/inputlayer.yml/runs?head_sha=$HEAD_SHA&event=pull_request&status=completed&per_page=1" \
              --jq '.workflow_runs[0].id // empty')
            echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV"
          else
            numbers=$(gh api "repos/$REPO/commits/$HEAD_SHA/pulls" \
              --jq ".[] | select(.state == \"open\" and .head.sha == \"$HEAD_SHA\") | .number")
          fi
          count=$(printf '%s\n' "$numbers" | grep -c . || true)
          if [ "$count" -eq 0 ]; then
            echo "no open pull request has $HEAD_SHA as its head"; exit 0
          fi
          if [ "$count" -gt 1 ]; then
            # One status on the commit would answer for every pull request: check none.
            gh api "repos/$REPO/statuses/$HEAD_SHA" -f state=error -f context=inputlayer/code-owners \
              -f description="more than one open pull request has this head; checked none"
            exit 1
          fi
          number=$numbers
          echo "run=$CHECK_RUN" >> "$GITHUB_OUTPUT"
          gh api "repos/$REPO/pulls/$number" --jq '"base=\(.base.sha)\nbase_ref=\(.base.ref)"' >> "$GITHUB_OUTPUT"
          echo "number=$number" >> "$GITHUB_OUTPUT"
          gh api "repos/$REPO/statuses/$HEAD_SHA" -f state=pending \
            -f context=inputlayer/code-owners -f description="checking the code owners' approval"

      # The certificate the run above kept. It comes from the pull request's own run, so il ci
      # comment shows it as text only, and posts it only as the certificate of HEAD_SHA.
      - id: certificate
        if: steps.pr.outputs.number && !cancelled()
        continue-on-error: true
        uses: actions/download-artifact@v4
        with:
          name: inputlayer-certificate
          # Outside the workspace: the checkout below cleans it.
          path: ${{ runner.temp }}/certificate
          run-id: ${{ steps.pr.outputs.run }}
          github-token: ${{ github.token }}
      # A check that failed before it wrote a certificate says so on
      # the pull request, where a person looks first. gh only: no il needed. It
      # updates il ci comment's own comment (the marker), so a later certificate replaces it. A
      # comment that cannot be posted never stops the approval check below.
      - if: steps.pr.outputs.number && steps.certificate.outcome != 'success' && github.event.workflow_run.conclusion == 'failure' && !cancelled()
        continue-on-error: true
        env:
          NUMBER: ${{ steps.pr.outputs.number }}
        run: |
          marker='<!-- inputlayer-ci -->'
          body="$marker
          ### InputLayer

          The InputLayer check stopped before it could check this pull request, so nothing was checked here. Its log says why."
          id=$(gh api "repos/$REPO/issues/$NUMBER/comments" --paginate \
            --jq ".[] | select(.user.type == \"Bot\" and (.body | startswith(\"$marker\"))) | .id" | head -n1)
          if [ -n "$id" ]; then
            gh api -X PATCH "repos/$REPO/issues/comments/$id" -f body="$body" > /dev/null
          else
            gh api "repos/$REPO/issues/$NUMBER/comments" -f body="$body" > /dev/null
          fi

      # Your default branch, and the pull request's base and head as git objects only.
      - if: steps.pr.outputs.number
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          persist-credentials: false
      - if: steps.pr.outputs.number
        env:
          NUMBER: ${{ steps.pr.outputs.number }}
          BASE_REF: ${{ steps.pr.outputs.base_ref }}
        run: |
          export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.extraheader
          export GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GITHUB_TOKEN" | base64 -w0)"
          git fetch --no-tags origin "+refs/pull/$NUMBER/head:refs/remotes/pull/head" \
            "+refs/heads/$BASE_REF:refs/remotes/origin/$BASE_REF"

      # A placeholder: il's public install is not available yet (see the note below).
      - name: Install il
        if: steps.pr.outputs.number
        run: |
          # install il (public install not yet available)

      - id: approval
        if: steps.pr.outputs.number
        env:
          NUMBER: ${{ steps.pr.outputs.number }}
          BASE: ${{ steps.pr.outputs.base }}
        run: |
          set +e
          il codeowners approval --base "$BASE" --head "$HEAD_SHA" --pr "$NUMBER" --repo "$REPO" \
            --json-out owners-approval.json | tee approval.txt
          code=${PIPESTATUS[0]}
          case "$code" in 0) state=success ;; 1) state=failure ;; *) state=error ;; esac
          line=$(grep -m1 -E '^il codeowners approval: (FAIL|cannot tell|ok)' approval.txt | cut -c1-140)
          gh api "repos/$REPO/statuses/$HEAD_SHA" -f state="$state" \
            -f context=inputlayer/code-owners -f description="${line:-exit $code}"
          exit "$code"

      # A person's override, read again from every comment (il ci override), and the check run
      # "InputLayer guarantees" on the head: whether the check passed comes from GitHub's own
      # record of the check's run, never from what that run wrote. Without a certificate of this
      # head, or when il could not decide, it fails, and says why.
      - id: override
        if: steps.pr.outputs.number && !cancelled()
        env:
          NUMBER: ${{ steps.pr.outputs.number }}
          RUN: ${{ steps.pr.outputs.run }}
        run: |
          cert="$RUNNER_TEMP/certificate/certificate.json"
          rm -f override.json conclusion.json
          if [ -f "$cert" ] && [ -n "$RUN" ]; then
            il ci override --certificate "$cert" --pr "$NUMBER" --head "$HEAD_SHA" --run "$RUN" \
              --workflow .github/workflows/inputlayer.yml \
              --out override.json --certificate-out certificate.json --conclusion-out conclusion.json || true
          else
            jq -n '{conclusion: "failure", title: "No certificate of this head",
              summary: "The check left no certificate of this head commit: it stopped before it wrote one, or no finished run of it was found. Its log says why."}' > conclusion.json
          fi
          [ -s conclusion.json ] || jq -n '{conclusion: "failure", title: "InputLayer could not decide",
            summary: "il did not run here: see the workflow'"'"'s log."}' > conclusion.json
          # When the comments were read (il's own time, else now): the newest reading wins.
          read_at=$(jq -r '.read_at // empty' conclusion.json)
          [ -n "$read_at" ] || read_at=$(date -u +%Y-%m-%dT%H:%M:%S.%NZ)
          # Only a well-formed reading no later than this runner's clock (and 5 minutes) counts: a
          # check of that name with any other stamp never keeps this one from posting.
          ceiling=$(date -u -d '+5 minutes' +%Y-%m-%dT%H:%M:%S.%NZ)
          latest=$(gh api -X GET "repos/$REPO/commits/$HEAD_SHA/check-runs" -f check_name="InputLayer guarantees" \
            -f per_page=100 | jq -r --arg ceiling "$ceiling" \
            '[.check_runs[] | select(.name == "InputLayer guarantees") | .external_id // ""
              | select(test("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]{9}Z$"))
              | select(. <= $ceiling)] | max // ""')
          if [[ -n "$latest" && "$latest" > "$read_at" ]]; then
            echo "a later reading is already posted ($latest): posting nothing"
            echo "newer=true" >> "$GITHUB_OUTPUT"
            exit 0
          fi
          jq --arg sha "$HEAD_SHA" --arg at "$read_at" '{name: "InputLayer guarantees", head_sha: $sha,
            external_id: $at, status: "completed", conclusion: .conclusion,
            output: {title: .title, summary: .summary}}' conclusion.json > check-run.json
          gh api "repos/$REPO/check-runs" --input check-run.json > /dev/null

      # Not when a later reading posted its check: an older one never undoes it.
      - if: steps.certificate.outcome == 'success' && steps.override.outputs.newer != 'true' && !cancelled()
        env:
          NUMBER: ${{ steps.pr.outputs.number }}
        run: |
          approval=() data=() override=()
          # The approval step's own record: a change that still needs a code owner is said first.
          if [ -f owners-approval.json ]; then approval=(--approval owners-approval.json); fi
          # What the comment shows that the certificate does not carry (each break's steps, what
          # goes wrong for a person), which il ci --certificate wrote beside it.
          if [ -f "$RUNNER_TEMP/certificate/certificate.comment.json" ]; then data=(--comment-data "$RUNNER_TEMP/certificate/certificate.comment.json"); fi
          # A person's override, only as il ci override read it here.
          if [ -f override.json ]; then override=(--override override.json); fi
          il ci comment --certificate "$RUNNER_TEMP/certificate/certificate.json" "${approval[@]}" "${data[@]}" "${override[@]}" \
            --pr "$NUMBER" --head "$HEAD_SHA"

      # A step that failed before the check (the install of il) leaves no verdict: say so.
      # The approval step was then skipped, and its outcome is 'skipped' (never empty).
      - if: "!cancelled() && steps.pr.outputs.number && steps.approval.outcome == 'skipped'"
        run: |
          gh api "repos/$REPO/statuses/$HEAD_SHA" -f state=error -f context=inputlayer/code-owners \
            -f description="the check did not run: see the workflow's log"

It posts its result as the commit status inputlayer/code-owners on the pull request's head, and the certificate as a comment on the pull request with il ci comment. A later run updates that comment. Set up the owners first with il codeowners write: see Guarantees.

Then make your default branch's rule (a branch protection rule or a ruleset) require the check InputLayer guarantees and the status check inputlayer/code-owners, and require a review from code owners. In a ruleset, give InputLayer guarantees the GitHub Actions app as its source. Require those two, never the check job's own result (InputLayer check): GitHub runs a pull request's own copy of the check workflow, so the pull request can change what that job reports. InputLayer guarantees fails on a break the pull request brings, is neutral when a person overrode every such break (below), and passes when nothing fails; when the check left no certificate of the head, or il could not decide, it fails and says why.

Overriding a break

A person with write access to the repository (write, maintain or admin; the pull request's author too, when they have it) can accept a break instead of a fix, with a comment on the pull request whose first line is:

text
/inputlayer override <reason>

That covers every break at the head; /inputlayer override <id>: <reason> covers that guarantee's only. The reason is required. The workflow above runs again on the comment, and il ci override reads every comment on the pull request back from GitHub: one counts only when its first line starts with the command, its author is a person (not a bot account, and not posted by an app for them) with write access, it was never edited, and it was posted after the check of the head finished. An id that names no guarantee in the run is refused, never read as covering every break. Only the newest one counts, so overrides of one id each do not add up: to override several, use one comment with no id. The comment then says, under each break it covers, "Overridden by @<login>: <reason>", the login as code, which notifies no one; and InputLayer guarantees turns neutral once every break that fails it is covered. After the check runs again (a re-run too), override again: a comment counts only for the check run it was posted after. A new commit has no override until someone comments again; an edited or deleted comment is read again.

What it cannot stop: GitHub cannot tell a person from an agent using that person's own token, so never give an agent a token with write access to the repository. And the required check stops nobody with write access who changes the workflow: anyone who can push a branch can edit their own copy of the check workflow, and so can also post, or keep il from posting, a check of that name, so a code owner's review of everything under .github/ is the guard. The same holds for what the check writes: whether each break blocks (a guarantee enforced or not) is read from the certificate the check job writes, which that pull request can rewrite.

What fails the job

The check job fails when il ci exits non-zero. The status inputlayer/code-owners fails when a guarantee file changed without its owner's approval.

ExitFailsWhen
0noNothing blocks
1yesA guarantee is broken, reproduced on the real code, introduced by this PR. An override does not change this exit: it turns the check InputLayer guarantees neutral. Also: the check found a break that was never tried on the code: no way to replay it, its test could not run, or its trace or replay ran out of time or could not be made (cannot tell on the certificate)
2yesUsage: a bad flag, no guarantee file on the base branch, or an unknown --only id. Nothing was checked
3yesAccess refused
4yesA check could not run, so the run did not see everything (cannot tell)
5yesNo engine could run the checks
6yesA check no longer matches its code: code it is anchored to is gone or changed, or the code is newer than the check and il derive did not derive it again in this run

When several apply, the worst wins: 5 > 3 > 4 > 1 > 6 > 0.

A break whose test could not run fails the job too. On InputLayer's checkout-quickstart example with its break, in a job whose Python has no pytest, il ci --certificate prints:

FAIL retry-once-payments-checkoutclient-pay: break found in the check, not yet reproduced on the real code. derived again from the head's code by il derive, its break replayed on the head and the base its test failed in 0 of 20 runs on this change's code; it errored in 20 of 20 runs on this change's code and 20 of 20 on the base's code (an error is not a reproduction) not tried on the code: the reproduction on the real code could not run: test not reproduced: .inputlayer/rederive/test_replay_retry_once_payments_checkoutclient_pay.py failed by an assertion on 0 of 20 runs and errored on 20: a test that errors does not count; it reached the outcome it checks (printed INPUTLAYER-REACHED) on only 0 of 20 runsil ci: 1 guarantee(s): 1 break found in the check, not yet reproduced on the real code (exit 1)

Those runs errored: none failed by the guarantee's own assertion, as its third line says, so the break was not reproduced, and the job fails because the reproduction could not run.

Only guarantees that il derived itself are derived again in CI, from the pull request's code. A guarantee written by a person or an agent shows out of date (exit 6) when a change moves the code its check is anchored to, until its check is updated in the pull request.

These do not fail the job, and are always shown on the certificate:

  • a break that is pre_existing: it breaks the base branch too;
  • a break that was replayed on the real code and did not reproduce (cannot tell, shown as needs your decision; with --strict, exit 4);
  • a guarantee that is stated, not checked;
  • a suggested guarantee's results, unless you pass --enforce-suggested;
  • changed code no guarantee covers;
  • an open change request.

The certificate

il ci --base <rev> --certificate <file> writes the certificate, and il ci comment posts it on the PR, updating il's earlier comment there.

On InputLayer's checkout-quickstart example, after a change that retries the payment without its idempotency key, il ci --certificate cert.json --github writes this job summary:

text
## InputLayer guarantees

| guarantee | model | verdict | model and code | evidence |
| --- | --- | --- | --- | --- |
| `retry-once-payments-checkoutclient-pay` | `.inputlayer/models/derived/retry-once-payments-checkoutclient-pay.iql` | broken, reproduced on the real code: derived again from the head's code by il derive, its break replayed on the head and the base | derived again from the head's code | 19 states |

**Exit 1**: broken, reproduced on the real code

The replay runs as a pytest test, so it needs pytest installed for the Python il ci runs (python3, or the one --python names). Without it the break is not reproduced, as in the example under What fails the job.

Fields

FieldWhat it says
CommitThe head commit checked, the base branch and its commit, and whether the run was against the base branch. If it was not, no guarantee can read verified
GuaranteeEvery guarantee on the base branch, checked or not, with its sentence, category and content hash
Verdict and wordchecked, evidence incomplete (a holding guarantee, in the current build), broken, cannot tell (with the reason) or stated, not checked; verified once bounds name machine-readable limits, which the current build does not record. See Concepts
Evidence kindHow each check ran and what backs the result, as il records it
Introduced byFor a break: this_change, pre_existing or not_determined
BoundsThe guarantee's bounds, in words. The current build records no machine-readable limits
AssumptionsNot on the certificate: printed with the verdict after 'Assumed, not checked:'
Leaves outWhat the guarantee leaves out, as accepted
Guarantee changesEach guarantee the PR adds, removes or edits, in plain words, and whether its code owners approved
Checks changedChecks the PR adds or edits, listed for review. They decide nothing for this PR
Not covered yetChanged lines no guarantee's check covers. When coverage could not be computed, it says so and why, never an empty list
OverridesEach override: who made it (a person with write access), why, and on which commit
ReplayEach reproduced break's test command (replay.command), to run from the repository at the head commit

The same data is in the file --certificate names, as inputlayer.certificate/1, with the guarantee files pinned by sha256, the run's start and end times and the CI run's URL. Every certificate carries the line "A record of the checks run, not a warranty."

Annotations and summary

With --github, each break and each check that could not run is annotated on the code it concerns, and the job summary gets one table row per guarantee, with separate sections for suggested guarantees (not enforced) and for open change requests.

Running it locally

You can run the same check before you push:

bash
il ci --base origin/main --certificate .inputlayer/certificate.json

It reads the guarantees and checks at origin/main, checks your code (uncommitted changes to code a derived guarantee watches are refused: a certificate is about a commit), and writes the certificate there. A local run says provider: local in it.

AI shouldn't certify its own code.

Public install is not available yet. The Quickstart shows what InputLayer printed on an example.

Rather we check one service for you first? Book an audit →