Skip to content

fix(provider-github): roll up only the latest check suite per workflow - #281

Merged
gusfcarvalho merged 3 commits into
mainfrom
fx/checks-latest-suite
Nov 25, 2026
Merged

gusfcarvalho merged 3 commits into
mainfrom
fx/checks-latest-suite

Conversation

@ccf-lisa

@ccf-lisa ccf-lisa Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

checksOf rolled every check suite of a PR's head commit into checks{state, settled}, so a suite superseded by a later run of the same workflow (a concurrency-group cancel, a re-trigger) turned a green PR into failure. Real case: compliance-framework/api#584, where a cancelled preview run sits next to its green successor; GitHub shows the PR green, the factory said failure, and pr.checks.completed rules (the catalog's bump-fix) would fire on a passing PR.

Stack: this is PR 1 of 2. PR 2 (fx/ci-rerun-effect) adds the ci.rerun effect op.

Changes

  • Observe query (observe.go): each check suite now also reads databaseId, createdAt, app { databaseId } and workflowRun { runNumber event workflow { databaseId } } (field names checked against the live GitHub GraphQL API on api#584).
  • checksOf → latestSuites: of the suites with check runs, only the latest of each workflow is rolled up. Kind = (App, workflow, event) for a GitHub Actions workflow run. A suite whose workflow can't be identified (another App's suite such as CodeRabbit's, an Actions suite with a null workflowRun, or a run with a null workflow) is never superseded and supersedes nothing. Latest = highest run number, then newest createdAt, then highest databaseId. The roll-up itself is unchanged (failure > pending > success, same conclusion sets, suites without runs ignored).
  • Re-runs: checked on GitHub (compliance-framework/api run 45409396833: attempt 1 failure, attempt 2 success). The run's check_suite_id stays the same, and that suite's conclusion changes to the latest attempt's. So the latest attempt is what counts, with no attempt handling needed. This is recorded in the checksOf doc comment.
  • Token: observePerms adds actions: read (for workflowRun). The ccf-factory App already lists actions R in the LLD's App table, and the serve/tokens test installations grant it.
  • githubtest: CheckSuite gains ID, Created, App, Workflow, RunNumber, Event. The fake GraphQL emits them and now requires actions for workflowRun, the same way it checks the other field permissions.
  • LLD (github-provider.md): the §Observe field list, the checks roll-up and the Observe token permissions are updated.

Decisions

  • The event is part of the kind, which is stricter than (app, workflow). A push run and a pull_request run of the same workflow are separate checks, and in practice they are in separate concurrency groups. So a failing push run is not hidden by a green pull_request run. The api#584 shape is all pull_request, so it is unaffected.
  • A later suite without check runs never supersedes an older one with runs. GitHub's empty queued suites are filtered out before grouping.
  • Only identifiable workflow runs supersede each other (review follow-up, decided by the reviewer). Suites without an App, without a workflowRun (other Apps, or an Actions suite whose run was deleted) or with a null workflow always count and supersede nothing. Grouping them per App would let unrelated suites supersede each other, so a failing one could hide behind a green one.
  • actions: read on Observe's token, with no fallback (confirmed in review). I couldn't check whether GitHub requires it for CheckSuite.workflowRun on a private repo, because public repos answer any token. Asking for it is cheaper than the failure mode where every PR's Observe gets FORBIDDEN. The prod installation already grants Actions: read. After deploy, an installation without Actions: read fails Observe, ReadContent and Project with ErrInvalid (the token mint names actions, before any GraphQL call; TestObserveFieldPermissions covers this).

Deploy note

  • The ccf-factory App must have Actions: read (the LLD already lists it, and the prod installation grants it). An installation without it fails Observe, ReadContent and Project with ErrInvalid after this is deployed.

Verification

  • go test -race ./...: all pass except internal/agent/host/provision TestBaseScriptRuns. That test also fails on main on macOS (/etc/os-release missing). It is environmental and unrelated.
  • make lint: 0 issues. make check-generated, make catalog, make openapi-lint: pass.
  • New tests:
    • TestObserveChecks cases:
      • the api#584 shape → success, settled
      • cancelled then failed, same workflow → failure
      • failed then succeeded (re-trigger) → success
      • any input order
      • two workflows with an unsuperseded cancel → failure
      • latest in progress over an older failure → pending
      • an empty later suite doesn't supersede
      • another event isn't superseded
      • another App's suites never supersede each other
      • an Actions suite with a null workflowRun is never superseded and supersedes nothing, and two of them both count
      • a run with a null workflow, in both directions
      • tie-breaks on createdAt and databaseId
    • Recorded fixture testdata/graphql/pr-superseded.json (the api#584 suites) with golden testdata/golden/observe/pr-superseded.json.
    • TestObserveFieldPermissions: also with actions missing.

Open questions for reviewers

  • None blocking. A related point that this PR leaves out of scope: the check_suite.completed webhook's event.checks.state fact is still the one completed suite's own conclusion. Rules should read item.pr.checks.state, which this PR fixes, not event.checks.state.

🤖 Generated with Claude Code

ccf-lisa Bot and others added 2 commits November 25, 2026 11:44
A check suite superseded by a later run of the same workflow on the same
commit (a concurrency-group cancel, a re-trigger) made a green PR read as
checks failure, so pr.checks.completed rules fired on passing PRs
(compliance-framework/api#584).

Observe now reads each suite's App, workflow run (number, event,
workflow) and createdAt/databaseId, and checksOf rolls up only the
latest suite per (App, workflow, event), or per App for non-Actions
suites. Re-runs keep the same suite, so the latest attempt counts.
Observe's token gains actions: read for workflowRun.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A suite with an App but no workflowRun (another App's, or an Actions
suite whose run is gone) got the kind "<app>", so unrelated suites
superseded each other and a failing one could hide behind a green one.
Only suites whose App, workflow and event are known are grouped now;
any other suite always counts and supersedes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gusfcarvalho
gusfcarvalho added this pull request to stack #283 November 25, 2026 16:00
@gusfcarvalho
gusfcarvalho merged commit c5e8752 into main Nov 25, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant