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(aio): show a newly created eval in the evals list (#81915)

Radu Raicea81a81cf33641
diff --git a/products/ai_observability/frontend/evaluations/AIObservabilityEvaluationsScene.test.tsx b/products/ai_observability/frontend/evaluations/AIObservabilityEvaluationsScene.test.tsx
new file mode 100644
index 000000000000..64fb0ab5e673
--- /dev/null
+++ b/products/ai_observability/frontend/evaluations/AIObservabilityEvaluationsScene.test.tsx
@@ -0,0 +1,48 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render } from '@testing-library/react'
+import { Provider } from 'kea'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { AIObservabilityEvaluationsScene } from './AIObservabilityEvaluationsScene'
+import { llmEvaluationsLogic } from './llmEvaluationsLogic'
+
+describe('AIObservabilityEvaluationsScene', () => {
+ beforeEach(() => {
+ useMocks({
+ get: {
+ '/api/environments/:teamId/llm_analytics/provider_keys/': { results: [] },
+ '/api/environments/:teamId/llm_analytics/evaluation_config/': {
+ active_provider_key: null,
+ created_at: '2024-01-01T00:00:00Z',
+ updated_at: '2024-01-01T00:00:00Z',
+ },
+ '/api/projects/:teamId/evaluations/': { results: [] },
+ '/api/projects/:teamId/evaluation_directories/': [],
+ },
+ })
+ initKeaTests()
+ })
+
+ afterEach(() => {
+ cleanup()
+ })
+
+ it('releases the evaluations logic when the scene exits, so the next visit refetches', () => {
+ const evaluationsLogic = llmEvaluationsLogic()
+ const unmountSceneLogic = evaluationsLogic.mount() // what SceneExport.logic does
+
+ const { unmount } = render(
+ <Provider>
+ <AIObservabilityEvaluationsScene />
+ </Provider>
+ )
+
+ unmount()
+ unmountSceneLogic()
+
+ expect(evaluationsLogic.isMounted()).toBe(false)
+ })
+})
diff --git a/products/ai_observability/frontend/evaluations/AIObservabilityEvaluationsScene.tsx b/products/ai_observability/frontend/evaluations/AIObservabilityEvaluationsScene.tsx
index d8328fe5d438..11396888c358 100644
--- a/products/ai_observability/frontend/evaluations/AIObservabilityEvaluationsScene.tsx
+++ b/products/ai_observability/frontend/evaluations/AIObservabilityEvaluationsScene.tsx
@@ -35,7 +35,6 @@ import { FEATURE_FLAGS } from 'lib/constants'
import { LemonTableColumns } from 'lib/lemon-ui/LemonTable'
import { ProfilePicture } from 'lib/lemon-ui/ProfilePicture'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
-import { useAttachedLogic } from 'lib/logic/scenes/useAttachedLogic'
import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'
import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import { fullName } from 'lib/utils/strings'
@@ -737,13 +736,14 @@ function AIObservabilityEvaluationsContent(): JSX.Element {
export function AIObservabilityEvaluationsScene(): JSX.Element {
const { searchParams, location } = useValues(router)
const { featureFlags } = useValues(featureFlagLogic)
- const evaluationsLogic = useMountedLogic(llmEvaluationsLogic())
- const metricsLogic = evaluationMetricsLogic()
+ useMountedLogic(llmEvaluationsLogic())
+ // Mount for this component's lifetime rather than attaching to llmEvaluationsLogic:
+ // evaluationMetricsLogic connects to it, so attaching leaves the two holding each
+ // other mounted, and the list never reloads on the next visit to this scene.
+ useMountedLogic(evaluationMetricsLogic())
const showOfflineEvals = !!featureFlags[FEATURE_FLAGS.LLM_ANALYTICS_OFFLINE_EVALS]
const activeTab = getActiveTab(location.pathname, searchParams, showOfflineEvals)
- useAttachedLogic(metricsLogic, evaluationsLogic)
-
const tabs: LemonTab<string>[] = [
{
key: 'online-evals',
diff --git a/products/ai_observability/frontend/evaluations/llmEvaluationLogic.test.ts b/products/ai_observability/frontend/evaluations/llmEvaluationLogic.test.ts
index babc0d061907..fe50437e3b6c 100644
--- a/products/ai_observability/frontend/evaluations/llmEvaluationLogic.test.ts
+++ b/products/ai_observability/frontend/evaluations/llmEvaluationLogic.test.ts
@@ -11,6 +11,7 @@ import { LLMProviderKey, llmProviderKeysLogic } from '../settings/llmProviderKey
import { EVALUATION_SUMMARY_MAX_RUNS } from './constants'
import { evaluationReportLogic } from './evaluationReportLogic'
import { DEFAULT_HOG_SOURCE, llmEvaluationLogic } from './llmEvaluationLogic'
+import { llmEvaluationsLogic } from './llmEvaluationsLogic'
import { EvaluationConfig, EvaluationReport, EvaluationRun } from './types'
const mockProviderKeys: LLMProviderKey[] = [
@@ -1515,6 +1516,46 @@ return result`,
})
})
+ describe('saveEvaluation list refresh', () => {
+ it('reloads the evaluations list so it shows the eval just created', async () => {
+ const pushSpy = jest.spyOn(router.actions, 'push').mockImplementation(() => {})
+ let evaluationListCount = 0
+
+ useMocks({
+ get: {
+ '/api/projects/:teamId/evaluations/': () => {
+ evaluationListCount += 1
+ return { results: evaluationListCount === 1 ? [] : [mockSentimentEvaluation] }
+ },
+ '/api/projects/:teamId/evaluation_directories/': [],
+ },
+ post: {
+ '/api/projects/:teamId/evaluations/': () => mockSentimentEvaluation,
+ },
+ })
+
+ const evaluationsLogic = llmEvaluationsLogic()
+ evaluationsLogic.mount()
+
+ try {
+ await expectLogic(evaluationsLogic).toDispatchActions(['loadEvaluationsSuccess'])
+ expect(evaluationsLogic.values.evaluations).toEqual([])
+
+ logic = llmEvaluationLogic({ evaluationId: 'new', evaluationType: 'sentiment' })
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadEvaluationSuccess'])
+ logic.actions.setEvaluationName('Sentiment evaluation')
+ logic.actions.saveEvaluation()
+
+ await expectLogic(evaluationsLogic).toDispatchActions(['loadEvaluations', 'loadEvaluationsSuccess'])
+ expect(evaluationsLogic.values.evaluations).toHaveLength(1)
+ } finally {
+ pushSpy.mockRestore()
+ evaluationsLogic.unmount()
+ }
+ })
+ })
+
describe('saveEvaluation report persistence', () => {
it('does not create an evaluation when the report threshold is invalid', async () => {
let evaluationCreateCount = 0
diff --git a/products/ai_observability/frontend/evaluations/llmEvaluationLogic.ts b/products/ai_observability/frontend/evaluations/llmEvaluationLogic.ts
index bbc86413158f..1b44b34d5e4e 100644
--- a/products/ai_observability/frontend/evaluations/llmEvaluationLogic.ts
+++ b/products/ai_observability/frontend/evaluations/llmEvaluationLogic.ts
@@ -36,6 +36,7 @@ import {
import { EvaluationBackTarget, getEvaluationBackTarget } from './evaluationNavigation'
import { evaluationReportLogic, persistReportDraft } from './evaluationReportLogic'
import { getHogEvalExample } from './hogEvalExamples'
+import { llmEvaluationsLogic } from './llmEvaluationsLogic'
import { EvaluationTemplateKey, defaultEvaluationTemplates } from './templates'
import type {
EvaluationConditionSet,
@@ -1106,6 +1107,9 @@ export const llmEvaluationLogic = kea<llmEvaluationLogicType>([
values.evaluation as Parameters<typeof evaluationsPartialUpdate>[2]
)) as unknown as EvaluationConfig
actions.saveEvaluationSuccess(response)
+ // The list and the self-driving table read from llmEvaluationsLogic, which only
+ // fetches on mount. Refresh it here so they show the eval we just saved.
+ llmEvaluationsLogic.findMounted()?.actions.loadEvaluations()
if (isNew) {
globalSetupLogic.findMounted()?.actions.markTaskAsCompleted(SetupTaskId.SetUpLlmEvaluation)
}