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(signals): grace the scout due-check so hourly scouts don't halve (#62063)

Andrew Maguire4461c24c4873
diff --git a/products/signals/backend/temporal/agentic/scout_coordinator.py b/products/signals/backend/temporal/agentic/scout_coordinator.py
index 5703391babd7..607249e0d7c5 100644
--- a/products/signals/backend/temporal/agentic/scout_coordinator.py
+++ b/products/signals/backend/temporal/agentic/scout_coordinator.py
@@ -49,6 +49,10 @@ MAX_RUNS_PER_TICK = 50
# just the polling granularity — the floor on how often any scout can run.
COORDINATOR_INTERVAL_MINUTES = 30
+# Slack on the due-check so a scout that's a few seconds short at a tick still counts as due —
+# else stamp jitter makes it skip every other tick (a 60-min scout runs every 2h).
+DUE_GRACE_SECONDS = 60
+
@dataclass
class PlannedRun:
@@ -281,11 +285,11 @@ def _register_missing_configs(team: Team) -> set[str]:
def _overdue_seconds(config: SignalScoutConfig, now: datetime) -> float | None:
- """Seconds past due, or None if not yet due. Never-run rows are maximally overdue."""
+ """Seconds past due (down to `-DUE_GRACE_SECONDS`), or None if not yet due. Never-run rows are maximally overdue."""
if config.last_run_at is None:
return float("inf")
overdue = (now - config.last_run_at).total_seconds() - config.run_interval_minutes * 60
- return overdue if overdue >= 0 else None
+ return overdue if overdue >= -DUE_GRACE_SECONDS else None
@workflow.defn(name="run-signals-scout-coordinator")
diff --git a/products/signals/backend/test/test_scout_coordinator.py b/products/signals/backend/test/test_scout_coordinator.py
index fa59fbf3638f..923e46f110e5 100644
--- a/products/signals/backend/test/test_scout_coordinator.py
+++ b/products/signals/backend/test/test_scout_coordinator.py
@@ -279,6 +279,27 @@ async def test_config_within_interval_is_not_due(ateam):
assert await _run_activity() == []
+ "seconds_short,expected_skill_names",
+ [
+ (5, ["signals-scout-foo"]), # within grace — stamp jitter shouldn't halve cadence
+ (120, []), # beyond grace — genuinely not due yet
+ ],
+)
+async def test_due_check_grace_boundary(ateam, seconds_short, expected_skill_names):
+ await database_sync_to_async(_create_skill)(ateam, "signals-scout-foo")
+ last_run = timezone.now() - timedelta(minutes=60) + timedelta(seconds=seconds_short)
+ await database_sync_to_async(_create_config)(
+ ateam, "signals-scout-foo", enabled=True, run_interval_minutes=60, last_run_at=last_run
+ )
+
+ planned = await _run_activity()
+
+ assert [p.skill_name for p in planned] == expected_skill_names
+
+
@pytest.mark.asyncio
@pytest.mark.django_db
async def test_overdue_config_is_planned_without_stamping(ateam):