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(experiments): load history tab from experiment activity endpoint (#87906)

Juraj Majerik7097c81683dd
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts
index a70bcc61e431..51b070320257 100644
--- a/frontend/src/lib/api.ts
+++ b/frontend/src/lib/api.ts
@@ -2669,6 +2669,16 @@ const api = {
): Promise<ActivityLogPaginatedResponse<ActivityLogItem>> {
const scopes = Array.isArray(props.scope) ? [...props.scope] : [props.scope]
+ // The experiment activity endpoint merges in entries from the experiment's holdout
+ // and shared metrics, which the generic /activity_log scope+item_id filter can't express.
+ if (scopes.length === 1 && scopes[0] === ActivityScope.EXPERIMENT && props.id) {
+ return new ApiRequest()
+ .experimentsDetail(props.id as number, projectId)
+ .withAction('activity')
+ .withQueryString(toParams({ page: page || 1, limit: ACTIVITY_PAGE_SIZE }))
+ .get()
+ }
+
// Opt into the new /activity_log API
if (
[
diff --git a/frontend/src/lib/components/ActivityLog/activityLogLogic.experiment.test.tsx b/frontend/src/lib/components/ActivityLog/activityLogLogic.experiment.test.tsx
new file mode 100644
index 000000000000..8917d2264884
--- /dev/null
+++ b/frontend/src/lib/components/ActivityLog/activityLogLogic.experiment.test.tsx
@@ -0,0 +1,40 @@
+import { MOCK_TEAM_ID } from 'lib/api.mock'
+
+import '@testing-library/jest-dom'
+
+import { render } from '@testing-library/react'
+
+import { ActivityScope } from '~/types'
+
+import { makeTestSetup } from './activityLogLogic.test.setup'
+
+describe('the activity log logic', () => {
+ describe('humanizing experiments', () => {
+ // Guards the routing: a single experiment's activity must come from the experiment's
+ // own /activity endpoint (which merges holdout and shared-metric entries), not the
+ // generic /activity_log endpoint. If routing regresses, this mock is never hit and
+ // the log renders empty.
+ const experimentTestSetup = makeTestSetup(
+ ActivityScope.EXPERIMENT,
+ `/api/projects/${MOCK_TEAM_ID}/experiments/7/activity/`
+ )
+
+ it('fetches from the experiment activity endpoint and humanizes a launch', async () => {
+ const logic = await experimentTestSetup('my experiment', 'updated', [
+ {
+ type: ActivityScope.EXPERIMENT,
+ action: 'created',
+ field: 'start_date',
+ before: null,
+ after: '2024-01-01T00:00:00Z',
+ },
+ ])
+
+ const actual = logic.values.humanizedActivity
+ const text = render(<>{actual[0].description}</>).container.textContent
+ expect(text).toContain('peter')
+ expect(text).toContain('launched experiment')
+ expect(text).toContain('my experiment')
+ })
+ })
+})