Fixing red CI

Follow-ups fix failed checks on the pull requests kōjō opened. Two other cases also need a fix:

  • The default branch goes red. It stays red until someone notices. With follow_up.default_branch on, a failed check on the branch’s head starts one session that opens a draft pull request with a fix.
  • A person asks kōjō to fix their pull request. Before, kōjō opened a second pull request on top of theirs, which they then had to merge into their branch. Now a mention by the pull request’s author, or a mention on a pull request that carries the kojo:commit label, commits to that pull request’s own branch.

Both are narrow on purpose. The first is off until an operator turns it on, and the fix is always a draft. The second only writes to a branch whose owner asked, or that someone allowed to trigger work labeled.

A conveyor line of parcels runs under an orange warning beacon; below it a robot arm has lifted one parcel onto a workbench to mend it, and on a short belt to the right a second arm adds a piece to a hand-tied, tagged parcel without taking it off its belt. A conveyor line of parcels runs under an orange warning beacon; below it a robot arm has lifted one parcel onto a workbench to mend it, and on a short belt to the right a second arm adds a piece to a hand-tied, tagged parcel without taking it off its belt.
A red default branch gets a draft fix of its own; a person's pull request gets kōjō's commits on its own branch.

Where a failed check goes

Every forge reports a failed check as one event (check_failed), with its branch, its commit and, when the forge says so, its pull request. kōjō takes the first of these paths that applies:

flowchart TD
  E["A check fails"] --> C{"follow_up.checks on?"}
  C -- yes --> K{"On an open pull request kōjō opened?"}
  K -- yes --> KR["Follow-up round on kōjō's pull request"]
  K -- no --> L{"On a person's pull request with the label,<br/>added by someone with trigger_permission?"}
  L -- yes --> LR["Round on the person's branch,<br/>with the labeler's trust"]
  L -- no --> D
  C -- no --> D{"On the head of the default branch,<br/>with follow_up.default_branch on?"}
  D -- yes --> R["One draft fix of the default branch"]
  D -- no --> A["auto.check_failed, as before"]

A check that a path takes but turns down (a rejected round, a fix already open) stops there, and the audit log says why: it does not fall through to the next path.

A red default branch

Turning it on

repos:
  github/acme/web:
    enabled: true
    follow_up:
      default_branch: true   # a failed check on the default branch's head starts a draft fix

In the dashboard it is Fix a red default branch under Follow-ups and failed checks of a repository in Settings, Repositories. Operators can change it. It is off by default, so an upgrade changes nothing: until it is on, a failed check on the default branch goes the way of auto.check_failed, as it always did. With it on, this path replaces auto.check_failed for the default branch, and the fix session runs the skill auto.check_failed names, or lets the orchestrator choose when it names none.

What starts a fix

A failed check starts a fix when its branch is the repository’s default branch (as the forge reports it now) and its commit is that branch’s head. Then, in this order:

  • One session per red commit. A forge sends an event for each check that fails, and GitHub sends two for one failure (check_run and check_suite). The first event of a commit queues the session; the others are duplicates.
  • Stale commits. A commit that is no longer the head is turned down as red_stale: the later commit’s checks decide.
  • One fix at a time. While an earlier fix session of the repository is queued or running, or the pull request of the latest one is still open, the event is turned down as red_open. A branch that stays red does not pile up sessions.
  • After a declined fix. When a person closed the latest fix’s pull request without merging less than 24 hours ago, the event is turned down as red_declined. kōjō hears failed checks, not passing ones, so it cannot tell whether someone made the branch green in between: the 24 hours hold whatever happened on the branch. A flaky or long-red branch so gets at most one draft a day.

The session’s request is the check’s name, its link and what the forge reported with it (the output of each failing check, up to 48 KiB in all), read from the forge’s check runs for that commit. The build and the tests wrote that text, so it is data: it reaches the models only inside the fence that holds every text from outside, never as instructions. The session’s requester is ci:<branch>. Nobody asked for the work, so it lends nobody’s trust: it changes code in its own repository and nothing more (no team memory, no schedule, no change to a linked repository), and failed checks on its own pull request start no rounds (below).

The session

When it starts, the session reads the default branch’s head and its checks again. If no check of the head fails any more (a flaky test, or a person who fixed it by hand), the session ends succeeded with the outcome already_green and changes nothing. Otherwise it clones the head and works on the failure.

