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): stop the trace summary panel from claiming no project access (#100316)

posthog[bot]7d63a03b739a
diff --git a/products/ai_observability/frontend/summary-view/summaryViewLogic.test.ts b/products/ai_observability/frontend/summary-view/summaryViewLogic.test.ts
index 455c24c62b3a..678c9121a303 100644
--- a/products/ai_observability/frontend/summary-view/summaryViewLogic.test.ts
+++ b/products/ai_observability/frontend/summary-view/summaryViewLogic.test.ts
@@ -1,3 +1,5 @@
+import { MOCK_DEFAULT_ORGANIZATION } from 'lib/api.mock'
+
import { expectLogic } from 'kea-test-utils'
import posthog from 'posthog-js'
@@ -7,6 +9,7 @@ import { ApiError, NETWORK_ERROR_MESSAGES, NetworkError } from 'lib/api-error'
import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'
import type { LLMTrace } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
+import { AccessControlLevel, AccessControlResourceType, AppContext } from '~/types'
import { summaryViewLogic } from './summaryViewLogic'
@@ -80,6 +83,24 @@ describe('summaryViewLogic', () => {
}).toFinishAllListeners()
}
+ /**
+ * Consent approved and a chosen access level on `llm_analytics`, which is what decides whether
+ * the panel looks for a cached summary when it mounts.
+ */
+ function initWithSummarizationAccess(level: AccessControlLevel): void {
+ initKeaTests(true, undefined, undefined, {
+ ...MOCK_DEFAULT_ORGANIZATION,
+ is_ai_data_processing_approved: true,
+ })
+ window.POSTHOG_APP_CONTEXT = {
+ ...window.POSTHOG_APP_CONTEXT,
+ resource_access_control: {
+ ...window.POSTHOG_APP_CONTEXT?.resource_access_control,
+ [AccessControlResourceType.LlmAnalytics]: level,
+ },
+ } as AppContext
+ }
+
beforeEach(() => {
silenceKeaLoadersErrors()
initKeaTests()
@@ -202,6 +223,22 @@ describe('summaryViewLogic', () => {
expect(summarizationOptions().at(-1)?.signal?.aborted).toBe(true)
})
+ // Reading a trace needs the read level, and the cached-summary lookup is a POST, so it needs
+ // the write level. Without the guard the panel opens a readable trace with a denial banner.
+ test.each([
+ [AccessControlLevel.Editor, 1],
+ [AccessControlLevel.Viewer, 0],
+ ])('mounting with %s access sends %i cached-summary request(s)', async (level, expectedRequests) => {
+ initWithSummarizationAccess(level)
+
+ logic = summaryViewLogic({ trace, tree: [] })
+ logic.mount()
+ await flushMicrotasks()
+
+ expect(summarizationOptions()).toHaveLength(expectedRequests)
+ expect(logic.values.summaryError).toBeNull()
+ })
+
it('clears a stale summary when regeneration fails', async () => {
await generateSummary()
expect(logic.values.summaryData?.summary.title).toBe('Summary')
diff --git a/products/ai_observability/frontend/summary-view/summaryViewLogic.ts b/products/ai_observability/frontend/summary-view/summaryViewLogic.ts
index a163cb314fac..a669cc2d2591 100644
--- a/products/ai_observability/frontend/summary-view/summaryViewLogic.ts
+++ b/products/ai_observability/frontend/summary-view/summaryViewLogic.ts
@@ -3,10 +3,12 @@ import { loaders } from 'kea-loaders'
import { isAbortError } from 'lib/api'
import { ApiError, NetworkError, isTransientServerError } from 'lib/api-error'
+import { userHasAccess } from 'lib/utils/accessControlUtils'
import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'
import { teamLogic } from 'scenes/teamLogic'
import { LLMTrace, LLMTraceEvent } from '~/queries/schema/schema-general'
+import { AccessControlLevel, AccessControlResourceType } from '~/types'
import { EnrichedTraceTreeNode } from '../aiObservabilityTraceDataLogic'
import { llmAnalyticsSummarizationCreate } from '../generated/api'
@@ -105,6 +107,15 @@ export type summaryViewLogicType = MakeLogicType<
summaryViewLogicMeta
>
+/**
+ * Summarizing is a POST, so access control asks for the write level on `llm_analytics`, while
+ * reading the trace asks only for the read level. A user who can open the trace can still be
+ * refused here.
+ */
+function canSummarize(): boolean {
+ return userHasAccess(AccessControlResourceType.LlmAnalytics, AccessControlLevel.Editor)
+}
+
const GENERIC_SUMMARY_ERROR = "Couldn't generate a summary. Try again, and if it keeps happening contact support."
const NETWORK_SUMMARY_ERROR = 'Lost the connection while generating this summary. Check your connection and try again.'
@@ -331,10 +342,15 @@ export const summaryViewLogic = kea<summaryViewLogicType>([
},
})),
afterMount(({ props, actions, values }) => {
- if (props.autoGenerate && values.dataProcessingAccepted) {
+ // The cached-summary lookup is a POST too, so a user without the write level gets a denial
+ // on a trace they opened to read. Leave the panel on its empty state instead.
+ if (!values.dataProcessingAccepted || !canSummarize()) {
+ return
+ }
+ if (props.autoGenerate) {
// Auto-generate was requested (e.g., from URL param)
actions.generateSummary({ mode: values.summaryMode, forceRefresh: false })
- } else if (values.dataProcessingAccepted) {
+ } else {
// Try to load cached summary on mount (will use cache if available)
actions.loadCachedSummary()
}