repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

Add a dead-man's switch for a fail-closed pipeline (#36)

4041593045f41a229dbfd78410bfa6833a7fe75d

Oliver Jan Krylow <oliver@bugabinga.net> ·

SSH signature · not checked

Browse filesCompare with HEAD

## What forced this
Every merge gate is fail-closed: a red required check holds `merge-gate`
down. Right for one bad PR, catastrophic when the *check itself* breaks
(a green-tree CodeQL that finds no code fails on every PR) — then
nothing merges, no single PR is "wrong", and the hourly per-PR `sweeper`
never names it.

## The call
A deterministic, no-LLM board-wide scan (`adw-jam-detector`) calls a jam
when one required check is red on ≥2 open non-draft PRs, and escalates
through an ungated issue so the alert reaches the owner even when every
merge lane is wedged.

## What we deliberately didn't do
Dropped the single-PR "blocked too long" heuristic: one blocked PR is
the gate working correctly, so it can't distinguish a jam from normal
operation — only the cross-PR count can.

## Evidence
Tally logic unit-tested locally against check names with spaces (`CodeQL
Advanced`); caught and fixed a `paste -sd', '` cyclic-delimiter bug that
mis-joined the affected-PR list. Escalation is idempotent (one open
`pipeline-jammed` issue, auto-closed on the next clean scan);
`adw-doctor` is woken only on the transition into a confirmed jam, never
on re-scans.

## Surface touched
`.github/workflows/adw-jam-detector.yml` (new), the `pipeline-jammed`
label in `.github/labels.yml`, one unhappy-paths row + subsection in
`docs/plans/AGENTIC-DEVELOPMENT.md`.

## If this ages badly
The `workflow_run`/`check_suite` edges are best-effort (GitHub
suppresses some self-triggered check events); the `*/30` schedule is the
load-bearing floor. If jams are caught late, tighten the cron or add a
p35-style harness to confirm which edges actually fire. Revert the
workflow to disable.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB)_

Co-authored-by: Claude <noreply@anthropic.com>

Changed files (3)

+179 / −0 text lines

Diff layout

.github/labels.yml

Modified

+3 / −0 text lines

6969 description: "Escalated to the owner — never auto-merges"
7171# — housekeeping —
72- name: "pipeline-jammed"
73 color: "9b1c1c"
74 description: "A required check is failing across ≥2 PRs — merges are wedged; jam-detector opened this"
7275- name: "blocked"
7376 color: "b5179e"
7477 description: "Waiting on another issue — usually a needs:spec escalation"

.github/workflows/adw-jam-detector.yml

Added
new file mode 100644

+159 / −0 text lines

