Skip to content

Commit f2eca27

Browse files
authored
Merge branch 'master' into distributed-embedding-table
2 parents 077a964 + 7300a2b commit f2eca27

File tree

17 files changed

+111
-78
lines changed

17 files changed

+111
-78
lines changed

ee/api/session_summaries.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def _if_video_validation_enabled(self, user: User) -> bool | None:
106106
@staticmethod
107107
async def _get_summary_from_progress_stream(
108108
session_ids: list[str],
109-
user_id: int,
109+
user: User,
110110
team: Team,
111111
min_timestamp: datetime,
112112
max_timestamp: datetime,
@@ -117,7 +117,7 @@ async def _get_summary_from_progress_stream(
117117
results: list[tuple[SessionSummaryStreamUpdate, tuple[EnrichedSessionGroupSummaryPatternsList, str] | str]] = []
118118
async for update in execute_summarize_session_group(
119119
session_ids=session_ids,
120-
user_id=user_id,
120+
user=user,
121121
team=team,
122122
min_timestamp=min_timestamp,
123123
max_timestamp=max_timestamp,
@@ -171,7 +171,7 @@ def create_session_summaries(self, request: Request, **kwargs) -> Response:
171171
try:
172172
summary = async_to_sync(self._get_summary_from_progress_stream)(
173173
session_ids=session_ids,
174-
user_id=user.id,
174+
user=user,
175175
team=self.team,
176176
min_timestamp=min_timestamp,
177177
max_timestamp=max_timestamp,
@@ -217,15 +217,15 @@ def create_session_summaries(self, request: Request, **kwargs) -> Response:
217217
@staticmethod
218218
async def _summarize_session(
219219
session_id: str,
220-
user_id: int,
220+
user: User,
221221
team: Team,
222222
video_validation_enabled: bool | None,
223223
extra_summary_context: ExtraSummaryContext | None = None,
224224
) -> SessionSummarySerializer | Exception:
225225
try:
226226
summary_raw = await execute_summarize_session(
227227
session_id=session_id,
228-
user_id=user_id,
228+
user=user,
229229
team=team,
230230
video_validation_enabled=video_validation_enabled,
231231
extra_summary_context=extra_summary_context,
@@ -240,7 +240,7 @@ async def _summarize_session(
240240
async def _get_individual_summaries(
241241
self,
242242
session_ids: list[str],
243-
user_id: int,
243+
user: User,
244244
team: Team,
245245
video_validation_enabled: bool | None,
246246
extra_summary_context: ExtraSummaryContext | None = None,
@@ -251,7 +251,7 @@ async def _get_individual_summaries(
251251
tasks[session_id] = tg.create_task(
252252
self._summarize_session(
253253
session_id=session_id,
254-
user_id=user_id,
254+
user=user,
255255
team=team,
256256
video_validation_enabled=video_validation_enabled,
257257
extra_summary_context=extra_summary_context,
@@ -262,9 +262,9 @@ async def _get_individual_summaries(
262262
res: SessionSummarySerializer | Exception = task.result()
263263
if isinstance(res, Exception):
264264
logger.exception(
265-
f"Failed to generate individual session summary for session {session_id} from team {team.pk} by user {user_id}: {res}",
265+
f"Failed to generate individual session summary for session {session_id} from team {team.pk} by user {user.id}: {res}",
266266
team_id=team.pk,
267-
user_id=user_id,
267+
user_id=user.id,
268268
)
269269
else:
270270
# Return only successful summaries
@@ -296,7 +296,7 @@ def create_session_summaries_individually(self, request: Request, **kwargs) -> R
296296
try:
297297
summaries = async_to_sync(self._get_individual_summaries)(
298298
session_ids=session_ids,
299-
user_id=user.id,
299+
user=user,
300300
team=self.team,
301301
video_validation_enabled=video_validation_enabled,
302302
extra_summary_context=extra_summary_context,

ee/api/test/test_session_summaries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_create_summaries_success(
123123
# Verify execute_summarize_session_group was called correctly
124124
mock_execute.assert_called_once_with(
125125
session_ids=["session1", "session2"],
126-
user_id=self.user.pk,
126+
user=self.user,
127127
team=self.team,
128128
min_timestamp=datetime(2024, 1, 1, 10, 0, 0),
129129
max_timestamp=datetime(2024, 1, 1, 11, 0, 0),

ee/hogai/chat_agent/session_summaries/nodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ async def _summarize(session_id: str) -> dict[str, Any]:
488488
nonlocal completed
489489
result = await execute_summarize_session(
490490
session_id=session_id,
491-
user_id=self._node._user.id,
491+
user=self._node._user,
492492
team=self._node._team,
493493
model_to_use=SESSION_SUMMARIES_SYNC_MODEL,
494494
video_validation_enabled=video_validation_enabled,
@@ -521,7 +521,7 @@ async def _summarize_sessions_as_group(
521521

522522
async for update_type, data in execute_summarize_session_group(
523523
session_ids=session_ids,
524-
user_id=self._node._user.id,
524+
user=self._node._user,
525525
team=self._node._team,
526526
min_timestamp=min_timestamp,
527527
max_timestamp=max_timestamp,

ee/hogai/session_summaries/session/stream.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections.abc import Generator
22

33
from posthog.models.team.team import Team
4+
from posthog.models.user import User
45
from posthog.settings import SERVER_GATEWAY_INTERFACE
56
from posthog.temporal.ai.session_summary.summarize_session import execute_summarize_session_stream
67

@@ -10,22 +11,22 @@
1011

1112
def stream_recording_summary(
1213
session_id: str,
13-
user_id: int,
14+
user: User,
1415
team: Team,
1516
extra_summary_context: ExtraSummaryContext | None = None,
1617
local_reads_prod: bool = False,
1718
) -> SyncIterableToAsync | Generator[str, None, None]:
1819
if SERVER_GATEWAY_INTERFACE == "ASGI":
1920
return _astream(
2021
session_id=session_id,
21-
user_id=user_id,
22+
user=user,
2223
team=team,
2324
extra_summary_context=extra_summary_context,
2425
local_reads_prod=local_reads_prod,
2526
)
2627
return execute_summarize_session_stream(
2728
session_id=session_id,
28-
user_id=user_id,
29+
user=user,
2930
team=team,
3031
extra_summary_context=extra_summary_context,
3132
local_reads_prod=local_reads_prod,
@@ -34,15 +35,15 @@ def stream_recording_summary(
3435

3536
def _astream(
3637
session_id: str,
37-
user_id: int,
38+
user: User,
3839
team: Team,
3940
extra_summary_context: ExtraSummaryContext | None = None,
4041
local_reads_prod: bool = False,
4142
) -> SyncIterableToAsync:
4243
return SyncIterableToAsync(
4344
execute_summarize_session_stream(
4445
session_id=session_id,
45-
user_id=user_id,
46+
user=user,
4647
team=team,
4748
extra_summary_context=extra_summary_context,
4849
local_reads_prod=local_reads_prod,

ee/hogai/session_summaries/session/summarize_session.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class SingleSessionSummaryLlmInputs:
6363

6464
session_id: str
6565
user_id: int
66+
user_distinct_id_to_log: str | None = None
6667
summary_prompt: str
6768
system_prompt: str
6869
simplified_events_mapping: dict[str, list[str | int | None | list[str]]]
@@ -218,7 +219,12 @@ async def prepare_data_for_single_session_summary(
218219

219220

220221
def prepare_single_session_summary_input(
221-
session_id: str, user_id: int, summary_data: SingleSessionSummaryData, model_to_use: str
222+
session_id: str,
223+
user_id: int,
224+
summary_data: SingleSessionSummaryData,
225+
model_to_use: str,
226+
*,
227+
user_distinct_id_to_log: str | None = None,
222228
) -> SingleSessionSummaryLlmInputs:
223229
# Checking here instead of in the preparation function to keep mypy happy
224230
if summary_data.prompt_data is None:
@@ -241,6 +247,7 @@ def prepare_single_session_summary_input(
241247
input_data = SingleSessionSummaryLlmInputs(
242248
session_id=session_id,
243249
user_id=user_id,
250+
user_distinct_id_to_log=user_distinct_id_to_log,
244251
summary_prompt=summary_data.prompt.summary_prompt,
245252
system_prompt=summary_data.prompt.system_prompt,
246253
simplified_events_mapping=summary_data.prompt_data.simplified_events_mapping,

ee/hogai/session_summaries/tests/test_summarize_session.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_execute_summarize_session_stream_success(
4848
# Get the generator (stream simulation)
4949
empty_context = ExtraSummaryContext()
5050
result_generator = execute_summarize_session_stream(
51-
session_id=mock_session_id, user_id=mock_user.id, team=mock_team, extra_summary_context=empty_context
51+
session_id=mock_session_id, user=mock_user, team=mock_team, extra_summary_context=empty_context
5252
)
5353
# Get all results from generator (consume the stream fully)
5454
results = list(result_generator)
@@ -124,14 +124,14 @@ async def test_stream_recording_summary_asgi(
124124
return_value=iter([ready_summary]),
125125
) as mock_execute,
126126
):
127-
async_gen = stream_recording_summary(session_id=mock_session_id, user_id=mock_user.id, team=mock_team)
127+
async_gen = stream_recording_summary(session_id=mock_session_id, user=mock_user, team=mock_team)
128128
assert isinstance(async_gen, SyncIterableToAsync)
129129
results = [chunk async for chunk in async_gen]
130130
assert len(results) == 1
131131
assert results[0] == ready_summary
132132
mock_execute.assert_called_once_with(
133133
session_id=mock_session_id,
134-
user_id=mock_user.id,
134+
user=mock_user,
135135
team=mock_team,
136136
extra_summary_context=None,
137137
local_reads_prod=False,
@@ -155,13 +155,13 @@ def test_stream_recording_summary_wsgi(
155155
return_value=iter([ready_summary]),
156156
) as mock_execute,
157157
):
158-
result_gen = stream_recording_summary(session_id=mock_session_id, user_id=mock_user.id, team=mock_team)
158+
result_gen = stream_recording_summary(session_id=mock_session_id, user=mock_user, team=mock_team)
159159
results = list(result_gen) # type: ignore[arg-type]
160160
assert len(results) == 1
161161
assert results[0] == ready_summary
162162
mock_execute.assert_called_once_with(
163163
session_id=mock_session_id,
164-
user_id=mock_user.id,
164+
user=mock_user,
165165
team=mock_team,
166166
extra_summary_context=None,
167167
local_reads_prod=False,

ee/hogai/tools/replay/summarize_sessions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ async def _summarize(session_id: str) -> dict[str, Any]:
459459
nonlocal completed
460460
result = await execute_summarize_session(
461461
session_id=session_id,
462-
user_id=self._user.id,
462+
user=self._user,
463463
team=self._team,
464464
model_to_use=SESSION_SUMMARIES_SYNC_MODEL,
465465
video_validation_enabled=video_validation_enabled,
@@ -496,7 +496,7 @@ async def _summarize_sessions_as_group(
496496

497497
async for update_type, data in execute_summarize_session_group(
498498
session_ids=session_ids,
499-
user_id=self._user.id,
499+
user=self._user,
500500
team=self._team,
501501
min_timestamp=min_timestamp,
502502
max_timestamp=max_timestamp,

ee/tasks/subscriptions/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
send_slack_message_with_integration_async,
2424
send_slack_subscription_report,
2525
)
26-
from ee.tasks.subscriptions.subscription_utils import generate_assets, generate_assets_async
26+
from ee.tasks.subscriptions.subscription_utils import _has_asset_failed, generate_assets, generate_assets_async
2727

2828
logger = structlog.get_logger(__name__)
2929

@@ -141,6 +141,9 @@ async def deliver_subscription_report_async(
141141
"deliver_subscription_report_async.assets_generated", subscription_id=subscription_id, asset_count=len(assets)
142142
)
143143

144+
if any(_has_asset_failed(asset) for asset in assets):
145+
get_subscription_failure_metric(subscription.target_type, "temporal", failure_type="asset_generation").add(1)
146+
144147
if not assets:
145148
logger.warning("deliver_subscription_report_async.no_assets", subscription_id=subscription_id)
146149
capture_exception(Exception("No assets are in this subscription"), {"subscription_id": subscription.id})

posthog/session_recordings/session_recording_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ def summarize(self, request: request.Request, **kwargs):
12581258
# If you want to test sessions locally - override `session_id` and `self.team.pk`
12591259
# with session/team ids of your choice and set `local_reads_prod` to True
12601260
return StreamingHttpResponse(
1261-
stream_recording_summary(session_id=session_id, user_id=user.pk, team=self.team),
1261+
stream_recording_summary(session_id=session_id, user=user, team=self.team),
12621262
content_type=ServerSentEventRenderer.media_type,
12631263
)
12641264

posthog/tasks/exports/image_exporter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,30 +205,30 @@ def _screenshot_asset(
205205

206206
try:
207207
WebDriverWait(driver, timeout).until(lambda x: x.find_element(By.CSS_SELECTOR, wait_for_css_selector))
208-
except TimeoutException:
208+
except TimeoutException as e:
209209
with posthoganalytics.new_context():
210210
posthoganalytics.tag("stage", "image_exporter.page_load_timeout")
211211
try:
212212
driver.save_screenshot(image_path)
213213
posthoganalytics.tag("image_path", image_path)
214214
except Exception:
215215
pass
216-
capture_exception()
216+
capture_exception(e)
217217

218218
raise Exception(f"Timeout while waiting for the page to load")
219219

220220
try:
221221
# Also wait until nothing is loading
222222
WebDriverWait(driver, 20).until_not(lambda x: x.find_element(By.CLASS_NAME, "Spinner"))
223-
except TimeoutException:
223+
except TimeoutException as e:
224224
with posthoganalytics.new_context():
225225
posthoganalytics.tag("stage", "image_exporter.wait_for_spinner_timeout")
226226
try:
227227
driver.save_screenshot(image_path)
228228
posthoganalytics.tag("image_path", image_path)
229229
except Exception:
230230
pass
231-
capture_exception()
231+
capture_exception(e)
232232

233233
# Get the height of the visualization container specifically
234234
height = driver.execute_script(

0 commit comments

Comments
 (0)