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(error-tracking): raise summary worker slots and report worker-busy skips (#126163)

James Gille159664a0161
diff --git a/products/error_tracking/backend/logic/issue_summaries.py b/products/error_tracking/backend/logic/issue_summaries.py
index 5e608fd32016..66b88d54abfa 100644
--- a/products/error_tracking/backend/logic/issue_summaries.py
+++ b/products/error_tracking/backend/logic/issue_summaries.py
@@ -490,6 +490,14 @@ def _generate_and_report(
return result
+def report_worker_busy(team_id: int, issue_id: UUID | str, trigger: IssueSummaryTrigger) -> None:
+ """Count and report a lifecycle attempt skipped because every worker summary slot was busy."""
+ ISSUE_SUMMARY_OUTCOMES.labels(outcome=IssueSummaryOutcome.RATE_LIMITED.value, trigger=trigger.value).inc()
+ _report_task(
+ team_id, issue_id, trigger, IssueSummaryOutcome.RATE_LIMITED, has_summary=False, timings=IssueSummaryTimings()
+ )
+
+
def _report_task(
team_id: int,
issue_id: UUID | str,
diff --git a/products/error_tracking/backend/temporal/lifecycle/summary_worker.py b/products/error_tracking/backend/temporal/lifecycle/summary_worker.py
index 8378791a1409..fe4448f333e2 100644
--- a/products/error_tracking/backend/temporal/lifecycle/summary_worker.py
+++ b/products/error_tracking/backend/temporal/lifecycle/summary_worker.py
@@ -17,9 +17,20 @@ if TYPE_CHECKING:
logger = structlog.get_logger(__name__)
-# A summary holds an activity slot for the whole model call, and alert dispatch shares this worker's slots.
+MIN_ISSUE_SUMMARY_WORKER_SLOTS = 3
+# Alert dispatch, embedding and severity inference share this worker's activity slots.
+MIN_NON_SUMMARY_WORKER_SLOTS = 2
+
+
+def issue_summary_worker_slot_count(max_concurrent_activities: int) -> int:
+ """A quarter of the activity slots, raised to a floor that a small worker still leaves room for."""
+ floor = min(MIN_ISSUE_SUMMARY_WORKER_SLOTS, max_concurrent_activities - MIN_NON_SUMMARY_WORKER_SLOTS)
+ return max(1, floor, max_concurrent_activities // 4)
+
+
+# A summary holds an activity slot for the whole model call.
ISSUE_SUMMARY_WORKER_SLOTS = threading.BoundedSemaphore(
- max(1, (settings.MAX_CONCURRENT_ACTIVITIES or DEFAULT_MAX_CONCURRENT_TASKS) // 4)
+ issue_summary_worker_slot_count(settings.MAX_CONCURRENT_ACTIVITIES or DEFAULT_MAX_CONCURRENT_TASKS)
)
@@ -29,9 +40,9 @@ def generate_summary_on_worker(
"""Run a lifecycle summary generation when the on-write flag is on and a worker summary slot is free."""
# issue_summaries imports the lifecycle rendering module, whose package imports the activities that call this.
from products.error_tracking.backend.logic.issue_summaries import ( # noqa: PLC0415
- ISSUE_SUMMARY_OUTCOMES,
IssueSummaryOutcome,
issue_summaries_on_write_enabled,
+ report_worker_busy,
)
# Checked outside the generator, which reports every attempt as an event, so a team without the flag sends none.
@@ -40,7 +51,7 @@ def generate_summary_on_worker(
# Skip instead of wait, because a waiting activity still holds its slot. The read path generates the summary.
if not ISSUE_SUMMARY_WORKER_SLOTS.acquire(blocking=False):
logger.warning("error_tracking_issue_summary_worker_busy", team_id=team_id, issue_id=issue_id, trigger=trigger)
- ISSUE_SUMMARY_OUTCOMES.labels(outcome=IssueSummaryOutcome.RATE_LIMITED.value, trigger=trigger.value).inc()
+ report_worker_busy(team_id, issue_id, trigger)
return IssueSummaryOutcome.RATE_LIMITED
try:
return generate().outcome
diff --git a/products/error_tracking/backend/tests/test_issue_summaries.py b/products/error_tracking/backend/tests/test_issue_summaries.py
index 0d358234c33b..128a9b0ebf78 100644
--- a/products/error_tracking/backend/tests/test_issue_summaries.py
+++ b/products/error_tracking/backend/tests/test_issue_summaries.py
@@ -14,6 +14,7 @@ from django.db import OperationalError
from django.test import SimpleTestCase
from parameterized import parameterized
+from prometheus_client import REGISTRY
from redis.exceptions import RedisError
from posthog.constants import AvailableFeature
@@ -115,6 +116,18 @@ class TestIssueSummaryParsing(SimpleTestCase):
base: dict[str, Any] = {"fingerprints": ["a"], "latest_release": "1.0.0", "occurrences": 5}
assert (compute_input_hash(**{**base, **before}) == compute_input_hash(**{**base, **after})) == same
+ @parameterized.expand(
+ [
+ ("single_slot", 1, 1),
+ ("keeps_two_for_alerts", 4, 2),
+ ("floor", 5, 3),
+ ("floor_above_quarter", 12, 3),
+ ("quarter", 50, 12),
+ ]
+ )
+ def test_issue_summary_worker_slot_count(self, _name: str, max_concurrent_activities: int, expected: int) -> None:
+ assert summary_worker.issue_summary_worker_slot_count(max_concurrent_activities) == expected
+
# Failures after the gates pass.
FAILURE_CASES: list[tuple[str, Any, IssueSummaryOutcome]] = [
@@ -536,25 +549,40 @@ class TestIssueSummaryGeneration(BaseTest):
"created",
issue_created_activities,
lambda test: generate_issue_created_summary_activity(test._issue_created_inputs()),
+ "write",
),
(
"reopened",
issue_reopened_activities,
lambda test: generate_issue_reopened_summary_activity(test._issue_reopened_inputs()),
+ "reopen",
),
]
)
def test_lifecycle_summary_activity_skips_while_worker_summary_slots_are_full(
- self, _name: str, activities: Any, run_activity: Any
+ self, _name: str, activities: Any, run_activity: Any, trigger: str
) -> None:
self.enterContext(patch.object(team_flags, "feature_enabled_or_false", return_value=True))
self.enterContext(patch.object(activities, "fetch_event_properties", return_value={"$lib": "web"}))
+ capture = MagicMock()
+ self.enterContext(patch.object(issue_summaries, "ph_background_capture", return_value=capture))
slots = threading.BoundedSemaphore(1)
self.enterContext(patch.object(summary_worker, "ISSUE_SUMMARY_WORKER_SLOTS", slots))
+ counter_labels = {"outcome": IssueSummaryOutcome.RATE_LIMITED.value, "trigger": trigger}
+ skips_before = REGISTRY.get_sample_value("error_tracking_issue_summary_total", counter_labels) or 0
slots.acquire()
assert run_activity(self) == IssueSummaryOutcome.RATE_LIMITED.value
assert self.llm_calls == 0
+ capture.assert_called_once()
+ assert capture.call_args.kwargs["event"] == issue_summaries.ISSUE_SUMMARY_TASK_EVENT
+ properties = capture.call_args.kwargs["properties"]
+ assert (properties["outcome"], properties["trigger"], properties["has_summary"]) == (
+ IssueSummaryOutcome.RATE_LIMITED.value,
+ trigger,
+ False,
+ )
+ assert REGISTRY.get_sample_value("error_tracking_issue_summary_total", counter_labels) == skips_before + 1
slots.release()
assert run_activity(self) == IssueSummaryOutcome.GENERATED.value