1# ADW jam detector — the pipeline's dead-man's switch. Every ADW gate is
2# fail-closed by design: a broken required check holds `merge-gate` red, which is
3# correct for ONE bad PR but catastrophic when the break is systemic (a green-
4# tree CodeQL that finds no code and fails on every PR, an action that got
5# yanked). Then nothing merges and no single PR is "wrong" — the jam is invisible
6# from any one PR's vantage. This job watches the whole board and rings a bell.
7#
8# Deterministic, no LLM: a shell/jq scan tallies, per required-check name, how
9# many distinct open non-draft PRs it is FAILING on. Same check red on >= 2 PRs =
10# a systemic jam, not one bad branch. The LLM (adw-doctor) is dispatched only
11# AFTER a jam is confirmed, and only on the transition into jam — never on a
12# steady-state re-scan, so it can't spam.
13#
14# Escalation lands as an ISSUE, not a PR — issues have no merge gate, so the
15# alert reaches the owner even when every merge lane is wedged. The issue is
16# idempotent (one open `pipeline-jammed` issue at a time) and auto-closes the
17# instant a scan comes back clean.
18#
19# Triggers: failure-completions of the gating workflows and check-suites give a
20# fast edge (seconds after the break), and a 30-minute schedule is the
21# deterministic floor — GitHub suppresses some self-triggered check events, so
22# the cron is what guarantees the jam is caught even if every edge is missed.
23name: adw-jam-detector
25on:
26 workflow_run:
27 workflows: ["adw-review", "adw-gate", "adw-build", "CodeQL Advanced", "DevSkim"]
28 types: [completed]
29 check_suite:
30 types: [completed]
31 schedule:
32 - cron: "*/30 * * * *" # deterministic floor — the edge triggers are best-effort
33 workflow_dispatch: {}
35permissions:
36 contents: read
37 issues: write
38 pull-requests: read
39 actions: write # dispatch adw-doctor on a confirmed jam
41concurrency:
42 group: adw-jam-detector
43 cancel-in-progress: false # let a running scan finish; don't drop the alert
45jobs:
46 detect:
47 # A green check can never jam the pipeline — only look when something failed
48 # (or on the schedule / a manual poke). This keeps the scan off the hot path
49 # of every successful run.
50 if: >-
51 github.event_name == 'schedule' ||
52 github.event_name == 'workflow_dispatch' ||
53 (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'failure') ||
54 (github.event_name == 'check_suite' && github.event.check_suite.conclusion == 'failure')
55 runs-on: ubuntu-latest
56 steps:
57 - id: token
58 uses: actions/create-github-app-token@v1
59 with:
60 app-id: ${{ secrets.APP_ID }}
61 private-key: ${{ secrets.APP_PRIVATE_KEY }}
63 - id: scan
64 env:
65 GH_TOKEN: ${{ steps.token.outputs.token }}
66 REPO: ${{ github.repository }}
67 THRESHOLD: "2" # a check red on this many PRs = systemic jam
68 run: |
69 set -euo pipefail
71 # Open, non-draft PRs — drafts are works-in-progress and can't jam the
72 # merge lane.
73 prs=$(gh pr list --repo "$REPO" --state open --json number,isDraft \
74 --jq '.[] | select(.isDraft==false) | .number')
76 # (PR, failing-check) pairs, one line each, tab-separated. Dedup per PR
77 # so a check counts once per PR no matter how many contexts it reports.
78 : > fails.tsv
79 for n in $prs; do
80 gh pr view "$n" --repo "$REPO" --json statusCheckRollup --jq '
81 .statusCheckRollup[]
82 | ((.conclusion // .state)) as $c
83 | select($c=="FAILURE" or $c=="ERROR" or $c=="TIMED_OUT"
84 or $c=="STARTUP_FAILURE" or $c=="CANCELLED")
85 | (.name // .context)' 2>/dev/null | sort -u \
86 | while IFS= read -r chk; do printf '%s\t%s\n' "$n" "$chk"; done >> fails.tsv || true
87 done
89 # Most-failing check and the distinct-PR count behind it. Each check
90 # appears at most once per PR in fails.tsv, so occurrences == #PRs.
91 top=$(cut -f2 fails.tsv | sort | uniq -c | sort -rn | head -1 || true)
92 count=$(printf '%s' "$top" | awk '{print $1+0}')
93 name=$(printf '%s' "$top" | sed -E 's/^[[:space:]]*[0-9]+[[:space:]]+//')
95 jammed=false
96 affected=""
97 if [ "${count:-0}" -ge "$THRESHOLD" ]; then
98 jammed=true
99 affected=$(awk -F'\t' -v c="$name" '$2==c {print $1}' fails.tsv | sort -un | sed 's/^/#/' | paste -sd',' - | sed 's/,/, /g')
100 fi
102 echo "jammed=$jammed" >> "$GITHUB_OUTPUT"
103 echo "culprit=$name" >> "$GITHUB_OUTPUT"
104 echo "count=${count:-0}" >> "$GITHUB_OUTPUT"
105 echo "affected=$affected" >> "$GITHUB_OUTPUT"
106 echo "Scan: jammed=$jammed culprit='$name' count=${count:-0} affected='$affected'"
108 - id: escalate
109 env:
110 GH_TOKEN: ${{ steps.token.outputs.token }}
111 REPO: ${{ github.repository }}
112 JAMMED: ${{ steps.scan.outputs.jammed }}
113 CULPRIT: ${{ steps.scan.outputs.culprit }}
114 COUNT: ${{ steps.scan.outputs.count }}
115 AFFECTED: ${{ steps.scan.outputs.affected }}
116 RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
117 run: |
118 set -euo pipefail
120 # At most one open jam issue — the idempotency key.
121 existing=$(gh issue list --repo "$REPO" --label pipeline-jammed --state open \
122 --json number --jq '.[0].number // empty')
124 if [ "$JAMMED" = "true" ]; then
125 body=$(cat <<EOF
126 The pipeline is jammed: the required check **\`$CULPRIT\`** is failing on
127 **$COUNT** open PRs, so \`merge-gate\` stays red and nothing merges.
129 Affected PRs: $AFFECTED
131 This is a *systemic* failure — the same check is red across multiple
132 unrelated PRs, so it is the check (or its config), not any one branch.
133 Detector run: $RUN_URL
135 The adw-doctor has been dispatched to diagnose. This issue auto-closes
136 when a scan finds the jam cleared.
137 EOF
138 )
139 if [ -n "$existing" ]; then
140 # Already alerting — refresh the state, do NOT re-dispatch the doctor.
141 gh issue comment "$existing" --repo "$REPO" --body "Still jammed on \`$CULPRIT\` ($COUNT PRs: $AFFECTED). $RUN_URL"
142 echo "Updated existing jam issue #$existing (no re-dispatch)."
143 else
144 # Transition into jam — open the alert and wake the doctor once.
145 gh issue create --repo "$REPO" \
146 --title "Pipeline jammed: \`$CULPRIT\` failing across $COUNT PRs" \
147 --label pipeline-jammed --body "$body"
148 gh workflow run adw-doctor.yml -R "$REPO" || echo "doctor dispatch failed (non-fatal)"
149 echo "Opened jam issue and dispatched adw-doctor."
150 fi
151 else
152 if [ -n "$existing" ]; then
153 gh issue close "$existing" --repo "$REPO" \
154 --comment "Scan is clean — no required check is failing across multiple PRs. Jam resolved. $RUN_URL"
155 echo "Closed stale jam issue #$existing."
156 else
157 echo "No jam, nothing open. Quiet."
158 fi
159 fi

docs/plans/AGENTIC-DEVELOPMENT.md

Modified

+17 / −0 text lines

@@ -281,11 +281,28 @@ Unhappy paths — where each failure routes
281281| a spec claim is unproven | `planner` / `surveyor` | `/pioneer` | `needs:prototype`; a prototype proves or disproves it |
282282| a Dependabot bump is semver-incompatible / MSRV-raising | `dependency-manager` | owner | escalate as its own issue; the bump waits |
283283| the cycle floods (WIP exceeded) or an agent loops | schedule | `sweeper` | enforce WIP, brake the runaway — the circuit-breaker |
284| a required check breaks systemically — same check red on ≥2 PRs, every lane wedged | `adw-jam-detector` (failure-events + 30-min floor) | owner + `adw-doctor` | un-gated `pipeline-jammed` issue; doctor dispatched once |
285286Two invariants hold across every row: an agent never fakes a green gate to move a
286287PR (PROJECT-INVARIANTS §5), and an agent never resolves ambiguity by guessing — it
287288routes to the human via one of `needs:spec`, `risk:high`, or `needs:info`.
290The last row is the pipeline's dead-man's switch. Every gate here is
291fail-closed — a red required check holds `merge-gate` down — which is right for
292one bad PR but catastrophic when the *check itself* breaks (a green-tree CodeQL
293that finds no code and fails everywhere, a yanked action). Then no single PR is
294"wrong" and the jam is invisible from any one PR. `adw-jam-detector` watches the
295whole board: a deterministic, no-LLM scan tallies how many open non-draft PRs
296each required check is failing on, and calls a jam when one check is red on ≥2.
297It fires on failure-completions of the gating workflows for a fast edge, with a
29830-minute schedule as the deterministic floor (GitHub suppresses some
299self-triggered check events). The alert is an **issue**, not a PR — issues carry
300no merge gate, so it reaches the owner even when every merge lane is jammed — and
301it is idempotent: one open `pipeline-jammed` issue that auto-closes the moment a
302scan comes back clean. Only after a jam is confirmed, and only on the transition
303into it, is `adw-doctor` woken to diagnose — never on a steady-state re-scan, so
304the LLM can't spam.
289306## Merging — native auto-merge, gated by labels
291308Nothing needs a bespoke merge robot. The close of the loop is **GitHub's native