Skip to content

🐛 fix(ci): guard changelog-sync against demoting a released section - #285

Merged
konih merged 1 commit into
mainfrom
fix/changelog-sync-release-guard
Aug 8, 2026
Merged

konih merged 1 commit into
mainfrom
fix/changelog-sync-release-guard

Conversation

@konih

@konih konih commented Aug 7, 2026 •

Copy link
Copy Markdown
Collaborator

Incident

Bot commit fbb5196a3 (:page_facing_up: docs: sync CHANGELOG.md [skip ci]) rewrote

-## [0.17.0](https://github.com/platformrelay/kollect/compare/v0.16.0..v0.17.0) - 2026-08-05
+## [Unreleased]

That is the exact inverse of the human release-cut commit aa9118919 (:memo: docs(changelog): cut v0.17.0 release notes). docs/_snippets launch-truth then resolved the released version as 0.16.0, and Docs CI went red on every open PR until it was patched by hand in #283. The symptom was fixed; the mechanism was not.

Diagnosed mechanism — tag-push race (established, not guessed)

event UTC
release-prep commits land on main (3815a3bd8) → triggers changelog-sync 17:56:13
bot pushes the demotion (fbb5196a3) 17:56:36
annotated tag v0.17.0 created/pushed 18:04:16

docs/RELEASE.md lands the release-prep PR on main first and pushes vX.Y.Z afterwards. changelog-sync fires on that push, checks out a HEAD where the tag does not exist yet, and git-cliff correctly classifies those commits as unreleased — rendering ## [Unreleased] over the hand-written header. Eight minutes later the tag arrives, but a tag push does not re-trigger on: push: branches: [main], so nothing re-heals it.

Confirmed by reproduction: git-cliff --config hack/release/cliff.toml in this worktree (tag now present) emits ## [0.17.0](…) - 2026-08-05. The config is not at fault — cliff.toml and task changelog:write are unchanged here.

This is structural, not a one-off: every release takes this path.

Why the guard is not "compare against existing git tags"

The obvious check — "a header matching an existing tag must not disappear" — would have caught nothing, because at sync time the tag did not exist. The load-bearing invariant is old-vs-new: a released section present in the committed CHANGELOG must not vanish from the regenerated one. Tag visibility is used only as a discriminator, not as the invariant.

The guard

hack/check-changelog-release-guard.sh <committed> <regenerated>, run in changelog-sync.yaml before anything is committed or pushed:

situation exit behaviour
no released section lost 0 commit & push (normal self-healing, unchanged)
top section demoted to [Unreleased], its tag not visible 2 ::warning, no push, job green — release in flight
any other released section disappears (tag visible, or non-top, or several) 1 ::error, job fails, nothing pushed
usage error 3 fails

Design notes:

  • It must not over-fire. The demotion is the normal release path, so failing on it would red every release and recreate the alarm fatigue this is meant to prevent. Hence exit 2 = refuse-to-push-and-stay-green.
  • Version tokens are compared as sets, never whole header lines — the date and compare link legitimately change on re-render. Prerelease tokens (0.18.0-rc.1, matching tag_pattern = "v[0-9].*") are handled.
  • [Unreleased] drift-healing is untouched — the guard only inspects ## [X.Y.Z] tokens, so the workflow's actual purpose still works.

Replayed against the real incident blobs

# under the original conditions (v0.17.0 tag not pushed yet)
exit 2 — ::warning "Release v0.17.0 appears to be in flight … Refusing to push that demotion"

# with the tag visible (a genuine regression)
exit 1 — ::error "Regenerated CHANGELOG.md drops released section(s): 0.17.0"

Either way the bad push is blocked.

Convergence caveat (deliberate scope choice)

After an exit-2 refusal, CHANGELOG.md stays as committed (which is correct — the hand-written header is the truth) and is regenerated by the next push to main after the tag lands. Adding tags: to the workflow trigger would heal it within seconds, but on a tag event actions/checkout resolves the tag ref and git push origin HEAD:main would then target a non-main commit; doing it safely needs an explicit ref: main and cannot be verified locally. Adding an untestable push path to main in the very lane that exists to stop bad bot pushes is the wrong trade — noted here as a follow-up rather than smuggled in.

Testing (TDD)

