: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
fix(replay): let Max pin recordings by session id instead of a $session_id filter (#79491)
posthog[bot]d5a6da537705
diff --git a/ee/hogai/tools/replay/filter_session_recordings.py b/ee/hogai/tools/replay/filter_session_recordings.pyindex 071c10e0d9b1..3d4d57bf7b30 100644--- a/ee/hogai/tools/replay/filter_session_recordings.py+++ b/ee/hogai/tools/replay/filter_session_recordings.py@@ -110,6 +110,10 @@ class FilterSessionRecordingsToolArgs(BaseModel):## Test Accounts- **filter_test_accounts**: true (recommended, exclude test accounts), false/null (include all)+ ## Specific Recordings+ - **session_ids**: array of session ids, to pin the result to exactly those recordings. Use it to show the sessions you are already talking about, for example the ones you just summarized.+ - `$session_id` is not a session property, so never filter on it in `filter_group` — pass the ids in `session_ids` instead.+# Operators by Data Type**String**: "exact", "is_not", "icontains", "not_icontains", "regex", "not_regex", "is_set", "is_not_set"**Numeric**: "exact", "is_not", "gt", "gte", "lt", "lte", "is_set", "is_not_set"diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 23864cf4d6b4..64c491994064 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -35405,6 +35405,13 @@"$ref": "#/definitions/RecordingOrderDirection","default": "DESC","description": "Replay originally had all ordering as descending by specifying the field name, this runs counter to Django behavior where the field name specifies ascending sorting (e.g. the_field_name) and -the_field_name would indicate descending order to avoid invalidating or migrating all existing filters we keep DESC as the default or allow specification of an explicit order direction here"+ },+ "session_ids": {+ "description": "Pin the result to specific recordings by their session id, e.g. the ones just summarized. `$session_id` is not a session property, so it cannot be filtered on in `filter_group`.",+ "items": {+ "type": "string"+ },+ "type": "array"}},"required": ["duration", "filter_group"],diff --git a/frontend/src/queries/schema/schema-assistant-replay.ts b/frontend/src/queries/schema/schema-assistant-replay.tsindex 145495b58b72..f0c566d03a45 100644--- a/frontend/src/queries/schema/schema-assistant-replay.ts+++ b/frontend/src/queries/schema/schema-assistant-replay.ts@@ -22,6 +22,8 @@ export interface MaxRecordingUniversalFilters {order_direction?: RecordingsQuery['order_direction']/** How many recordings the user requested to use. Skip if user did not indicate preference. */limit?: RecordingsQuery['limit']+ /** Pin the result to specific recordings by their session id, e.g. the ones just summarized. `$session_id` is not a session property, so it cannot be filtered on in `filter_group`. */+ session_ids?: RecordingsQuery['session_ids']}export type MaxOuterUniversalFiltersGroup = {diff --git a/posthog/schema.py b/posthog/schema.pyindex 984a5eed1f96..bfff47b14f7e 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -26236,6 +26236,14 @@ class MaxRecordingUniversalFilters(BaseModel):" order direction here"),)+ session_ids: list[str] | None = Field(+ default=None,+ description=(+ "Pin the result to specific recordings by their session id, e.g. the ones"+ " just summarized. `$session_id` is not a session property, so it cannot be"+ " filtered on in `filter_group`."+ ),+ )class MetricsQuery(BaseModel):diff --git a/posthog/session_recordings/playlist_filters.py b/posthog/session_recordings/playlist_filters.pyindex 15a399a23a88..4180caca79c8 100644--- a/posthog/session_recordings/playlist_filters.py+++ b/posthog/session_recordings/playlist_filters.py@@ -246,6 +246,9 @@ def convert_filters_to_recordings_query(filters: dict[str, Any]) -> RecordingsQu# Mirrors the frontend converter: dropping it would make a saved playlist count# every recording instead of the exposed population it displays.experiment_exposure=filters.get("experiment_exposure"),+ # Also mirrors the frontend converter: a playlist pinned to specific recordings+ # would otherwise count and render every recording that matches the rest of the filters.+ session_ids=filters.get("session_ids"),)except ValidationError as e:# we were seeing errors here and it was hard to debugdiff --git a/posthog/session_recordings/test/test_playlist_filters.py b/posthog/session_recordings/test/test_playlist_filters.pyindex 7159a20dccc2..0e1d52d18e4f 100644--- a/posthog/session_recordings/test/test_playlist_filters.py+++ b/posthog/session_recordings/test/test_playlist_filters.py@@ -42,6 +42,14 @@ class TestConvertFiltersToRecordingsQuery(SimpleTestCase):assert query.experiment_exposure.experiment_id == 42assert query.experiment_exposure.variant == "test"+ def test_session_ids_survive_conversion(self):+ # Dropped here, a playlist pinned to specific recordings would count and render every+ # recording matching the rest of the filters.+ filters = _filters("AND", "AND", [])+ filters["session_ids"] = ["0190abc", "0191def"]+ query = convert_filters_to_recordings_query(filters)+ assert query.session_ids == ["0190abc", "0191def"]+def test_visited_page_becomes_recording_property_not_event(self):filters = _filters("OR", "OR", [_visited_page("/cart"), _visited_page("/orders")])query = convert_filters_to_recordings_query(filters)