Skip to content

Commit 27428d8

Browse files
committed
fix(drift): the suppression ack is a receipt, so it follows the delivery instead of preceding it
`rejected_ack` is the state that silences the human-rejection notice for ever, and it was written inside the persist step — several steps BEFORE the notice POSTs. So on the first run after a closure the marker landed, the POST then failed, and every run after it read `rejected_ack=true`, stood the notice down and exited GREEN and silent: the suppression permanently un-narrated. Reached with certainty rather than by chance when the webhook has been rotated, which also kills the catch-all's POST that day, leaving nothing behind but a red cron run. The write now lives in its own step placed after the notice and gated on `steps.alert_rejected.outputs.posted == 'true'` — the same positive proof of delivery the catch-all stands down for — so the receipt cannot exist without the telling. Every failure path in it warns and exits 0, so an unrecordable ack costs one repeated ping and never a red run on a day the telling landed. The persist steps now only READ the marker. That step also scopes the write the way the marker self-healer is scoped (bot author AND a drift branch): rejection detection is body-keyed and state-blind, so a human PR that quotes or inherits the changeset marker was a full-body-rewrite target. It re-reads the PR live for the branch and author, which also stops a rewrite from the stale `--search` copy. Guards: the writer is located from the artifact, its position compared with the notice's, and its unreachability without a delivered POST settled by simulating the job with that POST failing. Mutation-tested: reverting the move, dropping the gate, defeating the gate with an extra || clause, dropping always(), rewriting instead of appending, flipping the closure precedence, deleting the idempotency check, deleting either half of the ownership test, and reddening the write-failure path all fail the suite.
1 parent 37532d4 commit 27428d8

2 files changed

Lines changed: 477 additions & 31 deletions

File tree

‎.github/workflows/fix-drift.yml‎

