Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(batch-exports): don't re-emit SLA breach warning on workflow replay (#70697)

Ross07a6dfe2100f
diff --git a/products/batch_exports/backend/temporal/metrics.py b/products/batch_exports/backend/temporal/metrics.py
index a7f2b5f45894..c2dd77e151ca 100644
--- a/products/batch_exports/backend/temporal/metrics.py
+++ b/products/batch_exports/backend/temporal/metrics.py
@@ -552,6 +552,20 @@ class SLAWaiter:
"""Coroutine used to wait for SLA seconds."""
await asyncio.sleep(self.sla.total_seconds())
+ # Only log when the timer resolves live, not when it re-resolves from history during a
+ # replay (worker recovery, cache eviction, queries).
+ #
+ # A breach that already happened was logged closely to the first time the timer fired,
+ # so we don't expect a breach to be missed; suppressing replays just avoids logging it again. A run
+ # that hasn't breached yet — including one recovering mid-flight — replays up to the
+ # live edge and then fires its still-pending timer live, so it logs as normal.
+ #
+ # The guard sits here (after the timer resolves) rather than around task creation
+ # because the sleep is a deterministic Temporal timer: the task must be created on
+ # every replay or history diverges. So we suppress the log, never the timer.
+ if workflow.in_workflow() and workflow.unsafe.is_replaying():
+ return
+
self._over_sla.set()
LOGGER.warning(
"SLA breached",