Two helpers that disagreed by a day
The scheduler asks two questions each minute: is today one of this campaign's dates, and is now its trigger time. They are answered by two helpers that both claim to work in India Standard Time.
The time helper built a date from the current instant and read back its local fields. Correct. The date helper built the same thing and then read it back through toISOString(), which reports UTC fields. India is five and a half hours ahead, so for any wall-clock time before 05:30 the UTC date is still yesterday.
So between midnight and 05:29 the two helpers described different days. The date check compared the campaign's scheduled dates against yesterday, found no match, and skipped it.
Why one skipped minute was fatal
A near miss would be survivable if the scheduler retried. It does not. The time check matches the exact trigger minute, deliberately, because matching anything overdue would make a backlog after an outage fire thousands of campaigns at once.
That is a defensible decision on its own, and together with the date bug it is absolute. A campaign gets exactly one minute in which it can be sent, the date check rejects it during that minute, and the minute does not come back. The row stays pending forever.
There is a recovery call on cron startup, meant for exactly this situation. It is a no-op here, because it asks the same exact-minute question.
And the failure is invisible in the only place anyone would look. The scheduled list shows campaigns whose status is pending or processing, so a campaign that can never fire sits in that list looking like one that has not fired yet. There is no error, no failed state and no alert. A customer sees "scheduled" and reasonably concludes it is going to happen.
The reason nobody found it locally
The double conversion only produces a wrong answer when the process is running in India Standard Time. Under UTC the two conversions cancel out and both helpers agree.
The compose file sets the timezone on the application service. It does not set it on the cron service, which is the one that runs the scheduler. In production that container inherits India Standard Time from the host environment; a fresh checkout on a developer's machine does not. So the bug exists in production, cannot be reproduced locally, and nothing in the repository shows the difference, because the setting that creates it is not in the repository.
That is the part I would want someone to take away. The code was identical in both places. The configuration was not, and the configuration lived somewhere no test could see. Confirming it needed one command against the running container to ask what timezone it actually thought it was in.
The fix, and the tests that pin it
Both helpers now format directly from the real instant with an explicit timezone, rather than constructing a date in one frame of reference and reading it in another:
/**
* Formatted straight from the real instant in IST, so it is correct
* whatever timezone the container runs in. en-CA renders YYYY-MM-DD.
*/
export function getIndianDate(): string {
return new Date().toLocaleDateString('en-CA', { timeZone: IST_TIME_ZONE })
}
It is a smaller change than the bug deserves, which is usually how date handling goes. The value is in the tests. They assert that the two helpers agree at the minute the stranded campaign was due, at midnight, at 05:29, at 05:30, and at 23:59, and then sweep a full 24 hours confirming neither ever disagrees with the true date and time. The named boundaries say what broke; the sweep says it cannot come back somewhere else.
A later test on the same file is there for a different reason: the helper that works out the next whole minute must roll over to the next day after 23:59, because the time matcher does not wrap midnight. That one is a note to a future reader that the exact-minute rule has edges, and this is where they are.
What I took from it
- Never build a date in one frame of reference and read it back in another. Format from the instant with an explicit zone, once.
- A system that only matches exactly needs something that catches what it missed, or every near miss is permanent.
- A status that means "waiting" and a status that means "can never happen" must not look the same to the person depending on it.
- When a bug will not reproduce, compare the environments before re-reading the code. The difference here was one variable set on one container and not another, and it was not in the repository at all.