Skip to content

Required Merge Gate fails or is cancelled on transient API errors and slow validation #169

Closed

Description

@kiwidream

Is there an existing issue for this?

I searched open and closed issues and PRs for the merge gate, its polling step and the log text below. #124 and #160 changed what the gate requires; neither concerns how it waits.

Current behaviour

The Required Merge Gate job waits for other checks on the same commit with a shell polling loop (wait_for_checks in required-merge-gate.yml). Two properties of that loop turn infrastructure noise into a red required check:

  1. One transient API failure fails the gate. Each poll assigns result="$(gh api ...)" with no retry. When the call fails, the step exits non-zero immediately. The gate reports failure even though nothing it was waiting for had failed.
  2. The wait budget equals the job timeout. max_attempts=720 with sleep_seconds=30 is 360 minutes of sleeping alone, and the job has timeout-minutes: 360. The loop's own "timed out" error can therefore never be reached: the runner cancels the job first, and a Full Validation Gate that is queued or slow for about six hours leaves the required check cancelled even if validation then succeeds.

Observed on 2026-09-16/17:

PR Gate job Outcome Full Validation Gate on the same commit
#165 104848436130 failed 20:49:58Z, log ends unexpected end of JSON input success 20:49:22Z
#159 104947590339 failed 20:49:56Z, same log line, while still waiting for the check to appear success 00:27:34Z (next day)
#162 104961179013 cancelled 02:18:28Z at the six-hour cap success 02:31:04Z

The two failures happened within two seconds of each other on unrelated commits, which points at one API blip rather than at either change. In all three cases Core Checks Gate and Full Validation Gate are green and the required check is red, so the PRs are blocked until someone re-runs the gate by hand.

Expected behaviour

  • A transient failure of the check-runs query is retried a bounded number of times and logged; it does not fail the gate on its own.
  • A persistent query failure still fails closed, with an error that says the API could not be read, distinct from "a required check failed".
  • An API error, an empty body or malformed output is never treated as success and never as "check not found yet" indefinitely.
  • The wait budget and the job timeout are reconciled so that the loop's own timeout message is reachable and states which checks were still pending.
  • The behaviour is covered by an executable test that runs the real polling logic against a stubbed gh, in the style of ci/checks/test_classifier_ci_contract.py, and that test runs in required CI.

Steps to reproduce

  1. Read wait_for_checks at the link above: the command substitution has no error handling, and the step runs under the default bash -e shell.
  2. Compare max_attempts x sleep_seconds with the job's timeout-minutes.
  3. Open the three job logs above and compare their end times with the Full Validation Gate check run on the same commits.

Relevant log output

Core Checks Gate: status=completed conclusion=success
Full Validation Gate: status=queued conclusion=pending
Core Checks Gate: status=completed conclusion=success
unexpected end of JSON input
##[error]Process completed with exit code 1.

Notes

CI only; no consensus, wallet or network behaviour is involved. The gate must remain fail-closed: the fix is to stop reporting noise as failure, not to make the gate easier to pass.

Activity

  1. added
    bug
    on Sep 18, 2026
  2. kiwidream commented on Sep 18, 2026

    @kiwidream
    MemberAuthor

    Addressed by #171, open against 1.x.x.

    The waiting loop now separates reading the check runs from judging them.

    • A failed check-runs query is retried up to 6 times with capped exponential
      backoff, each attempt logged with its reason, so the single API blip that
      failed ci: validate maintained source in scheduled heavy workflows #165 and ci: forward IBD workflow timeout inputs to the harness flags #159 two seconds apart no longer fails the gate.
    • When the retries are exhausted the gate fails closed, under
      Required Merge Gate could not read check runs, which is a different error
      from Required Merge Gate failed (a check concluded badly). An API error, an
      empty body, a truncated body, a page without a check_runs array or a run
      without a usable status are all query failures — never success, and never an
      endless "not found yet". "Query succeeded, no run with that name" is reported
      and treated separately, as pending.
    • The wait budget is now 19800s against the job's 360-minute cap. 360 minutes
      is the maximum a GitHub-hosted job can be given, so the budget had to go
      under it rather than the cap going up; the deadline is wall-clock, so time
      spent inside the API calls is charged to it and not only the sleeps. The
      loop's own Required Merge Gate timed out message is therefore reachable,
      and it names the checks that were still pending. A validation slower than
      330 minutes now ends with that message instead of the silent cancellation
      that hit script: cache successful P2MR PQC signature checks #162.
    • While reading the query, --paginate was added: per_page=100 alone could
      hide a required check beyond the first hundred check runs on a commit.
      Selection is unchanged — the newest run by started_at, falling back to
      created_at.

    ci/checks/test_merge_gate_poller.py runs the gate step's real run: script
    out of the workflow against a stubbed gh, with the waiting tunables
    overridden so it finishes in about 35 seconds, and runs in classify-changes
    — a job the gate depends on. Seven mutations were applied to the workflow to
    confirm the suite fails on each: removing the retry, a failed query counted as
    "not found yet", a failed query counted as success, a failure conclusion
    treated as pending, a budget above the job timeout, selecting the first check
    run instead of the last, and a deadline that counts only sleeps.

    Not addressed here, and unchanged: which checks each profile requires, and
    whether the hosted check is attached to a branch ruleset.

    #171 targets 1.x.x, which does not auto-close issues, so this stays open for a
    maintainer to close once it merges.

  3. kiwidream commented on Sep 23, 2026

    @kiwidream
    MemberAuthor

    Fixed on 1.x.x by #171 (merge ae722219be). Merges into a non-default branch do not fire closing keywords, so closing by hand. Mapping the expected behaviour to the merged workflow and its test at a6442d28f9:

    • Transient query failures are retried: query_check_run in .github/workflows/required-merge-gate.yml retries the check-runs query up to GATE_QUERY_MAX_ATTEMPTS (6) times with capped backoff and logs each attempt.
    • Persistent failure fails closed with its own title, Required Merge Gate could not read check runs, distinct from Required Merge Gate failed.
    • A non-zero exit, empty or truncated body, or a page without check_runs is a query failure, never absent; absent is reported only when the query succeeded. The query now paginates instead of stopping at 100 check runs.
    • The wait keeps one wall-clock deadline (GATE_WAIT_TIMEOUT_SECONDS, 19800 s against the 360-minute job cap), so Required Merge Gate timed out is reachable and names the checks still pending.
    • ci/checks/test_merge_gate_poller.py runs the gate step's real run: script against a stubbed gh, and runs in the classify-changes job the gate depends on; the gate run for 787504bdfe logged Ran 17 tests ... OK.

    All three gates were green on the merge commit. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions