Skip to content

ci(workflows): auto-rerun Test attempts GitHub cancelled without a runner - #570

Open
itsmiso-ai wants to merge 2 commits into
mainfrom
courier/misospace/windowstead/issue-562
Open

itsmiso-ai wants to merge 2 commits into
mainfrom
courier/misospace/windowstead/issue-562

Conversation

@itsmiso-ai

@itsmiso-ai itsmiso-ai commented Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #562.

GitHub's hosted macos-latest pool cancelled queued Test jobs during capacity windows without ever acquiring a runner. A new helper workflow recovers those runs on its own, and it never touches a run that failed for a real reason.

What ships

  • .github/workflows/ci-rerun.yml (new): triggers on workflow_run completion of the Test workflow, gated to failure or cancelled conclusions. Job-scoped permissions only: contents: read, actions: write, pull-requests: read, checks: read. No app token, no contents: write, no schedule.
  • .github/scripts/ci-rerun-action.mjs (new): the gate. An attempt reruns only when all of these hold:
    1. the run was a pull_request run with an open PR (looked up by head=<owner>:<branch>, because the event payload's pull_requests array is empty on real fork and same-repo runs),
    2. run_attempt is below 3 (three total attempts, no stored state),
    3. every non-success/non-skipped job of that attempt is cancelled, ran zero steps, never had a runner, and carries a failure-level annotation matching "not acquired".
      The rerun POSTs rerun-failed-jobs; if GitHub refuses it for any reason, one full rerun is the fallback. The decision never depends on parsing an HTTP status out of gh's error text. Any API error on the read path exits 1 without rerunning (fails closed).
  • tests/test_ci_rerun_gating.sh (new): structure checks on the workflow plus 15 behavioral cases that run the script against a stubbed gh API.
  • .github/workflows/test.yml: new ci-rerun-gating job runs the test in the CI matrix.

Verified against the live API, not memory

  • Run 46702351588 (one of the issue's runs): the run conclusion is failure, not cancelled, while the two macOS jobs are cancelled with runner_id: 0, runner_name: "", and zero steps. The helper therefore accepts both run conclusions.
  • GET /repos/.../check-runs/<job_id>/annotations returns the failure annotation "The job was not acquired by Runner of type hosted even after multiple attempts" plus a repo-wide notice "Due to capacity constraints...". The gate counts only the failure-level "not acquired" annotation as proof, because the notice rides along with unrelated cancels.
  • The jobs endpoint does not return a needs field, so dependency-cascaded cancels are excluded through the annotation rule instead: a cascaded cancel has no failure-level "not acquired" annotation.
  • head=forkland%3Afeature%2Fx filters correctly on GET /pulls; the test stub pins that encoded form, because a wrongly encoded value is silently ignored and would return every open PR.

Invariants this change keeps, and the other paths for the same rule

  • The Test workflow keeps read-only checkout behavior. test.yml still declares permissions: contents: read and is not modified except for the appended structure-test job.
  • No workflow here runs untrusted PR code in a privileged context. ci-rerun.yml checks out the default branch only (no ref: input, no head_sha reference anywhere), so actions: write is never exposed to PR content. ai-pr-review.yaml enforces the same trust boundary for the reviewer by a different rule (same-repo, non-draft gate); neither workflow is weakened.
  • Permissions are job-scoped, never workflow-level. tests/test_release_workflow_gating.sh enforces that rule for release.yml; the new test enforces it for ci-rerun.yml (no write grant before jobs:, job block pinned to the four grants).
  • Runner capacity is recovered by rerunning, never by weakening gating. Reruns stay inside the existing Test workflow semantics; the Manual Release workflow and release.yml are untouched, and no rerun path bypasses them.
  • A gated attempt tries both rerun endpoints before giving up: rerun-failed-jobs first, then one full rerun on any refusal, because the gate already proved the attempt is a pure capacity cancel. No decision path parses gh's error text for a status code. tests/test_ci_rerun_gating.sh pins the fallback for a status-carrying refusal, a status-less refusal, and a failed fallback (fails closed).
  • Every CI structure test must stay wired into the matrix. Other tests are wired the same way in test.yml; the new job follows the identical bash tests/... pattern.

Local validation (re-run on head ee9a7c7)

  • bash tests/test_ci_rerun_gating.sh — exit 0, 33 OK lines (structure + 15 behavioral cases, including: real failure blocks rerun, attempt 3 stops before any API call, notice-only annotation does not qualify, stale event for an old attempt does not rerun, status-less refusal still falls back, failed fallback fails closed, GET error fails closed, dry run never posts).
  • node --check .github/scripts/ci-rerun-action.mjs — clean.
  • bash tests/test_release_workflow_gating.sh, test_release_tag_validation.sh, test_release_version_injection.sh — all pass (shared-file regression check).
  • Both workflows parsed with js-yaml at 53d174d; the follow-up commit changes no YAML. ci-rerun.yml has no top-level permissions: block; the job holds exactly the four grants.
  • Not runnable in this container and pre-existing on clean main too: test_release_notes_guard.sh, test_web_package_validation.sh, test_ai_review_comment_authorization.sh (they need python3, absent here). CI has it.
  • GDScript suites were not run: this change adds no .gd files and touches no Godot resource.

External verification left pending

  • CI on this PR (full matrix, including the new ci-rerun-gating job).
  • The helper activates only after merge, because workflow_run executes the default-branch copy of the workflow. Real recovery depends on the next macOS capacity window.
  • GitHub does not document whether rerun-failed-jobs includes zero-step cancelled jobs; the any-refusal fallback to a full rerun covers a strict answer. The fallback is bounded by the three-attempt cap and the current-attempt assertion.

One deviation from the issue text, deliberate: checks: read is required in addition to actions: write and pull-requests: read, because the per-job annotations endpoint demands it.

its-saffron[bot]

This comment was marked as outdated.

…562)

The 409/422 fallback keyed off regexing gh's human-readable error text;
if that format drifted, a refused rerun would fail closed instead of
recovering. The gate has already proven the attempt is a pure capacity
cancel, so any refusal of the targeted rerun now gets the equivalent
full rerun, and only a failed fallback exits 1. Adds stub cases for a
status-less refusal and a failed fallback.

@its-saffron its-saffron Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{"schema":"review-handoff/v1","review_id":"fd4920e430896c58","head_sha":"ee9a7c7286608c4a74a9f0ad960e5bb9dfa04485","verdict":"approve","review_result":"partial","required_checks":"none","items":[{"id":"fb045b3a28d387398b859aae8e8d5875b908ca850ee8d341987be868e38aba69","severity":"info","category":"verification","path":".github/workflows/ci-rerun.yml","line":10,"message":"The second-attempt recovery depends on GitHub emitting a `workflow_run` event per re-run attempt; the stubbed test covers only the decision script, not the trigger, so the three-attempt ceiling is unverified end to end. (review thread PRRT_kwDOSBzTVM7AG5mh: open)"},{"id":"a31bb22d852a7d15fda690af455fff26e43363f8312533a854e1b7a65572f095","severity":"minor","category":"other","path":".github/scripts/ci-rerun-action.mjs","line":null,"message":"The full-rerun fallback re-executes every job of the attempt, including jobs that already succeeded, so a 409/422 refusal costs a complete matrix re-run rather than just the cancelled macOS jobs. (review thread PRRT_kwDOSBzTVM7AG5me: open)"}],"items_total":2,"items_truncated":false,"unresolved_requirement_ids":[],"unresolved_requirement_ids_total":0,"unresolved_requirement_ids_truncated":false,"unresolved_requirement_ids_source_total":0,"unresolved_required_checks":[],"unresolved_required_checks_total":0,"unresolved_required_checks_truncated":false,"unresolved_required_checks_source_total":0,"unresolved_review_obligations":[],"unresolved_review_obligations_total":0,"unresolved_review_obligations_truncated":false,"derived_obligation_state":null}

AI Automated Review

🟡 Automated recommendation: INCOMPLETE — no blocking code defect proven; approval withheld (the reviewer declared a materially relevant question unresolved)

Full PR review.

Analysis engine: MiniMax-M3.1-Flash (anthropic) — primary route · pr-reviewer-action v3.11.2

Reviewer-declared material unknowns (unresolved questions, not proven defects):

  • It remains unverified whether GitHub emits a 'workflow_run' completion event for every rerun attempt, which is required for automatic recovery beyond the first attempt.

Findings (1 minor, 1 info)

Severity Location Finding
Info .github/workflows/ci-rerun.yml:10 The second-attempt recovery depends on GitHub emitting a `workflow_run` event per re-run attempt; the stubbed test covers only the decision script, not the trigger, so the three-attempt ceiling is unverified end to end. (review thread PRRT_kwDOSBzTVM7AG5mh: open)
Minor .github/scripts/ci-rerun-action.mjs The full-rerun fallback re-executes every job of the attempt, including jobs that already succeeded, so a 409/422 refusal costs a complete matrix re-run rather than just the cancelled macOS jobs. (review thread PRRT_kwDOSBzTVM7AG5me: open)

Recommendation: Incomplete — no blocking code defect proven; approval withheld (the reviewer declared a materially relevant question unresolved). (Model suggestion before validation, not authoritative: approve with an external-verification caveat; no blocker or major issue is established at the current head.)

Linked Issue Fit

The helper implements the requested capacity-only gate, three-attempt ceiling, least-privilege permissions, default-branch execution, and CI-wired structure test. The live API evidence confirms that the specified zero-step, runnerless jobs carry the failure-level “not acquired” annotation used by the gate.

Tool Harness Findings

The workflow-security checklist and current-head workflow/script were inspected. Live run and annotation responses corroborate the detection shape, while the stubbed tests cover the decision paths and fallback behavior. The tool loop was interrupted before observing a real rerun attempt end to end.

Unknowns or Needs Verification

GitHub’s behavior for emitting a workflow_run completion event for every rerun attempt remains externally unverified. The current implementation fails closed if an event is absent, but a live second-attempt recovery would settle whether the acceptance criterion is fulfilled end to end.

Sources

Current-head diff and files; linked issue PR 562; successful CI rerun gating (workflow structure) check; live run/job/annotation API responses.

Unresolved Review Threads

  • PRRT_kwDOSBzTVM7AG5mh: open
  • PRRT_kwDOSBzTVM7AG5me: open
  • PRRT_kwDOSBzTVM7AG5mb: fixed

Approval withheld — review incomplete: the reviewer declared a materially relevant question unresolved No blocking code defect was proven; this run needs review and no native approval is certified.

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.

Auto-rerun Test workflow jobs GitHub cancels without acquiring a runner (macOS capacity)

1 participant