Lines changed: 99 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -648,25 +648,18 @@ jobs:
648648
# needs-human alert suppressed, and that must hold as long as the
649649
# rejection does. Only the POSTING is one-shot.
650650
#
651-
# FAIL OPEN: an ack that cannot be written is not recorded, so the
652-
# suppression is reported again next run — a repeat ping, never a
653-
# suppression nobody was told about. (If the POST itself then fails the
654-
# run goes red and the end-of-job catch-all reports the day, so the
655-
# window is noisy rather than silent.)
651+
# The ack is only READ here, never WRITTEN. This step runs BEFORE the
652+
# notice, so a write here recorded "already told" for a telling that
653+
# had not happened yet: the marker landed, the POST then failed, and
654+
# every later run read `rejected_ack=true`, stood the notice down and
655+
# exited GREEN and silent — the suppression permanently un-narrated.
656+
# The write is a RECEIPT and lives in "Record the suppression ack"
657+
# below, gated on that POST's own positive proof of delivery.
656658
ACK_MARKER="drift-suppression-reported: ${CHANGESET_KEY}"
657659
if printf '%s' "$REJECTED_PR" | jq -e --arg a "<!-- ${ACK_MARKER} -->" \
658660
'(.body // "") | contains($a)' >/dev/null; then
659661
echo "rejected_ack=true" >> "$GITHUB_OUTPUT"
660662
echo "ok-applied: this suppression was already reported (PR #${REJECTED} carries the ack marker) — not re-posting it"
661-
else
662-
ACK_FILE="${RUNNER_TEMP}/drift-suppression-ack-${REJECTED}.md"
663-
{
664-
printf '%s\n\n' "$(printf '%s' "$REJECTED_PR" | jq -r '.body // ""')"
665-
printf '<!-- %s -->\n' "${ACK_MARKER}"
666-
} > "$ACK_FILE"
667-
if ! ACK_ERR="$(gh pr edit "$REJECTED" --body-file "$ACK_FILE" 2>&1)"; then
668-
echo "::warning::could not record the suppression ack on PR #${REJECTED} (${ACK_ERR}) — reporting the suppression anyway; the next run tries again"
669-
fi
670663
fi
671664
exit 0
672665
fi
@@ -1230,22 +1223,14 @@ jobs:
12301223
} >> "$GITHUB_OUTPUT"
12311224
echo "needs-human: changeset ${CHANGESET_KEY} was REJECTED by a human (closed PR #${REJECTED}) — not re-proposing it"
12321225
# TOLD ONCE, NOT TOLD EVERY MORNING — see the identical block on the
1233-
# ok-applied path above for why the ack lives in the closed PR's body
1234-
# and why `rejected` is still published on every run.
1226+
# ok-applied path above for why the ack lives in the closed PR's body,
1227+
# why `rejected` is still published on every run, and why the ack is
1228+
# only READ here (the write is a receipt and follows the delivery).
12351229
ACK_MARKER="drift-suppression-reported: ${CHANGESET_KEY}"
12361230
if printf '%s' "$REJECTED_PR" | jq -e --arg a "<!-- ${ACK_MARKER} -->" \
12371231
'(.body // "") | contains($a)' >/dev/null; then
12381232
echo "rejected_ack=true" >> "$GITHUB_OUTPUT"
12391233
echo "needs-human: this suppression was already reported (PR #${REJECTED} carries the ack marker) — not re-posting it"
1240-
else
1241-
ACK_FILE="${RUNNER_TEMP}/drift-suppression-ack-${REJECTED}.md"
1242-
{
1243-
printf '%s\n\n' "$(printf '%s' "$REJECTED_PR" | jq -r '.body // ""')"
1244-
printf '<!-- %s -->\n' "${ACK_MARKER}"
1245-
} > "$ACK_FILE"
1246-
if ! ACK_ERR="$(gh pr edit "$REJECTED" --body-file "$ACK_FILE" 2>&1)"; then
1247-
echo "::warning::could not record the suppression ack on PR #${REJECTED} (${ACK_ERR}) — reporting the suppression anyway; the next run tries again"
1248-
fi
12491234
fi
12501235
# Emit it like every other early return, so the rejected PR is
12511236
# still nameable (and the "every exit names a PR" invariant holds).
@@ -1451,6 +1436,95 @@ jobs:
14511436
# POSITIVE PROOF OF DELIVERY — see the catch-all's comment below.
14521437
echo "posted=true" >> "$GITHUB_OUTPUT"
14531438
1439+
# THE RECEIPT FOLLOWS THE DELIVERY.
1440+
#
1441+
# `rejected_ack` means "a human has already been told", and the only thing
1442+
# that makes that true is the POST above returning 2xx. Written inside the
1443+
# persist step — which runs BEFORE the notice — the marker recorded the
1444+
# telling in advance: the ack landed, the POST then failed, and every run
1445+
# after it read `rejected_ack=true`, stood the notice down and exited GREEN
1446+
# and silent, leaving the suppression permanently un-narrated. Not a chance
1447+
# window: the likeliest way for this alerting to break is the webhook being
1448+
# rotated, which fails that POST with CERTAINTY — and kills the catch-all's
1449+
# POST the same day, so the run leaves behind only a red cron job, the one
1450+
# signal this workflow refuses to rely on. Gated on `posted` — the same
1451+
# positive proof the catch-all stands down for — the marker can only exist
1452+
# because the telling was delivered.
1453+
#
1454+
# FAIL OPEN ON EVERY PATH, so this step can silence nothing itself: an
1455+
# unrecordable ack costs one repeated ping tomorrow, so every giving-up path
1456+
# warns and exits 0. It posts nothing, so it is deliberately NOT in the
1457+
# catch-all's stand-down set.
1458+
- name: Record the suppression ack (the notice was DELIVERED)
1459+
id: rejected_ack
1460+
if: >-
1461+
always() &&
1462+
steps.alert_rejected.outputs.posted == 'true'
1463+
env:
1464+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
1465+
CHANGESET_KEY: ${{ steps.sync.outputs.changeset_key }}
1466+
PR_REJECTED: ${{ steps.pr.outputs.rejected }}
1467+
NH_REJECTED: ${{ steps.needs_human_pr.outputs.rejected }}
1468+
run: |
1469+
# No `-e`: a run whose telling was DELIVERED must not go red because the
1470+
# receipt could not be filed. Every failure below is handled explicitly
1471+
# and ends `exit 0`.
1472+
set -uo pipefail
1473+
# The same precedence the notice above uses to choose which closure it
1474+
# named, so the receipt lands on the PR the human was told about.
1475+
CLOSED_PR="${PR_REJECTED:-}"
1476+
[ -n "$CLOSED_PR" ] || CLOSED_PR="${NH_REJECTED:-}"
1477+
if [ -z "$CLOSED_PR" ] || [ -z "${CHANGESET_KEY:-}" ]; then
1478+
echo "::warning::the suppression notice was delivered, but the closing PR (#${CLOSED_PR:-none}) or the changeset key (${CHANGESET_KEY:-none}) is missing here, so no ack can be recorded — the notice reports the suppression again next run"
1479+
exit 0
1480+
fi
1481+
# Read the closed PR live rather than reusing the persist step's copy: the
1482+
# branch and author the scoping below needs are not in that payload, and
1483+
# that payload came from the index-backed `--search` listing this file
1484+
# elsewhere treats as lagging a body edit by minutes — so rewriting the
1485+
# body from it could silently revert a human's recent edit.
1486+
if ! PR_JSON="$(gh pr view "$CLOSED_PR" --json body,headRefName,author 2>&1)"; then
1487+
echo "::warning::could not read PR #${CLOSED_PR} to record the suppression ack (${PR_JSON}) — the notice reports the suppression again next run"
1488+
exit 0
1489+
fi
1490+
# SCOPED like the marker self-healer, because this is a WRITE into a body
1491+
# a human may own: rejection detection is body-keyed and state-blind, so a
1492+
# human PR that quotes or inherits the changeset marker is a candidate —
1493+
# and DRIFT.md asks humans to do drift work on `fix/drift-<slug>` branches.
1494+
# Bot author AND a drift branch, the same conjunction `bot_managed` uses.
1495+
# Its other arm (branch ends in a changeset key) is deliberately not
1496+
# reproduced: for a WRITE the fail-open direction is to decline any PR this
1497+
# workflow cannot prove it opened, and declining costs a repeated ping.
1498+
BRANCH="$(printf '%s' "$PR_JSON" | jq -r '.headRefName // ""')"
1499+
AUTHOR="$(printf '%s' "$PR_JSON" | jq -r '(.author.login // "") | ascii_downcase')"
1500+
DRIFT_BRANCH=no
1501+
case "$BRANCH" in fix/drift-*|drift-needs-human/*) DRIFT_BRANCH=yes ;; esac
1502+
if [ "$DRIFT_BRANCH" != yes ] || [ "$AUTHOR" != "app/copilotkit-devops-bot" ]; then
1503+
echo "::warning::PR #${CLOSED_PR} is not a PR this workflow opened (branch '${BRANCH}', author '${AUTHOR}'), so its body is not machine state to append to — no ack recorded, and the notice reports the suppression again next run"
1504+
exit 0
1505+
fi
1506+
ACK_MARKER="drift-suppression-reported: ${CHANGESET_KEY}"
1507+
# An intact ack is left BYTE-IDENTICAL — no edit, no API write, no
1508+
# appending ratchet. Reachable whenever the persist step's `--search`
1509+
# copy of the body was the stale one.
1510+
if printf '%s' "$PR_JSON" | jq -e --arg a "<!-- ${ACK_MARKER} -->" \
1511+
'(.body // "") | contains($a)' >/dev/null 2>&1; then
1512+
echo "PR #${CLOSED_PR} already carries the suppression ack — nothing to record"
1513+
exit 0
1514+
fi
1515+
ACK_FILE="${RUNNER_TEMP}/drift-suppression-ack-${CLOSED_PR}.md"
1516+
# APPEND-ONLY: the existing body, human prose and changeset marker alike,
1517+
# is copied through verbatim and only the ack line is added after it.
1518+
{
1519+
printf '%s\n\n' "$(printf '%s' "$PR_JSON" | jq -r '.body // ""')"
1520+
printf '<!-- %s -->\n' "${ACK_MARKER}"
1521+
} > "$ACK_FILE"
1522+
if ! ACK_ERR="$(gh pr edit "$CLOSED_PR" --body-file "$ACK_FILE" 2>&1)"; then
1523+
echo "::warning::could not record the suppression ack on PR #${CLOSED_PR} (${ACK_ERR}) — the notice reports the suppression again next run and tries again"
1524+
exit 0
1525+
fi
1526+
echo "recorded the suppression ack on PR #${CLOSED_PR} — the delivered notice is not re-posted"
1527+
14541528
# Alert: the sync found a genuinely-new family or a still-referenced
14551529
# deprecation — the two irreducible human decisions (see
14561530
# self-healing-drift-plan.md "Bucket B"). The needs-human note was

0 commit comments

Comments
 (0)