: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(data-warehouse): add agent rule for temporal workflow versioning (#71077)
Tom Owers7f598825fc4f
diff --git a/.claude/rules/temporal-workflow-versioning.md b/.claude/rules/temporal-workflow-versioning.mdnew file mode 100644index 000000000000..4900f31a2a02--- /dev/null+++ b/.claude/rules/temporal-workflow-versioning.md@@ -0,0 +1,26 @@+---+paths:+ - 'posthog/temporal/**'+ - 'products/*/backend/temporal/**'+---++**Editing a `@workflow.defn` body (adding/removing/reordering `execute_activity`, child-workflow+starts, or timers) breaks in-flight executions with "Non Deterministic Error"** — on deploy every+running execution replays its recorded history against the new code, and any new unconditional+command at a point an execution already passed fails the replay. Activity implementations and+activity _input_ dataclasses are safe to edit; workflow command sequences are not.++When adding a new activity or child-workflow start to an existing workflow, gate it one of two ways:++1. `if workflow.patched("my-change-2026-07"): ...` — the default. Old histories skip the block,+ new executions record a marker and run it. Precedent: `posthog/temporal/ai_observability/run_evaluation.py`.+ Once no pre-patch executions remain (days, for short-lived workflows), optionally swap to+ `workflow.deprecate_patch(...)` + unconditional code.+2. Gate on a **new field of an existing activity's output dataclass that defaults to the skip+ value** (e.g. `enrichment_needed: bool = False` in `create_job_model.py`) — old histories decode+ the missing field to the default, so the new command never fires during replay. Only valid when+ the decision comes from recorded history and skipping is acceptable for in-flight runs.++Never gate workflow commands on values computed inside the workflow body (feature flags, settings,+clock, DB reads) — that is itself non-deterministic. Removing/reordering existing commands needs+`workflow.patched()` with the old path kept in the `else` branch.diff --git a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.pyindex 9257ae3de6dc..b2cb25c897bb 100644--- a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py+++ b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py@@ -320,6 +320,11 @@ def trigger_schedule_buffer_one_activity(schedule_id: str) -> None:# TODO: update retry policies+#+# DETERMINISM: adding, removing, or reordering activities / child-workflow starts in `run` breaks+# every in-flight execution with a non-deterministic replay error on deploy. Gate new commands with+# `workflow.patched("...")`, or on a new `create_job_model` output field that defaults to the skip+# value — see .claude/rules/temporal-workflow-versioning.md.@workflow.defn(name="external-data-job")class ExternalDataJobWorkflow(PostHogWorkflow):@staticmethod