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(exports): expire video export rows when the bucket drops the file (#101123)

Tue Haulundc3743b39a2df
diff --git a/products/exports/backend/api/test/test_exports.py b/products/exports/backend/api/test/test_exports.py
index 4d6c09d5f46b..1d88ef19177d 100644
--- a/products/exports/backend/api/test/test_exports.py
+++ b/products/exports/backend/api/test/test_exports.py
@@ -288,7 +288,7 @@ class TestExports(APIBaseTest):
"insight": None,
"export_context": None,
# PNG format gets 180 days (6 months) expiry
- "expires_after": (now() + timedelta(days=180))
+ "expires_after": (now() + timedelta(days=180) + timedelta(days=1))
.replace(hour=0, minute=0, second=0, microsecond=0)
.isoformat()
.replace("+00:00", "Z"),
@@ -314,7 +314,7 @@ class TestExports(APIBaseTest):
# Expiry is determined by format (PNG = 180 days), not the provided value
expected_expiry = (
- (now() + timedelta(days=180))
+ (now() + timedelta(days=180) + timedelta(days=1))
.replace(hour=0, minute=0, second=0, microsecond=0)
.isoformat()
.replace("+00:00", "Z")
@@ -375,7 +375,7 @@ class TestExports(APIBaseTest):
"exception": None,
"export_context": None,
# PNG format gets 180 days (6 months) expiry
- "expires_after": (now() + timedelta(days=180))
+ "expires_after": (now() + timedelta(days=180) + timedelta(days=1))
.replace(hour=0, minute=0, second=0, microsecond=0)
.isoformat()
.replace("+00:00", "Z"),
@@ -1487,9 +1487,9 @@ class TestExports(APIBaseTest):
("image/png", timedelta(days=180)),
("text/csv", timedelta(days=7)),
("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", timedelta(days=7)),
- ("video/mp4", timedelta(days=365)),
- ("video/webm", timedelta(days=365)),
- ("image/gif", timedelta(days=365)),
+ ("video/mp4", timedelta(days=30)),
+ ("video/webm", timedelta(days=30)),
+ ("image/gif", timedelta(days=30)),
("application/pdf", timedelta(days=180)),
]
)
@@ -1517,7 +1517,7 @@ class TestExports(APIBaseTest):
data = response.json()
expected_expiry = (
- (now() + expected_delta)
+ (now() + expected_delta + timedelta(days=1))
.replace(hour=0, minute=0, second=0, microsecond=0)
.isoformat()
.replace("+00:00", "Z")
diff --git a/products/exports/backend/models/exported_asset.py b/products/exports/backend/models/exported_asset.py
index 02ff4dd379f5..5cdb86512bb4 100644
--- a/products/exports/backend/models/exported_asset.py
+++ b/products/exports/backend/models/exported_asset.py
@@ -33,8 +33,8 @@ EXPORTED_ASSET_PURPOSE_SUBSCRIPTION_DELIVERY = "subscription_delivery"
DATASET_EXPORT_KIND = "dataset"
SEVEN_DAYS = timedelta(days=7)
+THIRTY_DAYS = timedelta(days=30)
SIX_MONTHS = timedelta(days=180)
-TWELVE_MONTHS = timedelta(days=365)
# The rasterizer interpolates this id into an internal recording API path, so anything that could
@@ -166,12 +166,15 @@ class ExportedAsset(models.Model):
if export_format in (cls.ExportFormat.CSV, cls.ExportFormat.XLSX, cls.ExportFormat.JSONL):
return SEVEN_DAYS
elif export_format in (cls.ExportFormat.MP4, cls.ExportFormat.WEBM, cls.ExportFormat.GIF):
- return TWELVE_MONTHS
+ # Matches the bucket's `exports-video` lifecycle rule, which drops the file at 30 days.
+ return THIRTY_DAYS
return SIX_MONTHS
@classmethod
def compute_expires_after(cls, export_format: str) -> datetime:
- expiry_datetime = now() + cls.get_expiry_delta(export_format)
+ # Rounded up, because S3 rounds a lifecycle rule up to the next UTC midnight; rounding down
+ # retires the row while the object it points at is still there.
+ expiry_datetime = now() + cls.get_expiry_delta(export_format) + timedelta(days=1)
return expiry_datetime.replace(hour=0, minute=0, second=0, microsecond=0)
@property
diff --git a/products/exports/backend/tests/test_exported_asset_model.py b/products/exports/backend/tests/test_exported_asset_model.py
index d156b9b4d7c9..21ab1d21277f 100644
--- a/products/exports/backend/tests/test_exported_asset_model.py
+++ b/products/exports/backend/tests/test_exported_asset_model.py
@@ -12,7 +12,7 @@ from posthog.storage.object_storage import ObjectStorageError
from products.exports.backend.models.exported_asset import (
SEVEN_DAYS,
SIX_MONTHS,
- TWELVE_MONTHS,
+ THIRTY_DAYS,
ExportedAsset,
get_content_response,
save_content_from_file,
@@ -117,9 +117,9 @@ class TestExportedAssetExpiresAfter(APIBaseTest):
(ExportedAsset.ExportFormat.PDF, SIX_MONTHS),
(ExportedAsset.ExportFormat.CSV, SEVEN_DAYS),
(ExportedAsset.ExportFormat.XLSX, SEVEN_DAYS),
- (ExportedAsset.ExportFormat.MP4, TWELVE_MONTHS),
- (ExportedAsset.ExportFormat.WEBM, TWELVE_MONTHS),
- (ExportedAsset.ExportFormat.GIF, TWELVE_MONTHS),
+ (ExportedAsset.ExportFormat.MP4, THIRTY_DAYS),
+ (ExportedAsset.ExportFormat.WEBM, THIRTY_DAYS),
+ (ExportedAsset.ExportFormat.GIF, THIRTY_DAYS),
(ExportedAsset.ExportFormat.JSON, SIX_MONTHS),
(ExportedAsset.ExportFormat.JSONL, SEVEN_DAYS),
]
@@ -131,7 +131,7 @@ class TestExportedAssetExpiresAfter(APIBaseTest):
export_format=export_format,
)
- expected_expiry = (datetime(2024, 6, 15, tzinfo=UTC) + expected_delta).replace(
+ expected_expiry = (datetime(2024, 6, 15, tzinfo=UTC) + expected_delta + timedelta(days=1)).replace(
hour=0, minute=0, second=0, microsecond=0
)
assert asset.expires_after == expected_expiry
diff --git a/products/replay_vision/backend/temporal/activities/ensure_session_asset.py b/products/replay_vision/backend/temporal/activities/ensure_session_asset.py
index 0476921d0f03..6d60dd665b3c 100644
--- a/products/replay_vision/backend/temporal/activities/ensure_session_asset.py
+++ b/products/replay_vision/backend/temporal/activities/ensure_session_asset.py
@@ -1,5 +1,3 @@
-import datetime as dt
-
from django.utils.timezone import now
from temporalio import activity
@@ -14,7 +12,6 @@ _PLAYBACK_SPEED = 8
_RECORDING_FPS = 3
_SHOW_METADATA_FOOTER = True
_MOUSE_TAIL = False
-_ASSET_EXPIRES_AFTER_DAYS = 90
@activity.defn
@@ -51,7 +48,6 @@ async def ensure_session_asset_activity(inputs: EnsureSessionAssetInputs) -> Ens
"mouse_tail": _MOUSE_TAIL,
},
created_at=created_at,
- expires_after=created_at + dt.timedelta(days=_ASSET_EXPIRES_AFTER_DAYS),
is_system=True,
)
return EnsureSessionAssetOutput(asset_id=asset.id)
diff --git a/products/replay_vision/backend/tests/test_temporal.py b/products/replay_vision/backend/tests/test_temporal.py
index 278e07f1e8fe..3d8da4253ac0 100644
--- a/products/replay_vision/backend/tests/test_temporal.py
+++ b/products/replay_vision/backend/tests/test_temporal.py
@@ -5,6 +5,7 @@ import threading
from typing import Any
import pytest
+import time_machine
from unittest.mock import AsyncMock, MagicMock, patch
from django.conf import settings
@@ -2301,6 +2302,7 @@ class TestFetchSessionEventsActivity:
@pytest.mark.django_db(transaction=True)
class TestEnsureSessionAssetActivity:
@pytest.mark.asyncio
+ @time_machine.travel("2026-06-15T10:30:00Z", tick=False)
async def test_creates_new_asset_with_vision_render_params(self) -> None:
scanner = await sync_to_async(_make_scanner)()
result = await ensure_session_asset_activity(
@@ -2317,6 +2319,8 @@ class TestEnsureSessionAssetActivity:
assert ctx["playback_speed"] == 8
assert ctx["recording_fps"] == 3
assert ctx["show_metadata_footer"] is True
+ # No local override: the expiry has to stay whatever the bucket's lifecycle rule drops at.
+ assert asset.expires_after == dt.datetime(2026, 7, 16, tzinfo=dt.UTC)
@pytest.mark.asyncio
async def test_reuses_existing_system_asset_for_same_session(self) -> None: