Skip to content

fix(session-replay): keep xgboost off the temporal worker import path#68269

Merged
fercgomes merged 2 commits into
masterfrom
fix/lazy-xgboost-import-temporal-worker
Jul 3, 2026
Merged

fix(session-replay): keep xgboost off the temporal worker import path#68269
fercgomes merged 2 commits into
masterfrom
fix/lazy-xgboost-import-temporal-worker

Conversation

@fercgomes

@fercgomes fercgomes commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Problem

xgboost dlopens libomp at import time. On a macOS dev machine without an OpenMP runtime (no homebrew libomp), import xgboost raises XGBoostError — and since the shared temporal worker imports the surfacing scoring package at module load (worker.pysurfacing_scoring_sweep.metrics → package __init__activitiesscorerimport xgboost), the whole dev temporal worker crash-loops and every product's workflows stop running. The existing warmup_best_effort() guard never runs because the failure happens before the worker can boot.

Changes

Defer import xgboost into the two functions that actually use it (_load_booster, predict), with a TYPE_CHECKING import for annotations. A missing OpenMP runtime now fails surfacing scoring activities at runtime (logged, retried per policy) instead of preventing the worker from importing at all — matching the intent warmup_best_effort() already documents.

How did you test this code?

  • Verified the regression directly: after the change, importing posthog.temporal.session_replay.surfacing_scoring_sweep under Django no longer puts xgboost in sys.modules (it previously crashed outright on a machine without libomp).
  • ruff check / ruff format clean.
  • test_scorer.py can't run on the affected machine (it genuinely needs xgboost); CI runs it with libomp present, and no behavior inside the functions changed — only the import site moved.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Built with Claude Code. Found while debugging why a fresh onboarding cloud run sat queued forever locally: phrocs showed the temporal worker crash-looping on this import. Chose the lazy-import route (sanctioned for heavy/optional native deps, noqa: PLC0415) over adding libomp to the flox manifest — the worker staying up matters for everyone; provisioning the OpenMP runtime for people who actually run scoring locally can be a separate devex change.

🤖 Generated with Claude Code

xgboost dlopens libomp at import time, and on macOS dev machines without
an OpenMP runtime (no homebrew libomp) that raises XGBoostError while
the shared temporal worker imports the surfacing scoring package —
crash-looping the whole worker and taking every product's workflows
down with it. The warmup_best_effort guard never gets a chance to run
because the failure happens at module import.

Import xgboost lazily inside the two functions that use it, so a
missing OpenMP runtime only fails surfacing scoring activities at
runtime instead of preventing the worker from booting.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@fercgomes fercgomes marked this pull request as ready for review July 3, 2026 15:59
@fercgomes fercgomes added the stamphog Request AI approval (no full review) label Jul 3, 2026
@assign-reviewers-posthog assign-reviewers-posthog Bot requested review from a team, TueHaulund, arnohillen, fasyy612 and ksvat and removed request for a team July 3, 2026 16:00
@greptile-apps

greptile-apps Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(session-replay): keep xgboost off th..." | Re-trigger Greptile

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial, well-scoped fix deferring an xgboost import to avoid breaking the shared temporal worker; no API/data model changes, and two independent bot reviewers gave 👍.

@fercgomes fercgomes enabled auto-merge (squash) July 3, 2026 16:02
@fercgomes fercgomes merged commit f7757bb into master Jul 3, 2026
238 checks passed
@fercgomes fercgomes deleted the fix/lazy-xgboost-import-temporal-worker branch July 3, 2026 16:51
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 3, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-03 17:20 UTC Run
prod-us ✅ Deployed 2026-07-03 17:35 UTC Run
prod-eu ✅ Deployed 2026-07-03 17:36 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stamphog Request AI approval (no full review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants