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(deletion): make recording-deletion queueing best-effort (#64456)

Yasen22e157ec5382
diff --git a/posthog/temporal/delete_teams/workflows.py b/posthog/temporal/delete_teams/workflows.py
index 8bddc7059ca8..17b1d22edea7 100644
--- a/posthog/temporal/delete_teams/workflows.py
+++ b/posthog/temporal/delete_teams/workflows.py
@@ -2,6 +2,7 @@ import datetime as dt
import temporalio.common
import temporalio.workflow
+import temporalio.exceptions
from posthog.temporal.common.base import PostHogWorkflow
from posthog.temporal.delete_teams.activities import (
@@ -85,14 +86,23 @@ class DeleteTeamsDataWorkflow(PostHogWorkflow):
team_inputs = TeamDataActivityInputs(team_ids=inputs.team_ids, user_id=inputs.user_id)
- # Start the autonomous session-replay recording deletion (fire-and-forget).
- await temporalio.workflow.execute_activity(
- queue_recording_deletions_activity,
- team_inputs,
- start_to_close_timeout=LIGHT_ACTIVITY_TIMEOUT,
- heartbeat_timeout=LIGHT_HEARTBEAT_TIMEOUT,
- retry_policy=SIDE_EFFECT_RETRY_POLICY,
- )
+ # Start the autonomous session-replay recording deletion (fire-and-forget). Best-effort:
+ # queuing recording deletion is not a prerequisite for removing the team's data, so if it
+ # exhausts its retries we log and carry on rather than wedging the whole deletion. Recordings
+ # left behind are reaped by their own retention/TTL.
+ try:
+ await temporalio.workflow.execute_activity(
+ queue_recording_deletions_activity,
+ team_inputs,
+ start_to_close_timeout=LIGHT_ACTIVITY_TIMEOUT,
+ heartbeat_timeout=LIGHT_HEARTBEAT_TIMEOUT,
+ retry_policy=SIDE_EFFECT_RETRY_POLICY,
+ )
+ except temporalio.exceptions.ActivityError:
+ temporalio.workflow.logger.warning(
+ "queue_recording_deletions_activity failed; continuing team deletion without it",
+ exc_info=True,
+ )
for activity in BULKY_POSTGRES_ACTIVITIES:
await temporalio.workflow.execute_activity(
diff --git a/posthog/temporal/tests/delete_teams/test_workflows.py b/posthog/temporal/tests/delete_teams/test_workflows.py
index d61b4d14f32a..00b3fb5e4f68 100644
--- a/posthog/temporal/tests/delete_teams/test_workflows.py
+++ b/posthog/temporal/tests/delete_teams/test_workflows.py
@@ -214,6 +214,21 @@ async def test_transient_error_is_retried():
assert len(attempts) == 2 # retried once, then succeeded
+async def test_recording_deletion_failure_does_not_block_workflow():
+ # Queuing recording deletion is best-effort: if it exhausts its retries, the rest of the
+ # team deletion must still run to completion.
+ attempts: list[str] = []
+
+ async def always_fails(inputs: TeamDataActivityInputs) -> None:
+ attempts.append("attempt")
+ raise RuntimeError("recording deletion service unavailable")
+
+ activities = _core_activities_with("queue_recording_deletions_activity", always_fails)
+ await _run_core_with(activities) # completes despite recording deletion failing
+
+ assert len(attempts) == 5 # exhausted SIDE_EFFECT_RETRY_POLICY, then swallowed
+
+
async def test_recursion_error_fails_fast_without_retry():
# A RecursionError is deterministic (e.g. json.loads can't decode a deeply-nested JSON column
# on a cascaded row), so the retry policy must not loop on it.