Skip to content

fix(ci): move SLACK_WEBHOOK_URL guard out of job-level if: (5 Slack workflows) - #233

Merged
FabioLeitao merged 2 commits into
mainfrom
cursor/sre-automation-agent-protocol-5fc6
Apr 27, 2026
Merged

FabioLeitao merged 2 commits into
mainfrom
cursor/sre-automation-agent-protocol-5fc6

Conversation

@cursor

@cursor cursor Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

CI Autofix Automation

Failure logs

5 red Slack workflow runs per push on main (and feature branches), e.g.:

  • slack-release-published-notify.yml run 25005009490
  • slack-operator-ping.yml run 25005008794
  • slack-ci-failure-notify.yml, slack-pr-merged-notify.yml, slack-ops-digest.yml (same shape)

GitHub UI message on every one: "This run likely failed because of a workflow file issue."
The runs report event: push, the workflow name is the file path (not the YAML name:), and jobs[] is empty (total_count: 0). That trio is GitHub's tell-tale signature of workflow-validation failure — the engine never scheduled a job, so there are no logs to fetch.

History: slack-release-published-notify.yml has been failing on every push since at least run 398 (2026-04-26). It has never succeeded. The Slack manual ping workflow had the same bug fixed once before (commit 2962068) and the same posture is in use by the sonar job in ci.yml (commit 881bdec).

Broken by

Commit 4e05a4d ("ci(workflow): Slack manual ping skips job when webhook empty + guard test", 2026-04-19) re-added the anti-pattern by introducing a guard test that required SLACK_WEBHOOK_URL to appear in the job-level if:. The five Slack workflows were aligned to that guard:

jobs:
  notify:
    runs-on: ubuntu-latest
    if: >-
      ${{
        secrets.SLACK_WEBHOOK_URL != '' &&
        ...
      }}

Reason (RCA — Julia Evans style)

GitHub Actions evaluates job-level if: expressions during workflow validation, before any runner picks the workflow up. The secrets context is not reliably available during that validation pass for many event types (push, release, workflow_run, pull_request: closed, schedule). When secrets.SLACK_WEBHOOK_URL cannot be evaluated:

  1. GitHub treats the if: as falsy and produces a workflow run with zero jobs.
  2. A run with zero jobs is recorded as failure with the canned "workflow file issue" message.
  3. Because no job ran, there are no step logs to inspect — only the postmortem of the run metadata reveals the cause.

This is the same class of bug the sonar job in ci.yml already fixed in 881bdec ("fix Sonar job without secrets in job-level if"). The Slack workflows simply regressed to the bad pattern.

Fixed by

Replace the job-level secret check with a step-level detection step that reads the secret in env: (where the secrets context is fully resolved at run time, not validation time) and writes present=true|false to $GITHUB_OUTPUT. Every downstream step is then gated on if: steps.webhook.outputs.present == 'true'.

jobs:
  notify:
    runs-on: ubuntu-latest
    # Non-secret guards stay at job level (event, vars.*, upstream conclusion, merged flag).
    if: ${{ vars.SLACK_NOTIFY_RELEASE_PUBLISHED == 'true' }}
    steps:
      - name: Detect Slack webhook
        id: webhook
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        run: |
          if [ -n "$SLACK_WEBHOOK_URL" ]; then
            echo "present=true" >> "$GITHUB_OUTPUT"
          else
            echo "present=false" >> "$GITHUB_OUTPUT"
            echo "SLACK_WEBHOOK_URL is unset; downstream steps will skip cleanly."
          fi

      - name: Post release published summary to Slack
        if: steps.webhook.outputs.present == 'true'
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        ...

Applied symmetrically to all five files. Other guards (event type, vars.* opt-ins, upstream workflow_run.conclusion, pull_request.merged) stay at the job level — they never depended on the secrets context.

Anti-regression

