Skip to content

Commit f7757bb

Browse files
fercgomesclaude
andauthored
fix(session-replay): keep xgboost off the temporal worker import path (#68269)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 505ccb5 commit f7757bb

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • posthog/temporal/session_replay/surfacing_scoring_sweep

posthog/temporal/session_replay/surfacing_scoring_sweep/scorer.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
import os
1818
import tempfile
1919
import threading
20+
from typing import TYPE_CHECKING
2021
from urllib.parse import urlparse
2122

2223
import numpy as np
2324
import pandas as pd
24-
import xgboost as xgb
2525
import structlog
2626

27+
if TYPE_CHECKING:
28+
import xgboost as xgb
29+
2730
from posthog.storage import object_storage
2831
from posthog.temporal.session_replay.surfacing_scoring_sweep.feature_schema import assert_serving_schema_parity
2932
from posthog.temporal.session_replay.surfacing_scoring_sweep.features import feature_matrix
@@ -82,6 +85,11 @@ def _load_booster() -> xgb.Booster:
8285
8386
On first load: runs assert_serving_schema_parity and caches feature_names.
8487
"""
88+
# Deferred: xgboost dlopens libomp at import, which can fail on machines without an OpenMP
89+
# runtime. This module is imported (via the package __init__) by the shared temporal worker,
90+
# and a scoring-only native dep must not stop every other workflow from loading.
91+
import xgboost as xgb # noqa: PLC0415 — keeps the heavy native dep off the worker's import path
92+
8593
global _BOOSTER, _FEATURE_NAMES
8694
cached_booster = _BOOSTER
8795
if cached_booster is not None:
@@ -172,6 +180,8 @@ def predict(df: pd.DataFrame) -> np.ndarray:
172180
path and skips re-validation. Returned array is positionally aligned
173181
with `df.index`.
174182
"""
183+
import xgboost as xgb # noqa: PLC0415 — keeps the heavy native dep off the worker's import path
184+
175185
booster = _load_booster()
176186
feature_names = get_feature_names()
177187

0 commit comments

Comments
 (0)