Skip to content

af-cron: CI Health Check reports its own command failure as 'CI failing on main' (condition ignores exitCode) #1456

Open

Description

@amrmelsayed

The CI Health Check cron reports a transient failure of its own gh command as a CI incident. Fired 2026-08-14 02:30Z with:

CI Alert: currently failing on main: Command failed: gh run list --branch main --limit 10 --json workflowName,conclusion --jq '...'

CI on main was green at the time, and the identical command succeeded on re-run seconds later, returning empty. The alert was purely a transient API/network failure wearing an incident's clothes.

Root cause: our own condition, not the framework

.af-cron/ci-health.yaml:

command: gh run list --branch main --limit 10 --json workflowName,conclusion --jq '... | join(", ")'
condition: "output != ''"
message: "CI Alert: currently failing on main: ${output}..."

When the command fails, its error text becomes output, which is non-empty, so output != '' is true and the alert fires with the error interpolated into a sentence asserting CI is broken. A command failure and a genuine CI failure are indistinguishable to this condition.

The framework already provides the discriminator. #1142 added exitCode to the condition sandbox (tower-cron.ts:259, :312-315), and the code comment states the intent plainly: "With a condition, the condition alone decides (a non-zero exit is data the condition can inspect via exitCode, not noise)." This task simply never inspects it.

Fix

condition: "exitCode === 0 && output != ''"

One line. The alert then fires only when the query genuinely ran and genuinely found failing workflows.

Worth doing in the same pass:

  • Audit the other tasks in .af-cron/ for the same shape (team-update.yaml uses the same runner and deserves a look).
  • Consider a runner-side guard so this cannot recur per-task: when exitCode !== 0 and the condition does not mention exitCode, either suppress delivery or prefix the message with a clear "the check itself failed" marker. The current default is arguably the wrong way round — a task author who writes a naive condition gets false incidents rather than silence.

Why this is worth more than its size