hack/test/changelog_sync_release_guard_test.sh — offline, fixture CHANGELOGs plus throwaway git repos whose tag sets are controlled by which repo the guard runs in (no test-only backdoor in the production script). No release needs to be cut to exercise it. Written first, confirmed red (FAIL: missing hack/check-changelog-release-guard.sh), then made green.

21 checks, covering both directions:

  • must not over-fire: identical files; [Unreleased] body re-render; no [Unreleased] section at all (the file's current state — all post-tag commits are cliff-skipped docs); gaining an [Unreleased] section; a newly rendered release header; changed date/compare-link on an intact release
  • refuse (2): top release demoted with tag absent; same for a -rc.1 prerelease; refusal names the pending tag and emits ::warning
  • fatal (1): top demoted while tag is visible; prerelease equivalent; dropped middle section (with and without its tag); top demotion plus a dropped middle (fatal wins over refusal); every release section wiped; emits ::error
  • usage (3): missing args; unreadable inputs — must not silently pass

Wired into the ci.yaml lint job next to core_events_rbac_test.sh.

Structural assertions (mutation-tested)

The test also locks the workflow wiring. These deliberately parse the YAML (python3 + yaml, the core_events_rbac_test.sh pattern) rather than grepping lines — the header comment also contains the script path, so a line-based grep/head -1 check would match the comment and pass even with the guard step deleted or moved after the push. It asserts, within jobs.sync.steps:

  1. some step's run invokes check-changelog-release-guard.sh;
  2. its index is lower than the step running git push origin HEAD:main;
  3. the push step's if: references steps.<guard-id>.outputs — a verdict nobody consumes is not a guard.

Each was mutation-tested against the real workflow to confirm it is not vacuous:

mutation result
drop if: steps.guard.outputs.verdict == 'push' ✅ fails
move the guard step after the push step ✅ fails (guard step (index 5) must run BEFORE the push step (index 4))
delete the guard step entirely ✅ fails (no step in job 'sync' runs check-changelog-release-guard.sh)

Both new scripts are committed 100755, matching their siblings.

Documentation

The workflow header comment previously said the job "soft-fails with a warning (it is NOT a required check, so it never blocks a merge)" — now false in one branch. Rather than appending, that paragraph is rewritten to state which conditions soft-fail (missing App-token secrets / push failure — unchanged) and which are now fatal, and it documents the release-guard verdicts and the convergence caveat. No documented caveat was dropped: the App-token activation notes, the ruleset-bypass setup, and the paths-ignore / [skip ci] loop guards are all retained verbatim.

No CHANGELOG entry in this PR — verified, not assumed

cliff.toml evaluates commit_parsers in order and ^fix precedes ^(test|chore|ci|build|style), so fix(ci): lands under Bug Fixes, not skipped (cf. existing - **ci:** Drop doomed changelog:verify from preflight (#139)). It is still not hand-written here: the entry needs the post-squash SHA, which is unknowable pre-merge — that is precisely why changelog-sync exists and why changelog:verify was removed from preflight in #139. The (now guarded) sync will add it.

Gates

  • task lint:shell (shellcheck 0.11.0, --severity=warning) — clean
  • hack/test/changelog_sync_release_guard_test.sh — 19/19 pass
  • actionlint — changelog-sync.yaml clean; the one ci.yaml SC2129 style note is pre-existing on main (unrelated "Job summary" step, shifted two lines by this diff)
  • python3 -c "import yaml; yaml.safe_load(...)" on both workflows — ok
  • hack/scrub.sh — ok
  • YAML/shell-only lane; no Go touched, so the Go gate matrix was not run

changelog-sync regenerated CHANGELOG.md from a HEAD where the release tag was
not pushed yet, so git-cliff rendered the cut section as [Unreleased] and bot
commit fbb5196 pushed that demotion of ## [0.17.0] to main. docs launch-truth
then resolved the released version as 0.16.0 and Docs CI went red on every PR.

Diff every regeneration against the committed CHANGELOG.md before pushing.
Released version tokens are compared as sets, so dates and compare links may
change freely. Tag visibility discriminates the ordinary release path (top
section demoted, tag not pushed yet -> warn and refuse to push, job green) from
a real regression (tag visible, or a non-top section vanished -> error, fail,
push nothing). [Unreleased] drift-healing is untouched.
@konih
konih force-pushed the fix/changelog-sync-release-guard branch from 034062f to 15d32ea Compare August 7, 2026 08:18
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

@konih

konih commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

REVIEW — Kollect/fix-changelog-sync-release-guard @ 15d32ea — APPROVE — 2026-08-07

Verdict: APPROVE (P2/P3 notes only, none blocking)

Independent review; I did not write this code and verified the author's claims rather than accepting them.

Gate matrix

Gate Result Notes
hack/test/changelog_sync_release_guard_test.sh ✅ 21/21 checks (PR body's Gates line says 19/19 — stale)
Mutation testing (6 independent) ✅ all caught — see below
Guard replayed vs. real incident blobs ✅ exit 2 (tag absent) / exit 1 (tag visible), as claimed
End-to-end incident reproduction ✅ byte-identical to fbb5196a3
Live over-fire check on current HEAD ✅ regenerated ≠ committed, guard exit 0
Shell robustness probes ✅ CRLF, empty files, no ## [ headers, no trailing newline, non-git cwd, tokens with spaces
task lint:shell / actionlint / yaml.safe_load / scrub ✅ trusted from lane report; ci.yaml SC2129 confirmed pre-existing
Go gate matrix n/a YAML/shell-only lane, no Go touched

Diagnosis — verified, and more strongly than claimed

  • Timestamps hold. aa9118919 17:56:13Z → bot fbb5196a3 17:56:36Z (+23s) → annotated tag v0.17.0 tagger date 18:04:16Z, 8 minutes later.
  • Exact-inverse confirmed at blob level, not just visually: the human cut moved CHANGELOG.md f34ed8308→ec9223a42; the bot moved it ec9223a42→f34ed8308. The same two blobs, swapped.
  • End-to-end reproduction. I reconstructed the runner: checked out 3815a3bd8, deleted the v0.17.0 tag, ran git-cliff --config hack/release/cliff.toml -o CHANGELOG.md. Output is byte-identical to fbb5196a3's CHANGELOG.md. The cause is the missing tag; cliff.toml is exonerated.
  • Structural, not a one-off — docs/RELEASE.md:190 lands the prep PR first, :204-205 pushes the tag afterwards. Every release takes this path.
  • The invariant choice is right. A tag-based check would have been vacuous: at sync time refs/tags/v0.17.0 did not exist, so "a header matching an existing tag must not vanish" is trivially true. Old-vs-new is the correct load-bearing invariant, with tag visibility as discriminator only.

Mutation testing — 6/6 caught, suite is not vacuous

I re-ran the author's three and added three more. For the workflow mutations I re-prepended the original header comment so the separate grep 'release guard' assertion still passed and the failure was isolated to the structural check.

# Mutation Result
1 delete the guard step ✅ fails — no step in job 'sync' runs check-changelog-release-guard.sh
2 move the guard step after the push ✅ fails — guard step (index 5) must run BEFORE the push step (index 4)
3 drop if: steps.guard.outputs.verdict == 'push' ✅ fails — push step must be gated on the guard verdict
4 neuter the guard script to exit 0 ✅ fails — 13 FAILs
5 replace the tag discriminator with true ✅ fails — want exit 1, got 2 on both tag-visible cases
6 relax the "exactly one missing AND top section" constraint ✅ fails — top-demotion-plus-dropped-middle and wipe-everything both degrade to a refusal

The previously-vacuous grep | head -1 problem is genuinely fixed — it now parses jobs.sync.steps and asserts guard-index < push-index plus steps.<guard-id>.outputs in the push step's if:.

Exit 2 — the risky path, examined

It is monotonically safer than the status quo: its worst case is "no push", never "wrong push". Convergence is proven, not asserted — with the tag restored at the same HEAD, cliff's output byte-matches the hand-written committed file, so the guard returns 0 and the next push to main heals cleanly. The only way a hold persists is an aborted release leaving an untagged hand-written header, and that re-emits the tag-naming ::warning on every push to main, so it is loud rather than silent (P3 below).

Over-fire — disproven on real data

On the repo's actual current HEAD the regenerated file differs from the committed one and the guard still exits 0 (all 25 released section(s) survived). [Unreleased] drift-healing is untouched, as claimed. task changelog:write regenerates the whole file (git-cliff -o CHANGELOG.md, no --latest/--prepend), so whole-file set comparison is the correct semantics.

Other verifications

  • fetch-depth: 0 + fetch-tags: true on the checkout — the tag discriminator is real, not always-false.
  • Fail-closed wiring: a missing/erroring guard script yields 127 → *) exit 1 → job red, push skipped (verdict unset). Correct direction.
  • No annotation/output injection: only literal push/hold/in-sync reach $GITHUB_OUTPUT; version tokens reach :: annotations only mid-line via %s (never as a format string), and sed is line-based so a token cannot contain a newline to start a new workflow command.
  • Header comment rewrite is honest — diffing comment lines old vs new, the only pre-existing edit is this job soft-fails → the push step soft-fails, which corrects a sentence the fatal path would have made false. App-token activation, ruleset bypass, and paths-ignore/[skip ci] loop guards are all retained verbatim. Nothing dropped.
  • Regression lock actually runs: the lint job has no if:/needs:, and ci.yaml's paths-ignore excludes neither hack/** nor .github/workflows/**.
  • No CHANGELOG entry needed — confirmed cliff.toml:60 ^fix precedes :71 ^(test|chore|ci|build|style), so fix(ci): lands under Bug Fixes. The author's reasoning checks out.
  • Conventions: both scripts are 100755, carry SPDX and set -euo pipefail (134/145 hack/*.sh use the latter). agent-context/GUIDELINES.md defines no shell-script rules, so precedent governs and both conform.

Findings

ID Sev Area Finding Evidence Blocks?
1 P2 Docs The runbook that encodes the very ordering at fault is not updated. Every release will now produce a changelog-sync run that warns and declines to push — expected and green, but the operator has no in-repo note saying so; it lives only in the workflow header comment. ADR-0705 (owns git-cliff/tag-driven releases, names changelog-sync explicitly) is likewise untouched. No-ADR is defensible — this is a defensive CI mechanism, not a reversal of 0705 — but two lines in RELEASE.md are warranted. docs/RELEASE.md:190,204-205; docs/adr/0705-release-supply-chain.md No
2 P3 Robustness Fail-open on a readable-but-not-a-file input: [[ -r ]] passes for a directory and mapfile < <(headers …) swallows sed's error (errexit does not apply inside process substitution), yielding empty sets and exit 0. Verified: guard /tmp /tmp/empty → 0. Not reachable from the workflow's two fixed paths. hack/check-changelog-release-guard.sh:41-46,59-60 No
3 P3 Robustness Discriminator hardcodes the v prefix. Correct today and consistent with cliff.toml:50 tag_pattern = "v[0-9].*", but a scheme change would silently route genuine regressions to the lenient exit-2 path. Safe direction; worth a comment tying it to tag_pattern. hack/check-changelog-release-guard.sh:100 No
4 P3 Design An aborted release (header committed, tag never pushed) parks the workflow in exit-2 hold indefinitely, suspending drift-healing. Mitigated: the named ::warning re-fires on every push to main. hack/check-changelog-release-guard.sh:99-102 No
5 P3 Docs PR body Gates says 19/19 pass; the suite emits 21 checks (the Testing section correctly says 21). PR body No
6 P3 Scope The tags:-trigger omission is documented honestly and with sound reasoning, which meets the scope-honesty bar — but a PR body is not durable in-repo after squash-merge and no follow-up issue is linked. Suggest filing one. PR body, "Convergence caveat" No

Functional correctness

All stated acceptance criteria hold under independent replay. The guard blocks the real incident (exit 2, green), escalates the genuine-regression variant (exit 1, red), converges once the tag lands (exit 0, byte-exact), and does not over-fire on the repo's live state. The exit-code contract in the script header, the workflow header comment, and the PR body agree with observed behaviour.

TDD / coverage delta

No Go coverage surface. New production unit hack/check-changelog-release-guard.sh goes 0 → 21 behavioural checks, wired into CI's lint job. Tests exercise behaviour, not tautology: neutering the script produces 13 failures and each of two logic mutations produces targeted failures. No zero-coverage new production code.

Summary / next steps

APPROVE — clear to merge (maintainer merges; this review does not authorize it). Recommended non-blocking follow-ups: a short note in docs/RELEASE.md telling the release operator the changelog-sync warning is expected (Finding 1), and a tracked issue for the tags:-trigger convergence gap (Finding 6). Findings 2-5 are hardening/nit notes.

@konih
konih merged commit a5fdd3d into main Aug 8, 2026
31 checks passed
@konih
konih deleted the fix/changelog-sync-release-guard branch August 8, 2026 10:48
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.

1 participant