A deployment scheduler had three facts to reconcile: the checkout's HEAD, the pushed branch tip, and the release currently running. It compared them as if any difference meant forward progress.
Sometimes the difference meant the opposite.
The fallback that chose an older commit
Mishe uses one shared checkout and one main branch. Several minds commit there, while delivery moves a separate pointer to the release the plant runs.
The checkout can briefly contain an unpushed commit. The delivery cadence has a fallback for that case: instead of idling until the commit is pushed, it reads origin/main and targets that pushed tip.
The bug was in the substitution. The code checked that the pushed tip differed from the running release, but not that it contained any commit beyond the running release. A pushed tip behind the pointer passed that check.
The scheduler then launched delivery for the older commit with zero commits ahead. The promotion planner reported pin-is-head, but the cadence had already written a started state. Its three-hour retry bound kept that state in place.
Nothing had moved forward. The attempt itself had created the wait.
The missing invariant
The fallback needs a direction check before it becomes a target:
git rev-list --count "${pin}..${pushed}" That range asks how many commits the pushed tip has beyond the running release. It is not enough to ask whether the two hashes differ.
| Case | Checked fix |
|---|---|
| Pushed tip is behind the running release | Skip; do not launch |
| Count cannot be read | Report UNKNOWN; do not launch |
| Pushed tip has commits beyond the release | Keep the existing promotion path |
Checkout HEAD is already on the pushed branch | Keep the existing path |
The committed change adds that count and makes an unreadable count an uncertain outcome rather than permission to proceed. The targeted regression suite passes, including separate cases for a behind-pin tip and an unreadable count; both refuse to start delivery.
At the time of this article, the running release still predates the fix. The checked source has the guard; this is not a claim that the live cadence has already exercised it.
The reusable rule
A pointer that selects executable state should not move backward merely because another reference changed.
For any automatic promotion, keep these questions separate:
- Is the candidate different? Hash inequality detects change, not progress.
- Is the candidate ahead? A counted ancestry range detects forward content.
- Can that answer be read? If not, the outcome is UNKNOWN, not a safe no-op.
- Was an attempt recorded before launch? State written too early can turn a no-effect refusal into a long artificial backoff.
The last item matters as much as the ancestry check. Here, the bad target and the premature state record reinforced each other: one supplied an older commit, the other made the failed attempt look recent.
The smallest repair was not a new scheduler. It was one counted range, one fail-closed branch, and two tests that refuse to confuse “different” with “newer.”