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(phai): handle access-denied response in core memory settings load (#62460)

posthog[bot]414c148e28b9
diff --git a/frontend/src/scenes/settings/environment/maxSettingsLogic.test.ts b/frontend/src/scenes/settings/environment/maxSettingsLogic.test.ts
new file mode 100644
index 000000000000..6c78677c5fd6
--- /dev/null
+++ b/frontend/src/scenes/settings/environment/maxSettingsLogic.test.ts
@@ -0,0 +1,68 @@
+import { expectLogic } from 'kea-test-utils'
+
+import api from 'lib/api'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { maxSettingsLogic } from './maxSettingsLogic'
+
+describe('maxSettingsLogic', () => {
+ let logic: ReturnType<typeof maxSettingsLogic.build>
+
+ beforeEach(() => {
+ initKeaTests()
+ })
+
+ afterEach(() => {
+ logic?.unmount()
+ })
+
+ it('loads core memory from the first result', async () => {
+ useMocks({
+ get: {
+ '/api/environments/:team_id/core_memory/': () => [
+ 200,
+ { results: [{ id: 'mem-1', text: 'remember this' }] },
+ ],
+ },
+ })
+ logic = maxSettingsLogic()
+ logic.mount()
+
+ await expectLogic(logic)
+ .toDispatchActions(['loadCoreMemorySuccess'])
+ .toMatchValues({ coreMemory: { id: 'mem-1', text: 'remember this' }, isLoading: false })
+ })
+
+ it.each([403, 408, 502, 504])(
+ 'falls back to null without throwing when the load responds with %s',
+ async (status) => {
+ useMocks({
+ get: {
+ '/api/environments/:team_id/core_memory/': () => [status, { detail: 'nope' }],
+ },
+ })
+ logic = maxSettingsLogic()
+ logic.mount()
+
+ // The loader catches non-OK responses so they resolve as success with a null value,
+ // rather than bubbling up as an uncaught frontend error.
+ await expectLogic(logic)
+ .toDispatchActions(['loadCoreMemorySuccess'])
+ .toNotHaveDispatchedActions(['loadCoreMemoryFailure'])
+ .toMatchValues({ coreMemory: null, isLoading: false })
+ }
+ )
+
+ it('lets non-HTTP errors propagate so real regressions stay visible', async () => {
+ // A programming error (not an ApiError) should surface as a failure, not be silently swallowed.
+ jest.spyOn(api.coreMemory, 'list').mockRejectedValueOnce(new TypeError('boom'))
+ logic = maxSettingsLogic()
+ logic.mount()
+
+ await expectLogic(logic)
+ .toDispatchActions(['loadCoreMemoryFailure'])
+ .toMatchValues({ coreMemory: null, isLoading: false })
+ })
+})
diff --git a/frontend/src/scenes/settings/environment/maxSettingsLogic.tsx b/frontend/src/scenes/settings/environment/maxSettingsLogic.tsx
index 84f95eadc7c8..915fb984752c 100644
--- a/frontend/src/scenes/settings/environment/maxSettingsLogic.tsx
+++ b/frontend/src/scenes/settings/environment/maxSettingsLogic.tsx
@@ -3,6 +3,7 @@ import { forms } from 'kea-forms'
import { loaders } from 'kea-loaders'
import api from 'lib/api'
+import { ApiError } from 'lib/api-error'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { CoreMemory } from '~/types'
@@ -47,8 +48,18 @@ export const maxSettingsLogic = kea<maxSettingsLogicType>([
coreMemory: {
__default: null as CoreMemory | null,
loadCoreMemory: async (): Promise<CoreMemory | null> => {
- const response = await api.coreMemory.list()
- return response.results[0] || null
+ try {
+ const response = await api.coreMemory.list()
+ return response.results[0] || null
+ } catch (error) {
+ // Non-OK responses (e.g. 403 when lacking access to the environment, or upstream
+ // timeouts) shouldn't surface as uncaught frontend errors — fall back to empty state.
+ // Anything that isn't an HTTP error (a real regression in the API client) still propagates.
+ if (error instanceof ApiError) {
+ return null
+ }
+ throw error
+ }
},
updateCoreMemory: async (data: CoreMemoryForm) => {
if (!values.coreMemory) {