: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(tasks): read session logs across the resume chain (#66719)
Alessandro Pogliaghie081fbe65110
diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.pyindex cfe16588d67f..73fcec4a373a 100644--- a/products/tasks/backend/facade/api.py+++ b/products/tasks/backend/facade/api.py@@ -148,7 +148,6 @@ __all__ = ["presign_task_run_artifact","read_task_run_artifact","read_task_run_logs",- "read_task_run_session_log_content","redeem_code_invite","refresh_team_code_workstreams","relay_task_run_message",@@ -1735,16 +1734,6 @@ def read_task_run_logs(run_id: str | UUID, task_id: str | UUID, team_id: int) ->return "".join(parts)-def read_task_run_session_log_content(run_id: str | UUID, task_id: str | UUID, team_id: int) -> str | None:- """Raw session-log JSONL for a run. ``None`` if the run isn't found."""- from posthog.storage import object_storage # noqa: PLC0415 — keep storage deps off the api import path-- run = _get_visible_run(run_id, task_id, team_id)- if run is None:- return None- return object_storage.read(run.log_url, missing_ok=True) or ""--def create_task_run_connection_token(run_id: str | UUID, task_id: str | UUID, team_id: int, *, user_id: int, distinct_id: str) -> str | None:diff --git a/products/tasks/backend/presentation/views/api.py b/products/tasks/backend/presentation/views/api.pyindex 2185d4ad6245..cd944aebbcb4 100644--- a/products/tasks/backend/presentation/views/api.py+++ b/products/tasks/backend/presentation/views/api.py@@ -1559,7 +1559,7 @@ class TaskRunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):timer = ServerTimingsGathered()with timer("s3_read"):- log_content = tasks_facade.read_task_run_session_log_content(pk, task_id, self.team_id)+ log_content = tasks_facade.read_task_run_logs(pk, task_id, self.team_id)if log_content is None:raise NotFound()diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.pyindex f3f29893f8ce..b74d37a98621 100644--- a/products/tasks/backend/tests/test_api.py+++ b/products/tasks/backend/tests/test_api.py@@ -5426,6 +5426,44 @@ class TestTaskRunSessionLogsAPI(BaseTaskAPITest):self.assertEqual(response["X-Total-Count"], "0")self.assertEqual(response["X-Filtered-Count"], "0")+ def test_session_logs_walks_resume_chain(self):+ task = self.create_task()+ ancestor = TaskRun.objects.create(task=task, team=self.team, status=TaskRun.Status.COMPLETED)+ resumed = TaskRun.objects.create(+ task=task,+ team=self.team,+ status=TaskRun.Status.IN_PROGRESS,+ state={"resume_from_run_id": str(ancestor.id)},+ )++ self._seed_log(+ task,+ ancestor,+ [+ self._make_session_update_entry("user_message", "2026-01-01T00:00:01Z"),+ self._make_session_update_entry("agent_message", "2026-01-01T00:00:02Z"),+ ],+ )+ self._seed_log(+ task,+ resumed,+ [self._make_session_update_entry("agent_message", "2026-01-01T00:00:03Z")],+ )++ response = self.client.get(self._events_url(task, resumed))+ self.assertEqual(response.status_code, status.HTTP_200_OK)++ data = response.json()+ self.assertEqual(+ [e["notification"]["params"]["update"]["sessionUpdate"] for e in data],+ ["user_message", "agent_message", "agent_message"],+ )+ self.assertEqual(+ [e["timestamp"] for e in data],+ ["2026-01-01T00:00:01Z", "2026-01-01T00:00:02Z", "2026-01-01T00:00:03Z"],+ )+ self.assertEqual(response["X-Total-Count"], "3")+def test_session_logs_filter_by_event_types(self):task = self.create_task()run = TaskRun.objects.create(task=task, team=self.team, status=TaskRun.Status.IN_PROGRESS)