Skip to content

Conversation

@tomasfarias
Copy link
Contributor

Problem

We have a function adjust_bound_datetime_to_schedule_time_zone intended to resolve the problem of a backfill input not matching a schedule's timezone. In this case, we always prefer the schedule's timezone, assuming that as the source of truth.

Consider the way we resolve inputs for daily backfills: We simply replace the timezone for the schedule's timezone. This is fine for when the backfill is just starting: Since backfills are always at midnight, and we assume the input is midnight in some timezone, we can just replace that for the schedule's timezone and move on. For example an input of "2025-01-01T00:00:00+00:00" for a schedule in CET timezone would become "2025-01-01T00:00:00+01:00".

Continuing, later in the code we convert this input back into UTC. Continuing with the example, "2025-01-01T00:00:00+01:00" becomes "2024-12-31T23:00:00+00:00". Since these times are equivalent, so far so good.

The problem comes when the backfill activity fails: We send the converted timestamp as temporal heartbeat details and use that to recover from a failure. In the retry, we once again run adjust_bound_datetime_to_schedule_time_zone to adjust the timezone, but this timestamp was already converted UTC, so if the schedule is not in UTC, we will end up "double correcting": The "2024-12-31T23:00:00+00:00" in the details is now replaced to "2024-12-31T23:00:00+01:00" which is then converted to UTC and drifted back one hour to "2024-12-31T22:00:00+01:00".

Changes

When receiving a timestamp from activity details, cast it to the schedule's timezone, thus undoing the UTC cast, and letting everything proceed as it should.

How did you test this code?

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Changelog: (features only) Is this feature complete?

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@tomasfarias tomasfarias force-pushed the fix/convert-to-schedule-timezone-on-backfill-failure branch from d10d1f7 to 9d113c5 Compare December 8, 2025 17:37
@tomasfarias tomasfarias requested a review from a team December 8, 2025 17:38
Copy link
Contributor

@rossgray rossgray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like this should work. Were you able to reproduce and test that it fixes things locally? If not, maybe we can test in prod once this is live just to confirm it does fix the issue

@tomasfarias tomasfarias force-pushed the fix/convert-to-schedule-timezone-on-backfill-failure branch from 87bb49d to 60ea9c2 Compare December 9, 2025 08:58
@tomasfarias
Copy link
Contributor Author

tomasfarias commented Dec 9, 2025

@rossgray
I unfortunately wasn't able to reproduce a failure of the backfill activity

@tomasfarias tomasfarias force-pushed the fix/convert-to-schedule-timezone-on-backfill-failure branch from 60ea9c2 to c4316b6 Compare December 9, 2025 10:36
@tomasfarias tomasfarias merged commit 17a3a75 into master Dec 9, 2025
243 of 245 checks passed
@tomasfarias tomasfarias deleted the fix/convert-to-schedule-timezone-on-backfill-failure branch December 9, 2025 14:01
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.

3 participants