: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(posthog-ai): load run history through a log_entries alias route (#125577)
Shy Alter42ffab7c2fd5
diff --git a/frontend/src/lib/api.test.ts b/frontend/src/lib/api.test.tsindex 8d820aa8306d..f3f635deb9a9 100644--- a/frontend/src/lib/api.test.ts+++ b/frontend/src/lib/api.test.ts@@ -85,7 +85,7 @@ describe('API helper', () => {expect(fakeFetch).toHaveBeenCalledWith(path === 'proxy'? 'https://example.com/v1/runs/run-1/stream?resync=1'- : `/api/projects/123/tasks/task-1/runs/run-1/${path === 'history' ? 'logs' : 'stream'}/`,+ : `/api/projects/123/tasks/task-1/runs/run-1/${path === 'history' ? 'log_entries' : 'stream'}/`,expect.objectContaining({signal: controller.signal,...(path !== 'history' ? { headers: streamHeaders } : {}),diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.tsindex 22b3f5276209..470b5db67d9b 100644--- a/frontend/src/lib/api.ts+++ b/frontend/src/lib/api.ts@@ -5064,7 +5064,7 @@ const api = {): Promise<Record<string, any>[]> {const response = await new ApiRequest().taskRun(taskId, runId, options.projectId)- .withAction('logs')+ .withAction('log_entries').getResponse({ signal: options.signal })return parseLogEntries(await response.text())},@@ -5098,7 +5098,7 @@ const api = {}> {const response = await new ApiRequest().taskRun(taskId, runId, options.projectId)- .withAction('logs')+ .withAction('log_entries').withQueryString({...(options.tailBytes !== undefined ? { tail_bytes: options.tailBytes } : {}),...(options.before !== undefined ? { before: options.before } : {}),diff --git a/frontend/src/scenes/max/PostHogAiQuillComparison.stories.tsx b/frontend/src/scenes/max/PostHogAiQuillComparison.stories.tsxindex f5687588671a..1c4db69f87b8 100644--- a/frontend/src/scenes/max/PostHogAiQuillComparison.stories.tsx+++ b/frontend/src/scenes/max/PostHogAiQuillComparison.stories.tsx@@ -69,9 +69,9 @@ const meta: Meta = {results: [comparisonRun()],},[`/api/projects/:team_id/tasks/${COMPARISON_TASK_ID}/runs/${COMPARISON_RUN_ID}/`]: comparisonRun(),- [`/api/projects/:team_id/tasks/${COMPARISON_TASK_ID}/runs/${COMPARISON_RUN_ID}/logs`]: () =>+ [`/api/projects/:team_id/tasks/${COMPARISON_TASK_ID}/runs/${COMPARISON_RUN_ID}/log_entries`]: () =>new HttpResponse(comparisonRunLogBody()),- [`/api/projects/:team_id/tasks/${COMPARISON_TASK_ID}/runs/${COMPARISON_RUN_ID}/logs/`]: () =>+ [`/api/projects/:team_id/tasks/${COMPARISON_TASK_ID}/runs/${COMPARISON_RUN_ID}/log_entries/`]: () =>new HttpResponse(comparisonRunLogBody()),'/api/users/@me/': () => [200, { ...MOCK_DEFAULT_BASIC_USER, is_staff: false }],},diff --git a/posthog/settings/web.py b/posthog/settings/web.pyindex 36a9c51c3495..d520fc43bccb 100644--- a/posthog/settings/web.py+++ b/posthog/settings/web.py@@ -919,7 +919,7 @@ GZIP_RESPONSE_ALLOW_LIST = get_list("^/api/organizations/@current/plugins/?$","^api/(environments|projects)/@current/feature_flags/my_flags/?$","^/?api/(environments|projects)/\\d+/query/?$",- "^/?api/(environments|projects)/\\d+/tasks/[0-9a-fA-F-]+/runs/[^/]+/(logs|session_logs)/?$",+ "^/?api/(environments|projects)/\\d+/tasks/[0-9a-fA-F-]+/runs/[^/]+/(logs|log_entries|session_logs)/?$",# Deploy-static source catalog (no user input or secrets reflected): several# hundred KB of JSON that compresses ~7x."^/?api/(environments|projects)/(\\d+|@current)/external_data_sources/wizard/?$",diff --git a/posthog/test/test_gzip_middleware.py b/posthog/test/test_gzip_middleware.pyindex d75dec4aba58..13f6e0a94432 100644--- a/posthog/test/test_gzip_middleware.py+++ b/posthog/test/test_gzip_middleware.py@@ -56,6 +56,8 @@ class TestGzipAllowList(SimpleTestCase):@parameterized.expand([("logs", "logs/", True),+ ("log_entries", "log_entries/", True),+ ("log_entries_without_slash", "log_entries", True),("session_logs", "session_logs/", True),("sse_stream", "stream/", False),("stream_token", "stream_token/", False),diff --git a/products/posthog_ai/frontend/e2e/run-surface.spec.ts b/products/posthog_ai/frontend/e2e/run-surface.spec.tsindex 6961ab540341..92f8259a778d 100644--- a/products/posthog_ai/frontend/e2e/run-surface.spec.ts+++ b/products/posthog_ai/frontend/e2e/run-surface.spec.ts@@ -111,8 +111,8 @@ async function routeTasksApi(page: Page, mock: TasksApiMock): Promise<void> {const runsRe = new RegExp(`/tasks/${TASK_ID}/runs/$`)const runRe = new RegExp(`/tasks/${TASK_ID}/runs/${RUN_ID}/$`)const tokenRe = new RegExp(`/runs/${RUN_ID}/stream_token/$`)- // A paged read (`.../logs?tail_bytes=...`) has no trailing slash either, like the `stream` action below.- const logsRe = new RegExp(`/runs/${RUN_ID}/logs/?$`)+ // A paged read (`.../log_entries?tail_bytes=...`) has no trailing slash either, like the `stream` action below.+ const logsRe = new RegExp(`/runs/${RUN_ID}/log_entries/?$`)// The `stream` action URL has no trailing slash (`.../stream?start=latest`), unlike the other// resource paths — match it with an optional slash so the route intercepts instead of falling through// to the real backend (a fall-through 404s the fake run id and masks the clean-EOF drop under test).diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsxindex 823fa5b82b4c..4b601f329825 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx@@ -397,7 +397,7 @@ function taskMocks(},[`/api/projects/:team_id/tasks/${TASK_ID}/runs/${RUN_ID}/`]: run,[`/api/projects/:team_id/tasks/${TASK_ID}/runs/${EARLIER_RUN_ID}/`]: earlierRun,- [`/api/projects/:team_id/tasks/${TASK_ID}/runs/${RUN_ID}/logs`]: () => new HttpResponse(logs),+ [`/api/projects/:team_id/tasks/${TASK_ID}/runs/${RUN_ID}/log_entries`]: () => new HttpResponse(logs),[`/api/projects/:team_id/tasks/${TASK_ID}/runs/:run_id/artifacts/artifact-chart/download/`]: () =>new HttpResponse(CHART_SVG, { headers: { 'Content-Type': 'image/svg+xml' } }),[`/api/projects/:team_id/tasks/${TASK_ID}/runs/:run_id/artifacts/:artifact_id/preview/`]: {diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsxindex 9d26e464aa58..046a6bf6028a 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsx@@ -342,7 +342,7 @@ export const CloudTaskSelected: Story = {results: [TASK_1_RUN],},'/api/projects/:team_id/tasks/task-1/runs/run-task-1/': TASK_1_RUN,- '/api/projects/:team_id/tasks/task-1/runs/run-task-1/logs': () =>+ '/api/projects/:team_id/tasks/task-1/runs/run-task-1/log_entries': () =>new HttpResponse(JSON.stringify({type: 'notification',@@ -381,7 +381,7 @@ export const PiTaskSelected: Story = {results: [PI_TASK_RUN],},'/api/projects/:team_id/tasks/task-4/runs/run-task-4/': PI_TASK_RUN,- '/api/projects/:team_id/tasks/task-4/runs/run-task-4/logs': () =>+ '/api/projects/:team_id/tasks/task-4/runs/run-task-4/log_entries': () =>new HttpResponse(PI_TASK_LOG.map((entry) => JSON.stringify(entry)).join('\n')),},}),diff --git a/products/signals/frontend/inbox/__mocks__/inboxMocks.ts b/products/signals/frontend/inbox/__mocks__/inboxMocks.tsindex aa056737e931..258a80491d8e 100644--- a/products/signals/frontend/inbox/__mocks__/inboxMocks.ts+++ b/products/signals/frontend/inbox/__mocks__/inboxMocks.ts@@ -529,7 +529,7 @@ export function mockTaskRun(taskId: string, runId: string): any {}/**- * A single-message agent run log as JSONL — what the `/runs/:runId/logs` endpoint returns (one+ * A single-message agent run log as JSONL — what the `/runs/:runId/log_entries` endpoint returns (one* `StoredLogEntry` per line). One `agent_message` frame so the run viewer renders a single assistant* bubble instead of the "conversation backing run not found" error.*/diff --git a/products/signals/frontend/inbox/components/detail/InboxDetail.stories.tsx b/products/signals/frontend/inbox/components/detail/InboxDetail.stories.tsxindex f81cff0cef73..7cae477d9d0f 100644--- a/products/signals/frontend/inbox/components/detail/InboxDetail.stories.tsx+++ b/products/signals/frontend/inbox/components/detail/InboxDetail.stories.tsx@@ -152,7 +152,7 @@ const detailMocks = mswDecorator({200,mockTaskRun(req.params.taskId as string, req.params.runId as string),],- '/api/projects/:id/tasks/:taskId/runs/:runId/logs': () => new HttpResponse(mockRunLog()),+ '/api/projects/:id/tasks/:taskId/runs/:runId/log_entries': () => new HttpResponse(mockRunLog()),},post: {'/api/environments/:team_id/query/:kind/': reportMetricQueryHandler,diff --git a/products/signals/frontend/inbox/components/emptyState/FirstReportProgress.stories.tsx b/products/signals/frontend/inbox/components/emptyState/FirstReportProgress.stories.tsxindex d10eb1688144..a00cf802e7bb 100644--- a/products/signals/frontend/inbox/components/emptyState/FirstReportProgress.stories.tsx+++ b/products/signals/frontend/inbox/components/emptyState/FirstReportProgress.stories.tsx@@ -29,7 +29,7 @@ const meta: Meta<typeof FirstReportProgress> = {get: {'/api/projects/:id/tasks/:taskId': [200, mockTask('task-1', 'completed')],'/api/projects/:id/tasks/:taskId/runs/:runId': [200, mockTaskRun('task-1', 'run-1')],- '/api/projects/:id/tasks/:taskId/runs/:runId/logs': () => new HttpResponse(mockRunLog()),+ '/api/projects/:id/tasks/:taskId/runs/:runId/log_entries': () => new HttpResponse(mockRunLog()),},}),],diff --git a/products/tasks/backend/presentation/views/api.py b/products/tasks/backend/presentation/views/api.pyindex 4a00ab238f37..3ab427ae2b85 100644--- a/products/tasks/backend/presentation/views/api.py+++ b/products/tasks/backend/presentation/views/api.py@@ -2096,6 +2096,7 @@ class TaskRunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):"list","retrieve","logs",+ "log_entries","session_logs","task_session","stream",@@ -3451,6 +3452,14 @@ class TaskRunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):)@action(detail=True, methods=["get"], url_path="logs", required_scopes=["task:read"])def logs(self, request, pk=None, **kwargs):+ return self._logs_response(request, pk)++ @validated_request(query_serializer=TaskRunLogsQuerySerializer, exclude=True)+ @action(detail=True, methods=["get"], url_path="log_entries", required_scopes=["task:read"])+ def log_entries(self, request, pk=None, **kwargs):+ return self._logs_response(request, pk)++ def _logs_response(self, request, pk) -> HttpResponse:task_id = self._ensure_task_accessible()query = request.validated_query_datatimer = ServerTimingsGathered()diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.pyindex c66d132944cb..12389644fb21 100644--- a/products/tasks/backend/tests/test_api.py+++ b/products/tasks/backend/tests/test_api.py@@ -11314,14 +11314,16 @@ class TestTaskRunAPI(BaseTaskAPITest):@parameterized.expand([- ("default_keeps_the_copy", "", status.HTTP_200_OK, True),- ("thread_drops_the_copy", "?view=thread", status.HTTP_200_OK, False),- ("thread_drops_the_copy_from_a_page", "?tail_bytes=1&view=thread", status.HTTP_200_OK, False),- ("unknown_view_rejected", "?view=compact", status.HTTP_400_BAD_REQUEST, None),+ ("default_keeps_the_copy", "logs/", status.HTTP_200_OK, True),+ ("thread_drops_the_copy", "logs/?view=thread", status.HTTP_200_OK, False),+ ("thread_drops_the_copy_from_a_page", "logs/?tail_bytes=1&view=thread", status.HTTP_200_OK, False),+ ("unknown_view_rejected", "logs/?view=compact", status.HTTP_400_BAD_REQUEST, None),+ ("log_entries_drops_the_copy", "log_entries?view=thread", status.HTTP_200_OK, False),+ ("log_entries_rejects_unknown_view", "log_entries?view=compact", status.HTTP_400_BAD_REQUEST, None),])@patch("posthog.storage.object_storage.read")- def test_logs_endpoint_view(self, _name: str, query: str, expected_status: int, has_copy: bool | None, mock_read):+ def test_logs_endpoint_view(self, _name: str, path: str, expected_status: int, has_copy: bool | None, mock_read):task = self.create_task()run = TaskRun.objects.create(task=task, team=self.team)entry = {@@ -11332,10 +11334,11 @@ class TestTaskRunAPI(BaseTaskAPITest):}mock_read.side_effect = lambda path, missing_ok=False: json.dumps(entry) + "\n" if path == run.log_url else None- response = self.client.get(f"/api/projects/@current/tasks/{task.id}/runs/{run.id}/logs/{query}")+ response = self.client.get(f"/api/projects/@current/tasks/{task.id}/runs/{run.id}/{path}")self.assertEqual(response.status_code, expected_status)if has_copy is not None:+ self.assertEqual(response["Cache-Control"], "no-cache")claude_code = json.loads(response.content.decode("utf-8").splitlines()[0])["notification"]["params"]["update"]["_meta"]["claudeCode"]