Repository navigation
feat(provider-github): ci.rerun effect re-runs a PR head's failed workflow runs - #282
Merged
Merged
Conversation
…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
Bot
force-pushed
the
fx/ci-rerun-effect
branch
from
November 25, 2026 15:22
a377889 to
10b3a8e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 makesitem.pr.checks.stateignore superseded suites. This PR uses the same superseding rule.Contract (fixed: compliance-framework/factory-catalog depends on these exact names)
ci.rerun,SideAPI:v1alpha1.OpCIRerun, ineffectOps, and in the provider'sprOps, so a non-PR target isErrInvalid.factory ci rerun --pr <N|#N|owner/name#N> [--key <k>], MCP toolci_rerun.effects.allowand from a rule'seffect: { op: ci.rerun, target: primary }. The catalog validator accepts both; there's a newTestCIRerunOp.schemas/{rule,ruleset,taskspec}.schema.json,api/openapi.yaml(EffectOp enum) andweb/src/api/schema.d.ts(npm run gen:api).Provider behaviour (
internal/provider/github/effects_ci.go)GET …/pulls/{n}gives the head SHA. A closed or merged PR isErrInvalid.GET …/actions/runs?head_sha=<sha>&per_page=100, paged, up to 5 pages.latestRuns, which useschecksOf's rule. The comparator is now shared asrunOrder: run number, then created time, then ID. Of those runs, onlycompletedruns concludingfailure,timed_out,cancelledorstartup_failureare re-run.run_attemptisMaxRunAttempts(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.failureandtimed_outruns getPOST …/actions/runs/{id}/rerun-failed-jobs.cancelledandstartup_failureruns getPOST …/reruninstead, because they may have no failed job.partially-rerun: skipped run <id> (refused|attempt <n>), ….ErrInvalidcarrying every refusal.Outcome: "nothing-to-rerun".{actions: write, pull_requests: read}(the PR read needspull_requests).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
/checkspage.Also
GET …/actions/runs(needsactionsread; filters byhead_sha; paged), plusPOST …/rerun-failed-jobsand…/rerun(needactionswrite, return 201). A re-run is a new attempt that queues the run again. A run that isn't completed, andrerun-failed-jobson a run with no failed conclusion, are refused with 403. Helpers:AddWorkflowRuns,WorkflowRuns,SetWorkflowRun.ci.rerunon a PR (no CI is modelled) and rejects it on an issue.contracts.md§Effect opseffector.mdops tablegithub-provider.md: Apps table (actions RW), the Effects table, and a new "Decisions taken in fx/ci-rerun-effect" sectionrollout.md: App permissionsDeploy prerequisite: Actions: write
ccf-factoryGitHub App needsActions: writeforci.rerun. This is a manual change in the GitHub App settings, and each installation has to accept the new permission. Until thenci.rerunfails withErrInvalid(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 usesactions: read.ci.rerunineffects.allow) after this is released.Decisions
CreateEffect(internal/server/effects.go) replays any recordedeffectID(task, key)before the provider is called. Every successful Apply is recorded,nothing-to-rerunincluded. Sofactory ci rerun --key kacts once per task, whatever the head.--key rerun-<sha>, which the catalog does) or omit--key(each successful call then gets a fresh key).<key>@<head SHA>. The GitHubConnkeeps a bounded in-processrerunLog(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).rerunLogcovers 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.completedruns are re-run. A retry insideApplyre-lists the runs, so a run that was re-run before the failure is not posted again (tested).rerunLog) doesn't keepnothing-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).startup_failureruns call/rerundirectly (decided in review) rather than tryingrerun-failed-jobsfirst and falling back. That is one call, and the result is deterministic.ErrInvalidcomes 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.ci.rerunto the author identity. The reviewer App simply has no Actions permission, and the mint is refused with a message naming Actions: write (tested).Open questions for reviewers
nothing-to-rerun.POST /tasks/{id}/effectsreturns onlyeffectIdandurl(EffectResponse), soEffectResult.Outcomedoesn't reach the agent.pr.merge'slabelled-for-mergehas the same problem today. The URL is the PR's checks page in both cases. Decided: nooutcomefield for now. The catalog's bump-fix prompt (compliance-framework/factory-catalog#21) decides from its owngh run listbefore calling the effect and never reads its outcome. AddingoutcometoEffectResponsecan 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-tsctypecheck ofweb/: pass.go test -race ./...: all pass exceptinternal/agent/host/provision TestBaseScriptRuns. That test fails onmaintoo on macOS (no/etc/os-release); it is environmental and passes on Linux CI.TestApplyOpsci.reruncase: token, writes, replay.TestApplyCIRerun:/rerunrerun-failed-jobsTestApplyCIRerunNothing(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 isErrInvalidnaming both refusals.TestApplyCIRerunAttemptCap:nothing-to-rerunTestApplyCIRerunRefused:TestAPIOpsgolden (ci rerun --pr #9sendsci.rerunonacme/docs#9),TestPrecheck(refused wheneffects.allowlacks it), MCP tool table.TestApply, catalogTestCIRerunOp,TestEffectOpSide.🤖 Generated with Claude Code