Research note · November 2026
A bug that costs nothing, and why I reported it anyway
An iterator returns the instant the caller already has. Its mirror skips one entirely. Both reproduce in a few lines. And as far as I can tell, neither costs anyone a cent, because the only consumer happens to be idempotent. That gap between "broken" and "expensive" is the whole point of this note.
The behaviour
A monthly recurrence with its anchor after the query time, so the backwards loop runs:
r, _ := NewRecurrence(RecurrencePeriodMonth, parse("2024-06-01T00:00:00Z"))
it, _ := r.IterateFromNextAfter(parse("2024-03-15T00:00:00Z"), Exclusive)
gives
it.At = 2024-04-01T00:00:00Z
Next()^1 .At = 2024-04-01T00:00:00Z <- the same instant, again
Next()^2 .At = 2024-05-01T00:00:00Z
The mirror, IterateFromPrevBefore with a past anchor, skips instead of repeating: 2024-03-01 then 2024-05-01, with April never produced.
A control run with the anchor in the past, which does not enter the backwards loop, is clean: 04-01, 05-01, 06-01. That control is what makes the finding a finding. Without it, the failure could as easily have been the date arithmetic, and I would have reported the wrong thing.
The cause
In pkg/timeutil/recurrence.go the loop decrements its index, computes the next candidate, and breaks before assigning it:
ic -= 1
v, err := r.addIntervalNTimes(r.Anchor, ic)
if err != nil {
return RecurrenceIterator{}, err
}
if v.Before(t) {
break
}
res = v
So on the breaking pass the index has moved and the value has not. The struct returned then pairs them anyway, carrying iteration: ic alongside a res that belongs to ic+1. Next() recomputes the timestamp from the index, trusts it, and hands back the instant the caller is already holding.
One logical value, the position in the recurrence, held two ways: as an integer index and as a materialised time. They agree everywhere except the one path where the loop exits early.
Why it costs nothing
There is exactly one non-test caller, in the credit engine's grant handling, and IterateFromPrevBefore has none at all. The duplicated instant is collapsed by a dedupe-by-time a few lines later. The grant ID does end up in one slice twice, but the function that consumes it returns the grant's amount unconditionally, so applying it twice lands the same number as applying it once.
I looked for a balance error and could not produce one. The issue says so in those words.
So why file it
Three reasons, and the ordering matters.
The mirror case has no callers yet. That is not safety, it is a loaded gun with the safety on. The repeating variant is absorbed by a dedupe that happens to exist. The skipping variant has nothing in front of it, so the first caller to use IterateFromPrevBefore inherits a silently missing occurrence, and a missing recurrence in a credit engine is a real number.
The contract is indefensible on its own terms. An iterator whose Next() returns its current value is not a semantic anyone would choose. There is no competing interpretation a maintainer could offer in one sentence, which is the test I apply before filing anything. When such a sentence exists, the right artefact is a question, not a bug report.
The input is ordinary. Nothing stops a grant from recurring monthly on the first while being effective mid-month. That is a normal configuration, and it lands on the broken path.
The part that is easy to get wrong
The temptation with a finding like this is to make it sound expensive, because expensive findings get attention. The write-up practically offers to do it for you: a billing engine, a credit balance, a skipped recurrence.
But asserting a money impact I could not reproduce would be the same defect I was reporting. A value carried further than the evidence supports it. So the issue states plainly that no balance error was found, and explains why the thing is worth fixing regardless.
That sentence is also what makes the rest of the report credible. A reader who sees a researcher mark their own finding as harmless has reason to believe them when a later one is not.
Status
Issue #5521 is open and has had no maintainer response. It may be declined, and the reasoning above is the whole of the case for it.
Three earlier findings in the same engine were merged in October. Those are written up here.
Back to Nobulex →