The result is a pull request against the default branch, and it is always a draft:

  • kōjō never merges it, never marks it ready and never asks in chat about it, whatever the merge policy says. The merge step of the session’s replay says why it is a draft.
  • A change the goal critic rejected is a draft too, as for every session.
  • Its description names the failed check (linked when its address is a web address), the branch and the red commit, and says that nobody asked for the change. Its title and description never close an issue: closing keywords are made inert.
A session page titled Fix failing checks on main: outcome draft pr opened, the summary of a rounding fix, the critic report, a Request panel with the folded output of the failed checks, requester ci:main, trigger red default branch, the failed check unit on main at its commit, and a low risk assessment.
A red default branch's fix in the dashboard: the trigger is "red default branch", and the request panel names the failed check and folds its output.

Rounds on the draft

The draft is one of kōjō’s pull requests, so a mention on it by someone with trigger_permission is a follow-up that commits to it. Those rounds never merge it either. A failed check on the draft starts no round: a follow-up from a check borrows the trust of whoever asked for the pull request, and nobody did.

Commits on a person’s pull request

Who can ask

A mention on an open pull request that kōjō did not open, from someone with the repository’s trigger_permission, commits to that pull request’s own branch when one of these asks:

  • The pull request’s author. Their own mention is enough.
  • The label. The pull request carries the label follow_up.label (default kojo:commit), and the person who added it has trigger_permission now. Then anyone’s trusted mention commits to the branch.

Any other mention opens a pull request of kōjō’s own on top of theirs, as before. On a pull request from a fork, that pull request goes against the fork’s base branch instead (the fork’s branch does not exist in the repository), so it carries the fork’s commits too; it is then always a draft that kōjō never merges, whatever the merge policy, because the risk score measured only kōjō’s change.

Who added the label matters because adding labels needs less than writing code: on GitHub, triage access is enough, and on GitLab a Reporter can. kōjō reads who added it from the forge’s history of the pull request (GitHub’s issue timeline, GitLab’s resource label events, Forgejo’s timeline), and a label added by someone without trigger_permission does not count. The label is read when a mention or a failed check arrives; adding it starts nothing by itself. Bitbucket Cloud’s pull requests have no labels, so there only the author’s own mention commits to their branch.

repos:
  github/acme/api:
    enabled: true
    follow_up:
      label: kojo:fixup   # empty or unset means kojo:commit

Which branches kōjō writes to

Even when the author or the label asks, kōjō commits only to a branch that is the pull request’s own working branch. When one of these holds, the session opens its own pull request on top instead, and says on the pull request which one it was (“kōjō opens a pull request on top of this one instead of committing to its branch: …”):

Reason, as kōjō words it Why
the pull request is not open A closed or merged pull request is done
it comes from a fork, and kōjō does not push to a fork’s branch The branch is in someone else’s repository. A pull request whose head repository the forge does not report counts as a fork. kōjō’s own pull request goes against the fork’s base and is always a draft (above).
its branch is the repository’s default branch The default branch is not a pull request’s working branch
its branch is the base of pull request #N A develop or release branch that other pull requests target. A pull request kōjō opened on top of the branch (an earlier mention that stacked) does not count.
its branch is protected The forge reports branch protection on it

The session checks again when it starts: when the pull request has moved to another branch, or one of these reasons now holds, it fails without a change and says why. Each forge adapter checks again before it writes, and refuses a commit unless the pull request is open, its head branch is exactly the branch written to, it is not from a fork, and the branch is not the default branch. So a mistake in kōjō’s core cannot push to any other branch.

What kōjō does and never does there

The session clones the pull request’s branch at its current head, the author’s work included, and adds a commit to that branch. The commit is written through the forge’s API on top of the commit the session started from, and only while the branch still points there: when someone pushed in the meantime, nothing is pushed, both commits are named in a comment, and the session ends branch_moved.

On a person’s pull request kōjō never:

  • merges it, marks it ready, or changes its draft state, title or description;
  • pushes a change the goal critic rejected, or one with a check that could not be verified.