tests/test_github_workflows.py::test_slack_post_workflows_guard_webhook_secret was inverted: it now forbids secrets.* and SLACK_WEBHOOK_URL in any job-level if: and requires a step that

  • reads SLACK_WEBHOOK_URL via env:,
  • writes present=true|false to $GITHUB_OUTPUT,
  • has an id:,
  • and is followed by at least one step gated on steps.<id>.outputs.present == 'true'.
tests/test_github_workflows.py ........... 11 passed in 0.08s

Defensive architecture (zero impact on locks / DB / runtime)

This is a CI-only workflow change. No application code, no SQL, no detector heuristics, no API surface, no Docker image, no DB scan path is touched. There is zero impact on database locks, scan budgets, or the WITH (NOLOCK) posture from DEFENSIVE_SCANNING_MANIFESTO.md.

Doctrine

  • THE_ART_OF_THE_FALLBACK.md — graceful degradation, never silent failure. Workflows now degrade cleanly when the webhook is unset (step Detect Slack webhook logs a clear note and downstream steps skip) instead of producing a phantom failed run with no logs.
  • DEFENSIVE_SCANNING_MANIFESTO.md — test what you fly. The same present=true|false contract used by ci.yml's sonar job is now used by every Slack POST workflow, and the regression test enforces it.

Files

  • .github/workflows/slack-ci-failure-notify.yml
  • .github/workflows/slack-operator-ping.yml
  • .github/workflows/slack-ops-digest.yml
  • .github/workflows/slack-pr-merged-notify.yml
  • .github/workflows/slack-release-published-notify.yml
  • tests/test_github_workflows.py (regression guard inverted)

Verification after merge

  1. Watch a push to main — five red Slack workflows should turn green (or be skipped by their non-secret if:, which still records a successful run).
  2. workflow_dispatch of slack-operator-ping with SLACK_WEBHOOK_URL set should still post.
  3. workflow_dispatch without the secret should record a single green run that says "SLACK_WEBHOOK_URL is unset; downstream steps will skip cleanly" and nothing else.

SRE Autofix Automation — RCA + fix + regression guard. No application/runtime side effects. Pre-commit and tests/test_github_workflows.py green locally.

Open in Web View Automation 

…flows)

Root cause: every slack-*.yml referenced `secrets.SLACK_WEBHOOK_URL != ''`
inside the *job-level* `if:`. GitHub Actions cannot reliably resolve the
`secrets.*` context in a job-level `if:` for many event types, which
makes the workflow validate against an empty job set and emit a phantom
failed run with the message 'This run likely failed because of a workflow
file issue.' This is the exact symptom the SRE protocol triggered on (5
red runs per push on `main`).

Fix (defensive, no-regression): replace the job-level secret check with a
`Detect Slack webhook` step that reads the secret in `env:` and writes
`present=true|false` to $GITHUB_OUTPUT, then gate every downstream step
on `steps.webhook.outputs.present == 'true'`. Same posture already in
use by the `sonar` job in `ci.yml` (commit 881bdec). Non-secret
checks (event type, opt-in `vars.*`, upstream conclusion, PR-merged
flag) keep their job-level `if:` so trigger semantics are unchanged.

Regression guard: `tests/test_github_workflows.py::test_slack_post_
workflows_guard_webhook_secret` was inverted to forbid `secrets.*` /
`SLACK_WEBHOOK_URL` in job-level `if:` and to require a step-level
detection step plus at least one step gated on its output.

Doctrine: aligns with `docs/ops/inspirations/THE_ART_OF_THE_FALLBACK.md`
(graceful degradation, never silent failure) and `DEFENSIVE_SCANNING_
MANIFESTO.md` (test what you fly, no surprise side effects).

Made-with: Cursor

Co-authored-by: Fabio Tavares Leitão <[email protected]>
@FabioLeitao
FabioLeitao marked this pull request as ready for review April 27, 2026 18:58
@FabioLeitao
FabioLeitao merged commit ef74845 into main Apr 27, 2026
1 check passed
@FabioLeitao
FabioLeitao deleted the cursor/sre-automation-agent-protocol-5fc6 branch April 27, 2026 18:58
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.

2 participants