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(session-replay): keep xgboost off the temporal worker import path (#68269)

Fernando Gomesf7757bb64dd1
diff --git a/posthog/temporal/session_replay/surfacing_scoring_sweep/scorer.py b/posthog/temporal/session_replay/surfacing_scoring_sweep/scorer.py
index 1e0cb4fba2b6..161f76086535 100644
--- a/posthog/temporal/session_replay/surfacing_scoring_sweep/scorer.py
+++ b/posthog/temporal/session_replay/surfacing_scoring_sweep/scorer.py
@@ -17,13 +17,16 @@ from __future__ import annotations
import os
import tempfile
import threading
+from typing import TYPE_CHECKING
from urllib.parse import urlparse
import numpy as np
import pandas as pd
-import xgboost as xgb
import structlog
+if TYPE_CHECKING:
+ import xgboost as xgb
+
from posthog.storage import object_storage
from posthog.temporal.session_replay.surfacing_scoring_sweep.feature_schema import assert_serving_schema_parity
from posthog.temporal.session_replay.surfacing_scoring_sweep.features import feature_matrix
@@ -82,6 +85,11 @@ def _load_booster() -> xgb.Booster:
On first load: runs assert_serving_schema_parity and caches feature_names.
"""
+ # Deferred: xgboost dlopens libomp at import, which can fail on machines without an OpenMP
+ # runtime. This module is imported (via the package __init__) by the shared temporal worker,
+ # and a scoring-only native dep must not stop every other workflow from loading.
+ import xgboost as xgb # noqa: PLC0415 — keeps the heavy native dep off the worker's import path
+
global _BOOSTER, _FEATURE_NAMES
cached_booster = _BOOSTER
if cached_booster is not None:
@@ -172,6 +180,8 @@ def predict(df: pd.DataFrame) -> np.ndarray:
path and skips re-validation. Returned array is positionally aligned
with `df.index`.
"""
+ import xgboost as xgb # noqa: PLC0415 — keeps the heavy native dep off the worker's import path
+
booster = _load_booster()
feature_names = get_feature_names()