Skip to content

feat(provider-github): ci.rerun effect re-runs a PR head's failed workflow runs - #282

Merged
gusfcarvalho merged 4 commits into
fx/checks-latest-suitefrom
fx/ci-rerun-effect
Nov 25, 2026
Merged

gusfcarvalho merged 4 commits into
fx/checks-latest-suitefrom
fx/ci-rerun-effect

Conversation

@ccf-lisa

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

Copy link
Copy Markdown
Contributor

Summary

Adds a new API-side effect op, ci.rerun. With it an agent (the catalog's bump-fix) can treat a CI failure on a PR as a flake and re-run it, instead of changing code.

Stack: this is PR 2 of 2, based on #281 (fx/checks-latest-suite), which makes item.pr.checks.state ignore superseded suites. This PR uses the same superseding rule.

Contract (fixed: compliance-framework/factory-catalog depends on these exact names)

  • Op ci.rerun, SideAPI: v1alpha1.OpCIRerun, in effectOps, and in the provider's prOps, so a non-PR target is ErrInvalid.
  • Effector factory ci rerun --pr <N|#N|owner/name#N> [--key <k>], MCP tool ci_rerun.
  • Can be used from a TaskSpec's effects.allow and from a rule's effect: { op: ci.rerun, target: primary }. The catalog validator accepts both; there's a new TestCIRerunOp.
  • Regenerated schemas/{rule,ruleset,taskspec}.schema.json, api/openapi.yaml (EffectOp enum) and web/src/api/schema.d.ts (npm run gen:api).

Provider behaviour (internal/provider/github/effects_ci.go)

  1. GET …/pulls/{n} gives the head SHA. A closed or merged PR is ErrInvalid.
  2. GET …/actions/runs?head_sha=<sha>&per_page=100, paged, up to 5 pages.
  3. Only the latest run per (workflow, event) is considered. This is latestRuns, which uses checksOf's rule. The comparator is now shared as runOrder: run number, then created time, then ID. Of those runs, only completed runs concluding failure, timed_out, cancelled or startup_failure are re-run.
  4. Attempt cap: a run whose run_attempt is MaxRunAttempts (3) or more is skipped. The provider never takes a run past its third attempt, as a loop safety net for rule-driven use. Capped runs don't count as re-run.
  5. failure and timed_out runs get POST …/actions/runs/{id}/rerun-failed-jobs. cancelled and startup_failure runs get POST …/rerun instead, because they may have no failed job.
  6. A run GitHub refuses (403 or 422 on its re-run, e.g. older than 30 days or already re-running) is skipped, and the others are still re-run.
    • If at least one run was re-run, the op succeeds. When some were skipped (refused or capped), the outcome is partially-rerun: skipped run <id> (refused|attempt <n>), ….
    • If nothing was re-run and something was refused, the op is ErrInvalid carrying every refusal.
    • Otherwise (all green, running or capped) it succeeds with Outcome: "nothing-to-rerun".
  7. The token is the identity's installation token with {actions: write, pull_requests: read} (the PR read needs pull_requests).
  8. Idempotency: once per task per key on the Effector path, and per (key, head SHA) inside the provider. See the Decisions section below.
  9. Error mapping: 404 → ErrNotFound. 403/422 → ErrInvalid, and the message names Actions: write when GitHub says the integration can't access the resource or the mint is refused. Other 403s, such as a run over 30 days old, keep GitHub's message. 5xx and rate limits are retried.

The result's object is the PR and its URL is the PR's /checks page.

Also

  • githubtest: GET …/actions/runs (needs actions read; filters by head_sha; paged), plus POST …/rerun-failed-jobs and …/rerun (need actions write, return 201). A re-run is a new attempt that queues the run again. A run that isn't completed, and rerun-failed-jobs on a run with no failed conclusion, are refused with 403. Helpers: AddWorkflowRuns, WorkflowRuns, SetWorkflowRun.
  • fake provider: accepts ci.rerun on a PR (no CI is modelled) and rejects it on an issue.
  • Docs:
    • contracts.md §Effect ops
    • effector.md ops table
    • github-provider.md: Apps table (actions RW), the Effects table, and a new "Decisions taken in fx/ci-rerun-effect" section
    • rollout.md: App permissions
    • The repo has no changelog file.

Deploy prerequisite: Actions: write

  • The ccf-factory GitHub App needs Actions: write for ci.rerun. This is a manual change in the GitHub App settings, and each installation has to accept the new permission. Until then ci.rerun fails with ErrInvalid (HTTP 400 to the agent), and the message names the missing permission. fix(provider-github): roll up only the latest check suite per workflow #281 also uses actions: read.
  • The catalog side lands in compliance-framework/factory-catalog (bump-fix gets ci.rerun in effects.allow) after this is released.

Decisions

  • Idempotency: once per task per key (decided in review). This is the contract.
    • On the agent path, CreateEffect (internal/server/effects.go) replays any recorded effectID(task, key) before the provider is called. Every successful Apply is recorded, nothing-to-rerun included. So factory ci rerun --key k acts once per task, whatever the head.
    • To re-run a new head in the same task, use a per-head key (--key rerun-<sha>, which the catalog does) or omit --key (each successful call then gets a fresh key).
    • The head SHA is deliberately not folded into the server's effect key.
    • Inside the provider the effective key is <key>@<head SHA>. The GitHub Conn keeps a bounded in-process rerunLog (1024 entries) of the effective keys it re-ran something with, so the same key on the same head is a replay (Replayed: true, nothing posted).
    • The rerunLog covers what the store doesn't: a rule's effect is applied before it is recorded and again when its reconcile retries (rule keys are per event), and an Effector call whose Apply succeeded but whose record write failed is applied again.
    • GitHub keeps nothing that could carry the key: the re-run endpoints take no body, so there is no marker to look up, unlike the other ops.
    • If a restart makes the Conn forget a key, a replay still posts nothing while the runs it re-ran are queued or running, because only completed runs are re-run. A retry inside Apply re-lists the runs, so a run that was re-run before the failure is not posted again (tested).
  • The provider's own memory (rerunLog) doesn't keep nothing-to-rerun. That matters only for rule effects: on the agent path the stored effect replays the same key anyway. A partial re-run is remembered and replayed with its outcome (TestApplyCIRerunPartlyRefused).
  • Cancelled and startup_failure runs call /rerun directly (decided in review) rather than trying rerun-failed-jobs first and falling back. That is one call, and the result is deterministic.
  • Per-run refusals don't fail the op (decided in review). 403 and 422 on one run skip it, and the others are re-run. ErrInvalid comes only when nothing was re-run and something was refused. 404s and retryable errors still fail or retry the whole op.
  • MaxRunAttempts = 3 (decided in review): a run is never re-run past its third attempt.
  • The event is part of the superseding key, as in fix(provider-github): roll up only the latest check suite per workflow #281.
  • The catalog validator does not restrict ci.rerun to the author identity. The reviewer App simply has no Actions permission, and the mint is refused with a message naming Actions: write (tested).
  • The contract change is in this PR with the code that uses it. AGENTS.md prefers contracts in their own PR, but the stack was specified as these two PRs, and fix(provider-github): roll up only the latest check suite per workflow #281 doesn't touch the contract.

Open questions for reviewers

  • The agent can't see nothing-to-rerun. POST /tasks/{id}/effects returns only effectId and url (EffectResponse), so EffectResult.Outcome doesn't reach the agent. pr.merge's labelled-for-merge has the same problem today. The URL is the PR's checks page in both cases. Decided: no outcome field for now. The catalog's bump-fix prompt (compliance-framework/factory-catalog#21) decides from its own gh run list before calling the effect and never reads its outcome. Adding outcome to EffectResponse can be a separate contract PR if another consumer needs it.

Verification

  • make lint: 0 issues. make check-generated, make catalog, make openapi-lint: pass. vue-tsc typecheck of web/: pass.
  • go test -race ./...: all pass except internal/agent/host/provision TestBaseScriptRuns. That test fails on main too on macOS (no /etc/os-release); it is environmental and passes on Linux CI.
  • New and updated tests:
    • TestApplyOps ci.rerun case: token, writes, replay.
    • TestApplyCIRerun:
      • only the latest failed run per workflow is re-run
      • green, running, neutral and other-commit runs are skipped
      • cancelled and startup failure get /rerun
      • timed out gets rerun-failed-jobs
      • a replay with the same key posts nothing
      • another key re-runs
      • a new head re-runs
    • TestApplyCIRerunNothing (not remembered), TestApplyCIRerunPages, TestApplyCIRerunRetries.
    • TestApplyCIRerunPartlyRefused: a 403 or 422 on one run still re-runs the rest, the outcome names the skipped run, and a replay returns the same outcome. When every run is refused, the op is ErrInvalid naming both refusals.
    • TestApplyCIRerunAttemptCap:
      • a capped run alone → nothing-to-rerun
      • a capped run next to a run that can be re-run → named in the outcome
      • a run re-run up to the cap is skipped on the next call
    • TestApplyCIRerunRefused:
      • closed or merged PR
      • issue target, issue number, missing PR
      • installation without Actions: write
      • reviewer App
      • 403 on the re-run, 403 on the PR, a 403 for another reason
      • 422, 404
    • Effector: TestAPIOps golden (ci rerun --pr #9 sends ci.rerun on acme/docs#9), TestPrecheck (refused when effects.allow lacks it), MCP tool table.
    • Fake provider TestApply, catalog TestCIRerunOp, TestEffectOpSide.

🤖 Generated with Claude Code

ccf-lisa Bot and others added 4 commits November 25, 2026 12:17
…kflow runs

Adds the API-side effect op ci.rerun (v1alpha1.OpCIRerun, a PR op) so an
agent can treat a CI failure as a flake. The GitHub provider reads the
PR's head, lists its workflow runs, keeps the latest run per workflow and
event (the superseding rule checksOf uses, now shared as runOrder), and
re-runs the completed failed ones: rerun-failed-jobs, or rerun for a
cancelled run. Nothing to re-run is the nothing-to-rerun outcome.

Idempotency is per (key, head SHA): the Conn remembers the keys it re-ran
with, so the same key on the same head is a replay; the dispatcher's
Effect store is the durable record. The token is actions: write (plus
pull_requests: read); a missing grant is ErrInvalid naming Actions: write.

Also: effector op 'factory ci rerun --pr N [--key k]' (MCP ci_rerun), the
fake provider, githubtest Actions routes, regenerated schemas, OpenAPI and
web client, and the LLDs (contracts, effector, github-provider, rollout).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…right permission

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… startup failures whole

- startup_failure runs go to POST .../rerun, like cancelled ones.
- A run GitHub refuses (403/422) is skipped and the others are still
  re-run; the outcome names the skipped runs (partially-rerun: ...).
  Only when nothing was re-run and something was refused is the op
  ErrInvalid.
- A run at its third attempt (MaxRunAttempts) is never re-run again, a
  safety net against rule-driven loops.
- Docs: on the Effector path a --key acts once per task (the effect
  store replays it), so a later head needs --key rerun-<sha> or no key;
  rerunLog covers rule effects and the record-after-Apply window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ccf-lisa
ccf-lisa Bot force-pushed the fx/ci-rerun-effect branch from a377889 to 10b3a8e Compare November 25, 2026 15:22
@gusfcarvalho
gusfcarvalho added this pull request to stack #283 November 25, 2026 16:00
@gusfcarvalho
gusfcarvalho merged commit cc87cf6 into main Nov 25, 2026
61 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