# CI status checks (your own CI file)

A project can let its own CI file decide its landing check instead of Forge's runner. Forge
publishes each Candidate as a branch, the project's unchanged workflow runs on that push, and
the CI provider's own record of the run passes or fails the check. Forge's own repository keeps
using [Forge's runner](github-actions-checks.md); this is a second provider behind the same
project setting.

## Setup

1. Turn on the [GitHub mirror](github-app.md) to the repository whose workflow should run.
   Candidate branches start from main's mirrored commit, so the CI repository is the mirror.
2. Add one trigger line to the workflow's `push` branches, and nothing else:

   ```yaml
   on:
     push:
       branches: [main, 'forge/candidates/**']
   ```

3. Select the provider (owner only). `runtime` and `environmentFingerprint` are recomputed by the
   server from the setting; pass any 64-character hex value:

   ```sh
   nforge agent ROOT configure-runner '{"configuration":{"provider":"ci-status","ci":{"adapter":"github-actions","repository":"OWNER/NAME","workflow":".github/workflows/test.yml"},"runtime":"0000000000000000000000000000000000000000000000000000000000000000","environmentFingerprint":"0000000000000000000000000000000000000000000000000000000000000000"}}'
   ```

On the web, the owner starts from Settings → Landing and checks, which asks "Which CI do you
have?": GitHub Actions, GitLab CI, another CI or your own machines, or no CI yet. The project's
current check sets the initial choice as soon as the chooser opens. If the project has yet to
choose a check, the page suggests a CI based on main's files (workflow files, `.gitlab-ci.yml`,
or another CI's file in the root folder). Every answer leads to a route that works today: GitHub Actions to
the steps below, any other CI to a [machine you run](self-hosted-runner.md) (Forge cannot
publish to GitLab yet), and no CI to one command on that machine or on
[Forge's check workflow](github-actions-checks.md).

For GitHub Actions the page selects the current workflow immediately. When the current runner is
Forge's GitHub Actions runner, the page shows the workflow Forge starts directly. As files arrive,
the page lists other workflows on main and shows whether each can check a landing through a push
to the mirror. Choosing a different workflow on the page applies step 3. The page shows the exact
step 2 change where needed, and the server derives the pins. The **Check settings for agents**
chip shows the terminal command for reading the settings.

Choosing a file is not the end of setup. Until a landing has been checked by it, the page says
"No landing checked yet" and what stands in the way: the file on main does not run on Forge's
branches yet (with the exact change), the file is not on main, or nothing, in which case the
next landing is its first run. **Give this to your agent** copies this prompt, with the
project, file and line filled in:

```text
In the Forge project NAME, start a Lane and change .github/workflows/ci.yml: line 5 becomes:
    branches: [main, 'forge/candidates/**']
Change nothing else, then land it. This file decides the project's check, so the landing waits for the owner's approval.
```

Once a landing since the choice carries a check run, the page shows when that first landing was
checked and drops the setup text.

The setting is refused while the mirror is off or points at another repository.

## What happens per landing

1. The check run publishes `forge/candidates/<runId>` with the mirror's Git data API push: the
   changed blobs, one tree and one commit on main's mirrored commit, then one new ref. The branch
   is created once and never moved; Forge never writes main this way.
2. GitHub runs the workflow on that push.
3. GitHub's signed `workflow_run` webhook (the Forge App's existing webhook) reaches Forge. Only
   the configured workflow file's `push` run of the published commit on that branch, first
   attempt, counts. The first such run binds the check; every later or other run is ignored.
4. `completed` with `success` passes the check; `failure` fails it; `cancelled` cancels it. The
   run link in the receipt points at the GitHub run.
5. Superseding or cancelling an unneeded check requests a stop of its exact bound GitHub run,
   using Forge's existing cancellation action. A check with another live landing consumer stays
   running. If cancellation precedes GitHub's first event, that signed event binds the execution
   and requests its stop; it cannot revive the cancelled check. The provider link records the
   remote outcome. Cancellation cannot be undone; run a fresh check to execute the Candidate again.


Calls per landing: one publish action (one prepare and one record mutation, plus one source read
per 100 changed objects) and one webhook mutation per workflow event (requested, in progress,
completed), so about five or six. Nothing polls; an idle project costs nothing. An unneeded run uses the same one stop action and
one preparation mutation as Forge Actions; ordinary successful landings add neither. A transient
stop request retries that same provider run inside the action, with no extra Convex call.

## What a pass attests

A pass needs the CI provider's own record of the run, read on a channel the job cannot write:
the signed webhook for GitHub Actions, or Forge reading the provider API itself. A job that
reports its own status never passes a check, and a job report can only ask Forge to read the
provider record. Changing the CI file needs the owner's review, as changing a check script does:
the file is a protected check entry.

For an adapter execution that expects a Forge job API plan, a failed provider record
before that plan is recorded uses the shared check-infrastructure retry and CI-down hold.
A standalone workflow that supplies its own verdict needs no Forge job API plan.

## Outside contributors

The workflow runs with the mirror repository's secrets. Forge publishes only Candidates whose
author and requester are the owner or a contributor. An outside contributor's Candidate settles
`runner-unavailable` with that reason and needs a check on Forge's own runner.

## Limits today

- GitHub Actions publishes. GitLab CI is verified by the contract test (its pipeline record read
  through the GitLab API decides; its webhook is only a wake) but cannot publish yet, so the
  setting refuses it.
- When the Candidate base has a queued or running mirror publication, the same check waits for
  that exact publication and retries automatically when it completes, without polling. A terminal
  mirror failure settles the check visibly; a base with no publication still reports unavailable.
- A Candidate over eight 100-object windows fails visibly. Git LFS paths publish pointers and upload
  missing objects through the mirror's existing LFS transport before creating the Candidate ref.
- A signed completion removes the matching Candidate branch after the verdict, using the same
  webhook action and mutation. Cleanup checks the commit first, leaves a changed ref untouched,
  and records its recreate-ref undo instruction in backend logs. Provider run logs remain available.
  A missing branch is an idempotent replay; a GitHub failure remains visible in webhook logs.

Code: `src/ci-status.ts` (adapters and verdict), `convex/projectCiStatus.ts` (run, events),
`convex/projectCiStatusPublish.ts` (branch publish), `tests/ci-status-contract.test.mjs`.

## Optional proof on landing

Run `nforge x ROOT set-policy '{"acceptance":{"proofOnLanding":true}}'` to retain optional
proof evidence. It defaults off. This field is explicitly exempt from owner-gate classification:
it adds evidence, changes no acceptance rule, and never invalidates a queued landing's policy pin.
Proof never passes or fails the provider check; a project without a reporting step has no proof.

Any CI can submit the provider-neutral report after comparing the same head tests against base
and head. Supply the exact Forge run ID, Candidate State head and bound provider execution ID.
With an existing Forge project credential in your CI secret store, the step can use the Convex
client (the credential must already have project write access):

```js
import { ConvexHttpClient } from 'convex/browser';
import { makeFunctionReference } from 'convex/server';
const client = new ConvexHttpClient(process.env.FORGE_CONVEX_URL);
client.setAuth(process.env.FORGE_CI_TOKEN);
await client.mutation(makeFunctionReference('projectLandingProof:report'), {
  projectId: process.env.FORGE_PROJECT_ID,
  runId: process.env.FORGE_RUN_ID,
  head: process.env.FORGE_CANDIDATE_HEAD,
  executionId: process.env.FORGE_EXECUTION_ID,
  report: JSON.stringify({kind:'proof', reports:[
    {file:'tests/regression.test.mjs', base:'failed', head:'passed'},
  ]}),
});
```

Run each changed head test once on the base source, then on the head. Report `error` when setup
or execution cannot establish a test result, `passed` when it passes on base too, and `failed`
when it fails on base. Reports name at most twenty distinct test files; the same report can be
retried, while a different report cannot replace it. This is job-reported evidence, not an
independent provider attestation. GitHub Actions and GitLab CI share this report contract; the
existing GitLab publishing limitation above still applies.

Forge's runner adds the optional `hosted-proof` job only for its standard check when changed test
files are present and the installed workflow supports it. It reuses verified base blobs already
in the plan's cache, reconstructs the base with head tests, installs/builds it and runs each file
once with the same Candidate isolation as shards. A cold cache missing base blobs, setup failure
or unavailable isolation gives inconclusive evidence without extra source calls. Opaque commands
can report from their own CI using the step above. Forge joins base outcomes to its normal head
reports; a failed or flaky head test never proves a change.

The job is excluded from the required-job verdict, so acceptance never waits for it. One mutation
retains the report beside the run. Acceptance reads and `land`/`wait` summaries join that evidence
on the exact run; it can arrive after landing, and the immutable receipt stays unchanged. With
proof off there is no proof output, job, artifact data or call. With it on, budget one optional
job (roughly 2–4 runner-minutes plus tests), one mutation and one small run-side metadata field.
Public runners are paid for by their repository's existing CI arrangement; no new service is used.