A false "CI is failing on main" is not a harmless nuisance: it asserts a specific broken state, and the correct response to a real one is to stop merging. This is the third instance in twenty-four hours of a tool returning a confidently wrong answer that invited a wrong action — alongside afx cleanup -i reporting "builder not found" for builders that exist (#1445), which led to two worktrees being deleted by hand. The pattern is worth naming: our tooling's failure modes tend to present as findings rather than as failures.

Activity

  1. added
    area/tower
    on Aug 14, 2026
  2. amrmelsayed commented on Aug 16, 2026

    @amrmelsayed
    CollaboratorAuthor

    Recurred, 2026-08-16T00:48:16Z — same false positive, same shape:

    CI Alert: currently failing on main: Command failed: gh run list --branch main --limit 10 --json workflowName,conclusion --jq '…'

    Verified immediately after: every recent workflow on main is success (47477ca76, 8f28453a3, f705d07fb), and the identical command re-run returns empty with exit 0. Nothing was failing.

    That is the second time this alert has cried wolf in three days, against one true alarm in the same window (the #1435 TTL race reddening trunk on 08-15). So the signal is now wrong more often than it is right, which is worse than useless: it trains the reader to discount a message whose entire purpose is to be believed.

    The fix remains one line — condition: "exitCode === 0 && output != ''" — and the framework already provides exitCode to conditions (#1142; tower-cron.ts:259, :312-315). The task simply does not inspect it, so a transient gh failure lands its error text in ${output}, which is non-empty, which fires an alert asserting a specific broken state.

    Worth restating the general principle this issue is an instance of, since it now has three siblings (#1445, #1448 and the gh pr checks exit-code trap): an instrument that can answer a narrower question than its name implies must say so in its output. Here the check answers "did my query fail or find failures?" while its message asserts "CI is failing on main". Even before the condition is fixed, the message should distinguish the two — "the CI check could not run" is a different sentence from "CI is failing", and only one of them should stop a merge.

  3. amrmelsayed commented on Aug 19, 2026

    @amrmelsayed
    CollaboratorAuthor

    Second false-positive mode observed 2026-08-19 05:30Z, distinct from the command-failure one this issue was filed for: the cron alerted "currently failing on main: Dashboard E2E Tests" when no failing state existed. The cited failure was run 32115101362 (08-18 08:11Z, the pre-#1519 nightly), which a newer green workflow_dispatch run (32129607931, 08-18 11:00Z, verifying PR #1520's fix) had already superseded three hours later. No new run of any kind existed at alert time.

    Implication for the fix: the staleness check can't consider only the latest schedule-event run — a green workflow_dispatch of the same workflow on the same branch is equally authoritative about "currently failing". Either compare against the latest run regardless of trigger event, or suppress the alert when a newer green run of the workflow exists on the branch.

  4. amrmelsayed commented on Aug 21, 2026

    @amrmelsayed
    CollaboratorAuthor

    Instance #4, 2026-08-21 04:00Z — the original command-failure mode again: the alert body was the cron's own gh network error ("error connecting to api.github.com / check your internet connection"), reported as "currently failing on main". Actual state at verification: last 5 runs on main all green, including yesterday's nightly Dashboard E2E. Tally for prioritisation: two command-failure false alarms (08-15→18), one stale-run false alarm (08-19, comment above), now a third command-failure — four cried-wolves against zero true alerts since filing.

  5. amrmelsayed commented on Aug 30, 2026

    @amrmelsayed
    CollaboratorAuthor

    Instances 5 and 6, both false positives (now 6-for-6 false, 0 true): cron alerts 2026-08-28T23:30Z and 2026-08-29T02:00Z, both "error connecting to api.github.com / check your internet connection" — the alert text is the cron job's own gh network failure, the documented signature. Main was verifiably green through the window (scheduled CLI Integration + Dashboard E2E runs on d005034 succeeded 08-28 through 08-30).

  6. amrmelsayed commented on Sep 5, 2026

    @amrmelsayed
    CollaboratorAuthor

    Specimen 7 (2026-09-05 00:45Z), and it isolates a distinct defect class from the previous six: the alert body is the cron's own command error — Command failed: gh run list --branch main … — reported through the CI-failure template. Verified immediately after: gh run list --branch main showed the last four main pushes (through 80cbc4c) fully green on both workflows. So beyond threshold/parsing false positives, the monitor also lacks a distinction between "my probe failed" (transient gh/network error → should retry or report monitor degradation) and "CI failed" (should alert). Record stands at 7-for-7 false positives, zero true positives.

  7. amrmelsayed commented on Sep 5, 2026

    @amrmelsayed
    CollaboratorAuthor

    For the record: alert 8 (2026-09-05 20:30Z, "Dashboard E2E Tests failing on main") was the monitor's first true positive — the scheduled dashboard run really was red (#1630, fix in PR #1632). Running tally: 7 false positives, 1 true. The exitCode defect this issue tracks is unchanged; specimen 7 above remains the clean reproduction.

  8. amrmelsayed commented on Oct 5, 2026

    @amrmelsayed
    CollaboratorAuthor

    Another false positive, with the mechanism this time (2026-10-05 21:00Z alert)

    Alert text: "currently failing on main: CLI Integration Tests". Reality: every run on main's head 9cd860729 is green (push run 07:27Z and scheduled run 09:13Z both success). The most recent failed run in the whole repo is from 2026-08-18.

    Mechanism, reproduced by running the probe's exact command twice within a minute:

    • gh run list --branch main --limit 10 --json workflowName,conclusion does not return the ten most recent runs on main. It returned runs from 2026-09-18, 2026-09-16, 2026-08-22 and 2026-08-21, none from today, and the set differed between the two calls.
    • The --jq then takes group_by(.workflowName) | map(.[0]), i.e. the first run per workflow in whatever slice came back. One call returned a slice whose first CLI Integration Tests entry was a failure; the next call's slice was all success. Neither slice was current.

    So the probe is sampling an arbitrary historical slice, not main's current state. Fix shape for whoever owns the cron: query the current state directly, for example one call per workflow with --branch main --event push --limit 1 (or gh api repos/{owner}/{repo}/actions/workflows/<id>/runs?branch=main&event=push&per_page=1) and compare head_sha against git rev-parse origin/main before trusting the conclusion. A failure is only real when it is on the current head.

  9. amrmelsayed commented on Oct 9, 2026

    @amrmelsayed
    CollaboratorAuthor

    Second defect, same cron (observed 2026-10-07 to 2026-10-08, main architect):

    A command error is reported as a CI failure. When the check itself cannot run, the alert still reads "CI Alert: currently failing on main: …" with the error text spliced in where the workflow names go. Three instances:

    • 2026-10-07 02:45Z and 03:01Z: Command failed: gh run list --branch main … (the executor could not run gh; two other cron tasks in other workspaces failed in the same minute, so the cause was host-side and transient).
    • 2026-10-08 22:30Z: failed to get runs: Get "https://api.github.com/…": dial tcp …: connect: network is unreachable (no connectivity on the host).

    In all three cases every run on the current head of main (9cd8607) was green.

    Expected: distinguish "could not check" from "red". A non-zero exit from the gh query should produce either no message or a clearly different one ("CI health check could not run: "), never a "failing on main" alert. Together with the stale-slice problem already on this issue, four of four alerts in this stretch were false.

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

    area/tower

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions