repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

Make the dead-man switch count active failures (#77)

594a4879af448cc2cf3432a2b12aafe796ab8b15

agent-smith-bugabinga-adc[bot] <306488075+agent-smith-bugabinga-adc[bot]@users.noreply.github.com> ·

SSH signature · not checked

Browse filesCompare with HEAD

## What forced this
An intentional red `merge-gate` and stale failed attempts were diagnosed
as current systemic outages, spawning 15 duplicate alerts and cancelling
15 doctor runs in 45 minutes.

## The call
Define a jam as the same active, unexpected failure across PRs: reduce
each check context to its latest attempt, and count `merge-gate` only
when its labels require green.

## What we deliberately did not do
Do not raise the two-PR threshold; that delays real alarms while
preserving the misclassification.

## Evidence
[Detector run
29993708661](https://github.com/bugabinga/smith/actions/runs/29993708661)
reported `merge-gate` red on three PRs after PR #65 had a newer green
attempt; replaying the corrected rule leaves only two different
single-PR reviewer failures.

## Surface touched
Three ADW jam-definition surfaces, anchored at
`.github/workflows/adw-jam-detector.yml`.

## If this ages badly
If a proven active cross-PR failure is hidden by normalization, replace
the latest-attempt selector while retaining the expected-red filter.

---------

Co-authored-by: agent-smith-bugabinga-adc[bot] <agent-smith-bugabinga-adc[bot]@users.noreply.github.com>
Co-authored-by: Oliver Jan Krylow <oliver@bugabinga.net>
Co-authored-by: Claude <noreply@anthropic.com>

Changed files (3)

+127 / −37 text lines

Diff layout

.github/labels.yml

Modified

+1 / −1 text lines

9393# — housekeeping —
9494- name: "pipeline-jammed"
9595 color: "9b1c1c"
96 description: "A required check is failing across ≥2 PRs — merges are wedged; jam-detector opened this"
96 description: "A merge-critical check is unexpectedly failing across ≥2 PRs; jam-detector opened this"
9797- name: "blocked"
9898 color: "b5179e"
9999 description: "Waiting on another issue — usually a needs:spec escalation"

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

Modified

+98 / −20 text lines

11# 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.
2# fail-closed by design: an unexpected failure in the required merge-gate is
3# correct for ONE bad PR but catastrophic when the break is systemic. Then
4# nothing merges and no single PR is "wrong" — the jam is invisible from any
5# one PR's vantage. This job watches the whole board and rings a bell.
76#
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
7# Deterministic, no LLM: a shell/jq scan reduces each check name to its latest
8# run, then tallies how many distinct open non-draft PRs carry an active
9# `merge-gate` failure. Red is its normal waiting/held state, so it counts only
10# when the verdict/blocking labels say it should be green and the gate attempt
11# started after the last gate-relevant label transition. Same unexpected failure
12# on >= 2 PRs = a systemic jam, not one bad branch. It is the only check tallied,
13# because the ruleset makes it the sole required one — anything that genuinely
14# blocks a merge lands as a red gate. The LLM (adw-doctor) is dispatched only
1115# AFTER a jam is confirmed, and only on the transition into jam — never on a
1216# steady-state re-scan, so it can't spam.
1620# idempotent (one open `pipeline-jammed` issue at a time) and auto-closes the
1721# instant a scan comes back clean.
19# Triggers: failure-completions of the gating workflows and check-suites give a
23# Triggers: failure-completions of the gate workflow and check-suites give a
2024# fast edge (seconds after the break), and a 30-minute schedule is the
2125# deterministic floor — GitHub suppresses some self-triggered check events, so
2226# the cron is what guarantees the jam is caught even if every edge is missed.
2529on:
2630 workflow_run:
27 workflows: ["adw-review", "adw-gate", "adw-build", "CodeQL Advanced", "DevSkim"]
31 workflows: ["adw-review", "adw-gate", "adw-build"]
2832 types: [completed]
2933 check_suite:
3034 types: [completed]
7377 prs=$(gh pr list --repo "$REPO" --state open --json number,isDraft \
7478 --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.
80 # (PR, actively-failing-check) pairs, one line each, tab-separated.
81 # statusCheckRollup retains older attempts after a re-run, so reduce
82 # each check name to its latest start before deciding its state.
83 # Legacy StatusContext entries provide createdAt instead of CheckRun
84 # times.
85 #
86 # merge-gate is deliberately red while verdicts are missing or a
87 # blocking label holds the PR. Count it only when both verdicts are
88 # in, no blocker remains, and the attempt began after the last label
89 # transition that adw-gate reads. This rejects the ordinary red
90 # attempt that a label change supersedes before its gate run appears,
91 # without treating comments or unrelated labels as a fresh PR state.
7892 : > fails.tsv
93 required_gate_labels=(reviewed security-cleared)
94 blocking_gate_labels=(risk:high blocked changes-requested needs:info needs:spec needs:prototype stalled)
96 has_label() {
97 case $'\n'"$1"$'\n' in *$'\n'"$2"$'\n'*) return 0 ;; esac
98 return 1
99 }
101 is_gate_label() {
102 local label=$1
103 local gate_label
104 for gate_label in "${required_gate_labels[@]}" "${blocking_gate_labels[@]}"; do
105 [ "$label" = "$gate_label" ] && return 0
106 done
107 return 1
108 }
110 gate_should_be_green() {
111 local labels=$1
112 local gate_label
113 for gate_label in "${required_gate_labels[@]}"; do
114 has_label "$labels" "$gate_label" || return 1
115 done
116 for gate_label in "${blocking_gate_labels[@]}"; do
117 has_label "$labels" "$gate_label" && return 1
118 done
119 return 0
120 }
122 last_gate_label_transition() {
123 gh api --paginate "repos/$REPO/issues/$1/events" \
124 --jq '.[] | select(.event == "labeled" or .event == "unlabeled") | [.label.name, .created_at] | @tsv' \
125 | while IFS=$'\t' read -r label changed_at; do
126 if is_gate_label "$label"; then
127 printf '%s\n' "$changed_at"
128 fi
129 done \
130 | sort \
131 | tail -n 1
132 }
79134 for n in $prs; do
80 gh pr view "$n" --repo "$REPO" --json statusCheckRollup --jq '
81 .statusCheckRollup[]
135 pr=$(gh pr view "$n" --repo "$REPO" --json labels,statusCheckRollup)
136 labels=$(printf '%s' "$pr" | jq -r '.labels[].name')
138 if ! gate_should_be_green "$labels"; then
139 continue
140 fi
142 gate_label_transition=$(last_gate_label_transition "$n")
143 if [ -z "$gate_label_transition" ]; then
144 continue
145 fi
147 printf '%s' "$pr" | jq -r --arg gate_label_transition "$gate_label_transition" '
148 ((.statusCheckRollup // [])
149 | group_by(.name // .context)
150 | map(
151 max_by(.startedAt // .completedAt // .createdAt // "")
152 )[])
153 | (.startedAt // .completedAt // .createdAt // "") as $attempt_at
82154 | ((.conclusion // .state)) as $c
83155 | select($c=="FAILURE" or $c=="ERROR" or $c=="TIMED_OUT"
84156 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
157 | (.name // .context) as $check
158 | select(
159 $check == "merge-gate"
160 and $attempt_at >= $gate_label_transition
161 )
162 | $check' | sort -u \
163 | while IFS= read -r chk; do printf '%s\t%s\n' "$n" "$chk"; done >> fails.tsv
87164 done
89166 # Most-failing check and the distinct-PR count behind it. Each check
124201 if [ "$JAMMED" = "true" ]; then
125202 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.
203 The pipeline is jammed: the merge-critical check **\`$CULPRIT\`** has an
204 active, unexpected failure on **$COUNT** open PRs, so merges may be wedged.
129206 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.
208 This is a *systemic* failure — the same current check attempt is red
209 across multiple unrelated PRs, so it is the check (or its config), not
210 any one branch.
133211 Detector run: $RUN_URL
135213 The adw-doctor has been dispatched to diagnose. This issue auto-closes

docs/plans/AGENTIC-DEVELOPMENT.md

Modified

+28 / −16 text lines

287287| a spec claim is unproven | `planner` / `surveyor` | `/pioneer` | `needs:prototype`; a prototype proves or disproves it |
288288| a Dependabot bump is semver-incompatible / MSRV-raising | `dependency-manager` | owner | escalate as its own issue; the bump waits |
289289| the cycle floods (WIP exceeded) or an agent loops | schedule | `sweeper` | enforce WIP, brake the runaway — the circuit-breaker |
290| 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 |
290| the merge gate breaks systemically — unexpected active `merge-gate` red on ≥2 PRs | `adw-jam-detector` (failure-events + 30-min floor) | owner + `adw-doctor` | un-gated `pipeline-jammed` issue; doctor dispatched once |
292292Two invariants hold across every row: an agent never fakes a green gate to move a
293293PR (PROJECT-INVARIANTS §5), and an agent never resolves ambiguity by guessing — it
294294routes to the human via one of `needs:spec`, `risk:high`, or `needs:info`.
296The last row is the pipeline's dead-man's switch. Every gate here is
297fail-closed — a red required check holds `merge-gate` down — which is right for
298one bad PR but catastrophic when the *check itself* breaks (a green-tree CodeQL
299that finds no code and fails everywhere, a yanked action). Then no single PR is
300"wrong" and the jam is invisible from any one PR. `adw-jam-detector` watches the
301whole board: a deterministic, no-LLM scan tallies how many open non-draft PRs
302each required check is failing on, and calls a jam when one check is red on ≥2.
303It fires on failure-completions of the gating workflows for a fast edge, with a
30430-minute schedule as the deterministic floor (GitHub suppresses some
305self-triggered check events). The alert is an **issue**, not a PR — issues carry
306no merge gate, so it reaches the owner even when every merge lane is jammed — and
307it is idempotent: one open `pipeline-jammed` issue that auto-closes the moment a
308scan comes back clean. Only after a jam is confirmed, and only on the transition
309into it, is `adw-doctor` woken to diagnose — never on a steady-state re-scan, so
310the LLM can't spam.
296The last row is the pipeline's dead-man's switch. The ruleset names `merge-gate`
297as the sole required check, which makes it the sole way the whole board can
298seize: fail-closed is right for one bad PR and catastrophic when the gate
299*itself* breaks — a yanked action, an expired App token, a bad edit to
300`adw-gate.yml`. Then no single PR is "wrong" and the jam is invisible from any
301one PR. `adw-jam-detector` watches the whole board: a deterministic, no-LLM scan
302reduces each check name to its latest run, then tallies active `merge-gate`
303failures across open non-draft PRs. An ordinary red gate is control state, not
304illness: while a verdict is missing or a blocking label is present, it is
305supposed to fail. The detector therefore counts a red gate only when both
306verdict labels are present and no blocking label remains. An unexpected gate red
307on ≥2 PRs is a jam.
309Two failure classes sit deliberately outside its reach, because neither is a
310jam. A reviewer that never returns a verdict leaves the gate *legitimately* red;
311that is a stall, and the row above it is the sweeper's. An advisory red — CodeQL,
312DevSkim — blocks no merge and is never tallied; if one of those should hold a PR
313down, the fix is to make it a required check, not to widen the detector.
315The scan fires on failure-completions of the gating workflows for a fast edge,
316with a 30-minute schedule as the deterministic floor (GitHub suppresses some
317self-triggered check events). The alert is an **issue**,
318not a PR — issues carry no merge gate, so it reaches the owner even when every
319merge lane is jammed — and it is idempotent: one open `pipeline-jammed` issue
320that auto-closes the moment a scan comes back clean. Only after a jam is
321confirmed, and only on the transition into it, is `adw-doctor` woken to diagnose
322— never on a steady-state re-scan, so the LLM can't spam.
312324## Merging — native auto-merge, gated by labels