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(max): stop feedback prompt firing a false flag-missing error (#88932)

posthog[bot]f000ab1b5be1
diff --git a/frontend/src/scenes/max/feedbackPromptLogic.test.ts b/frontend/src/scenes/max/feedbackPromptLogic.test.ts
index dcb2e4969468..f9aba90a98d5 100644
--- a/frontend/src/scenes/max/feedbackPromptLogic.test.ts
+++ b/frontend/src/scenes/max/feedbackPromptLogic.test.ts
@@ -1,4 +1,5 @@
import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
import * as featureFlagLogic from 'lib/logic/featureFlagLogic'
@@ -258,6 +259,39 @@ describe('feedbackPromptLogic', () => {
})
})
+ describe('feedbackConfig flag-load race', () => {
+ function remountWithMissingPayload(): jest.SpyInstance {
+ jest.spyOn(featureFlagLogic, 'getFeatureFlagPayload').mockReturnValue(null)
+ const captureException = jest.spyOn(posthog, 'captureException').mockImplementation()
+ logic.unmount()
+ logic = feedbackPromptLogic({ conversationId: MOCK_CONVERSATION_ID })
+ logic.mount()
+ return captureException
+ }
+
+ it('stays silent before flags load, then recomputes once the payload arrives', () => {
+ const captureException = remountWithMissingPayload()
+
+ // Flags unresolved: a missing payload is the load-order race, not a real problem.
+ expect(logic.values.feedbackConfig).toBeNull()
+ expect(captureException).not.toHaveBeenCalled()
+
+ // Flags land with a valid payload: the selector recomputes instead of staying stuck at null.
+ jest.spyOn(featureFlagLogic, 'getFeatureFlagPayload').mockReturnValue(DEFAULT_CONFIG)
+ featureFlagLogic.featureFlagLogic.findMounted()?.actions.setFeatureFlags([], {})
+ expect(logic.values.feedbackConfig).toEqual(DEFAULT_CONFIG)
+ expect(captureException).not.toHaveBeenCalled()
+ })
+
+ it('reports the missing payload only once flags have loaded', () => {
+ const captureException = remountWithMissingPayload()
+ featureFlagLogic.featureFlagLogic.findMounted()?.actions.setFeatureFlags([], {})
+
+ expect(logic.values.feedbackConfig).toBeNull()
+ expect(captureException).toHaveBeenCalledTimes(1)
+ })
+ })
+
describe('per-conversation isolation', () => {
it('maintains separate state for different conversations', async () => {
const logic1 = feedbackPromptLogic({ conversationId: 'conversation-1' })
diff --git a/frontend/src/scenes/max/feedbackPromptLogic.ts b/frontend/src/scenes/max/feedbackPromptLogic.ts
index 53cefa710e9b..9e13f0ee23b9 100644
--- a/frontend/src/scenes/max/feedbackPromptLogic.ts
+++ b/frontend/src/scenes/max/feedbackPromptLogic.ts
@@ -1,8 +1,8 @@
-import { MakeLogicType, actions, kea, key, listeners, path, props, reducers, selectors } from 'kea'
+import { MakeLogicType, actions, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
import posthog from 'posthog-js'
import { FEATURE_FLAGS } from 'lib/constants'
-import { getFeatureFlagPayload } from 'lib/logic/featureFlagLogic'
+import { FeatureFlagsSet, featureFlagLogic, getFeatureFlagPayload } from 'lib/logic/featureFlagLogic'
import { maxThreadLogic } from './maxThreadLogic'
import { FeedbackRating, FeedbackTriggerType, captureFeedback } from './utils'
@@ -42,6 +42,8 @@ export interface FeedbackPromptLogicProps {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface feedbackPromptLogicValues {
+ featureFlags: FeatureFlagsSet // featureFlagLogic
+ receivedFeatureFlags: boolean // featureFlagLogic
canShowPrompt: boolean
currentTriggerType: FeedbackTriggerType
feedbackConfig: FeedbackConfig | null
@@ -105,6 +107,7 @@ export interface feedbackPromptLogicActions {
export interface feedbackPromptLogicMeta {
key: string
__keaTypeGenInternalSelectorTypes: {
+ feedbackConfig: (featureFlags: FeatureFlagsSet, receivedFeatureFlags: boolean) => FeedbackConfig | null
canShowPrompt: (feedbackConfig: FeedbackConfig | null) => boolean
messageInterval: (feedbackConfig: FeedbackConfig | null) => number
}
@@ -125,6 +128,10 @@ export const feedbackPromptLogic = kea<feedbackPromptLogicType>([
key((props) => props.conversationId),
+ connect({
+ values: [featureFlagLogic, ['featureFlags', 'receivedFeatureFlags']],
+ }),
+
actions({
submitRating: (rating: FeedbackRating) => ({ rating }),
completeDetailedFeedback: true,
@@ -190,14 +197,17 @@ export const feedbackPromptLogic = kea<feedbackPromptLogicType>([
selectors({
feedbackConfig: [
- () => [],
- (): FeedbackConfig | null => {
+ (s) => [s.featureFlags, s.receivedFeatureFlags],
+ (_featureFlags: FeatureFlagsSet, receivedFeatureFlags: boolean): FeedbackConfig | null => {
const payload = getFeatureFlagPayload(FEATURE_FLAGS.POSTHOG_AI_CONVERSATION_FEEDBACK_CONFIG)
if (!payload || typeof payload !== 'object') {
- posthog.captureException(
- new Error('POSTHOG_AI_CONVERSATION_FEEDBACK_CONFIG feature flag is not set'),
- { tags: { product: 'max_ai' } }
- )
+ // Before flags resolve the payload is simply absent; only a loaded-but-missing payload is a real problem.
+ if (receivedFeatureFlags) {
+ posthog.captureException(
+ new Error('POSTHOG_AI_CONVERSATION_FEEDBACK_CONFIG feature flag is not set'),
+ { tags: { product: 'max_ai' } }
+ )
+ }
return null
}
return {
diff --git a/products/posthog_ai/frontend/logics/feedbackPromptLogic.test.ts b/products/posthog_ai/frontend/logics/feedbackPromptLogic.test.ts
index 4c298bc06f83..f29d4aa3fba2 100644
--- a/products/posthog_ai/frontend/logics/feedbackPromptLogic.test.ts
+++ b/products/posthog_ai/frontend/logics/feedbackPromptLogic.test.ts
@@ -1,4 +1,5 @@
import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
import * as featureFlagLogic from 'lib/logic/featureFlagLogic'
@@ -103,6 +104,39 @@ describe('feedbackPromptLogic (sandbox)', () => {
})
})
+ describe('feedbackConfig flag-load race', () => {
+ function remountWithMissingPayload(): jest.SpyInstance {
+ jest.spyOn(featureFlagLogic, 'getFeatureFlagPayload').mockReturnValue(null)
+ const captureException = jest.spyOn(posthog, 'captureException').mockImplementation()
+ logic.unmount()
+ logic = feedbackPromptLogic(PROPS)
+ logic.mount()
+ return captureException
+ }
+
+ it('stays silent before flags load, then recomputes once the payload arrives', () => {
+ const captureException = remountWithMissingPayload()
+
+ // Flags unresolved: a missing payload is the load-order race, not a real problem.
+ expect(logic.values.feedbackConfig).toBeNull()
+ expect(captureException).not.toHaveBeenCalled()
+
+ // Flags land with a valid payload: the selector recomputes instead of staying stuck at null.
+ jest.spyOn(featureFlagLogic, 'getFeatureFlagPayload').mockReturnValue(DEFAULT_CONFIG)
+ featureFlagLogic.featureFlagLogic.findMounted()?.actions.setFeatureFlags([], {})
+ expect(logic.values.feedbackConfig).not.toBeNull()
+ expect(captureException).not.toHaveBeenCalled()
+ })
+
+ it('reports the missing payload only once flags have loaded', () => {
+ const captureException = remountWithMissingPayload()
+ featureFlagLogic.featureFlagLogic.findMounted()?.actions.setFeatureFlags([], {})
+
+ expect(logic.values.feedbackConfig).toBeNull()
+ expect(captureException).toHaveBeenCalledTimes(1)
+ })
+ })
+
it('records the cooldown timestamp when feedback is shown', () => {
const before = Date.now()
logic.actions.recordFeedbackShown()
diff --git a/products/posthog_ai/frontend/logics/feedbackPromptLogic.ts b/products/posthog_ai/frontend/logics/feedbackPromptLogic.ts
index 14dd8cd31b25..0f264d6a1ab7 100644
--- a/products/posthog_ai/frontend/logics/feedbackPromptLogic.ts
+++ b/products/posthog_ai/frontend/logics/feedbackPromptLogic.ts
@@ -2,7 +2,7 @@ import { MakeLogicType, actions, connect, kea, key, listeners, path, props, redu
import posthog from 'posthog-js'
import { FEATURE_FLAGS } from 'lib/constants'
-import { getFeatureFlagPayload } from 'lib/logic/featureFlagLogic'
+import { FeatureFlagsSet, featureFlagLogic, getFeatureFlagPayload } from 'lib/logic/featureFlagLogic'
import { FeedbackPromptRating, FeedbackPromptTrigger, RunRef, capturePromptFeedback } from '../utils/feedbackEvents'
import { computeTurnTrailers } from '../utils/turnTrailers'
@@ -51,6 +51,8 @@ function readStream(streamKey: string): StreamSnapshot {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface feedbackPromptLogicValues {
+ featureFlags: FeatureFlagsSet // featureFlagLogic
+ receivedFeatureFlags: boolean // featureFlagLogic
canShowPrompt: boolean
cancelCount: number
currentTriggerType: FeedbackPromptTrigger
@@ -127,6 +129,7 @@ export interface feedbackPromptLogicActions {
export interface feedbackPromptLogicMeta {
key: string
__keaTypeGenInternalSelectorTypes: {
+ feedbackConfig: (featureFlags: FeatureFlagsSet, receivedFeatureFlags: boolean) => FeedbackPromptConfig | null
canShowPrompt: (feedbackConfig: FeedbackPromptConfig | null) => boolean
messageInterval: (feedbackConfig: FeedbackPromptConfig | null) => number
}
@@ -150,6 +153,7 @@ export const feedbackPromptLogic = kea<feedbackPromptLogicType>([
key((props) => props.sessionId),
connect((props: FeedbackPromptLogicProps) => ({
+ values: [featureFlagLogic, ['featureFlags', 'receivedFeatureFlags']],
actions: [runStreamLogic({ streamKey: props.streamKey }), ['cancelRun']],
})),
@@ -224,14 +228,17 @@ export const feedbackPromptLogic = kea<feedbackPromptLogicType>([
selectors({
feedbackConfig: [
- () => [],
- (): FeedbackPromptConfig | null => {
+ (s) => [s.featureFlags, s.receivedFeatureFlags],
+ (_featureFlags: FeatureFlagsSet, receivedFeatureFlags: boolean): FeedbackPromptConfig | null => {
const payload = getFeatureFlagPayload(FEATURE_FLAGS.POSTHOG_AI_CONVERSATION_FEEDBACK_CONFIG)
if (!payload || typeof payload !== 'object') {
- posthog.captureException(
- new Error('POSTHOG_AI_CONVERSATION_FEEDBACK_CONFIG feature flag is not set'),
- { tags: { product: 'max_ai' } }
- )
+ // Before flags resolve the payload is simply absent; only a loaded-but-missing payload is a real problem.
+ if (receivedFeatureFlags) {
+ posthog.captureException(
+ new Error('POSTHOG_AI_CONVERSATION_FEEDBACK_CONFIG feature flag is not set'),
+ { tags: { product: 'max_ai' } }
+ )
+ }
return null
}
return {