The merge policy decides merging and marking ready, which kōjō does not do here, so it does not hold the push back: ask asks nothing, and a high risk score does not stop the commit. The author asked, or someone allowed to trigger work added the label, and the pull request’s own review still applies. Each round ends with a comment on the pull request:

  • Pushed: “Pushed <commit> to this pull request: follow-up round N of M. Goal critic: accepted. Risk level (score)”, with the risk’s reasons. The risk is measured on the whole pull request, as for kōjō’s own.
  • Rejected: what was tried, and “Nothing was pushed: the goal critic did not accept the change, and kōjō commits to a person’s branch only work that was accepted.” The change stays in the session.
  • Unverified: a check that runs on the code from before the pull request (on_base) found no merge base, so it could not run. Nothing is pushed, as for a rejected round: “Nothing was pushed: a check of the goal critic could not be verified (…), and kōjō commits to a person’s branch only work whose checks ran.” On kōjō’s own pull requests such a round goes only to a draft; a person’s pull request has no draft of kōjō’s to fall back to.

Rounds

follow_up.max_rounds (default 3) caps the rounds of one pull request, counted across sessions, as for kōjō’s own. After the last one, a mention is answered that kōjō makes no more changes there.

Failed checks on a labeled pull request

With follow_up.checks on and the label on the pull request, a failed check on the pull request’s current head starts a round, as on kōjō’s pull requests: once per commit, not while a session on the pull request is open, and within max_rounds.

The round borrows the trust of whoever added the label, read again at each round: they must still have trigger_permission, or nothing runs (request.reject). That is also how Dependabot’s and Renovate’s pull requests get fix rounds, once a maintainer labels them. An author’s own mention, without the label, does not turn check rounds on.

repos:
  github/acme/api:
    enabled: true
    follow_up:
      checks: true    # failed checks on kōjō's pull requests, and on labeled ones
      max_rounds: 3

How a mention is routed

flowchart TD
  M["A trusted mention on a pull request"] --> O{"Did kōjō open it?"}
  O -- yes --> F["Follow-up on kōjō's pull request"]
  O -- no --> W{"Mention by the author, or the label<br/>added by someone with trigger_permission?"}
  W -- no --> S["kōjō's own pull request on top, as before"]
  W -- yes --> B{"Branch eligible: open, not a fork,<br/>not the default branch, not a base, not protected?"}
  B -- no --> SW["Pull request on top, and kōjō says why"]
  B -- yes --> R{"No session busy with it,<br/>and rounds left?"}
  R -- no --> X["Answered on the pull request; nothing runs"]
  R -- yes --> C["Round committed to the pull request's branch"]

A mention while a session on the pull request is at work and takes messages is a message to that session, as anywhere else.

In the dashboard, the session page of such a round lists the rounds of the pull request under “Follow-ups on a person’s pull request”, with its branch and no opening session.

A session page for pull request #427, Export users as CSV with quoted fields: outcome pushed, a panel Follow-ups on a person's pull request #427 with 1 of 3 rounds, naming the branch carla/csv-export-quoting and saying kōjō leaves its title, description and draft state to its author, round 1 asked by carla and pushed, and a Request panel saying it is a follow-up of a person's pull request, on its branch, round 1.
A round on a person's pull request: kōjō commits to the branch and leaves the rest of the pull request to its author.
The Repositories settings of github/acme/web open at Follow-ups and failed checks: Follow up on a failed check ticked, Rounds per pull request empty, the label field set to kojo:fixup, and Fix a red default branch ticked.
The follow-up settings of a repository: check rounds, the label, and the red default branch.

Audit reasons

A failed check or a mention that starts nothing is written to the audit log as request.reject, with the reason and the commit or pull request:

Reason When
red_open A fix of the default branch is queued, running, or its pull request is open
red_stale The red commit is not the default branch’s head any more
red_declined The latest fix’s pull request was closed without merging less than 24 hours ago
the label was not added by someone with the trigger permission A failed check on a person’s pull request with the label, added by someone without trigger_permission
one of the branch reasons above A failed check on a labeled pull request whose branch kōjō does not write to
the check ran on an earlier commit of the pull request A failed check that is not about the pull request’s head
a session is working on the pull request A failed check while a session on the pull request is open
the pull request had all its follow-up rounds A failed check after the last round

Other entries: follow_up.route when a mention is routed to a person’s branch (asked_by is author or label, with the labeler), follow_up.start with foreign: true when such a round starts, red.start when a fix of the default branch starts (the red commit, the head it read, and whether that head was green), and merge.decide with the action none on a person’s pull request.

Scroll to move. + - zoom, 0 fit, Esc close.100%