: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(max): allow new AI conversations through read-only guard (#59806)
Paul D'Ambra0f8ac9fa55ce
diff --git a/frontend/src/lib/readOnlyGuard.test.ts b/frontend/src/lib/readOnlyGuard.test.tsindex 8ecc971b4ef0..d7a72c85c978 100644--- a/frontend/src/lib/readOnlyGuard.test.ts+++ b/frontend/src/lib/readOnlyGuard.test.ts@@ -91,6 +91,14 @@ describe('readOnlyGuard', () => {['insights timing with trailing slash', 'POST', '/api/projects/2/insights/timing/'],['metalytics (no trailing slash)', 'POST', '/api/projects/2/metalytics'],['metalytics with trailing slash', 'POST', '/api/projects/2/metalytics/'],+ ['new AI conversation', 'POST', '/api/environments/2/conversations'],+ ['new AI conversation with trailing slash', 'POST', '/api/environments/2/conversations/'],+ ['AI conversation by id', 'PATCH', '/api/environments/2/conversations/abc-123/'],+ ['AI conversation delete', 'DELETE', '/api/environments/2/conversations/abc-123/'],+ ['AI conversation queue', 'POST', '/api/environments/2/conversations/abc-123/queue'],+ ['AI conversation queue clear', 'POST', '/api/environments/2/conversations/abc-123/queue/clear'],+ ['AI conversation append message', 'POST', '/api/environments/2/conversations/abc-123/append_message'],+ ['AI conversation cancel', 'PATCH', '/api/environments/2/conversations/abc-123/cancel/'],] as const)('lets %s through (%s %s)', (_label, method, url) => {const notifier = jest.fn()setReadOnlyNotifier(notifier)@@ -107,6 +115,20 @@ describe('readOnlyGuard', () => {['insight non-viewed sub-action blocked', 'POST', '/api/environments/2/insights/123/viewed_by'],['insight non-timing sub-action blocked', 'POST', '/api/environments/2/insights/123/timing_breakdown'],['metalytics-like prefix blocked', 'POST', '/api/projects/2/metalyticsfoo/'],+ ['ticket saved views write blocked', 'POST', '/api/environments/2/conversations/views/'],+ [+ 'ticket saved views write blocked (no trailing slash)',+ 'POST',+ '/api/environments/2/conversations/views',+ ],+ ['ticket saved view detail write blocked', 'PATCH', '/api/environments/2/conversations/views/abc/'],+ ['support tickets write blocked (under projects)', 'POST', '/api/projects/2/conversations/tickets/'],+ [+ 'support tickets write blocked (under environments)',+ 'POST',+ '/api/environments/2/conversations/tickets/',+ ],+ ['conversations-like prefix blocked', 'POST', '/api/environments/2/conversationsfoo/'],] as const)('still blocks %s (%s %s) — only allowlisted paths pass', (_l, method, url) => {expect(() => assertNotReadOnly(method, url)).toThrow(ReadOnlyModeError)})diff --git a/frontend/src/lib/readOnlyGuard.ts b/frontend/src/lib/readOnlyGuard.tsindex 77d4edc9851e..52769d50a332 100644--- a/frontend/src/lib/readOnlyGuard.ts+++ b/frontend/src/lib/readOnlyGuard.ts@@ -44,19 +44,25 @@ export function isReadOnly(): boolean {return getter?.() ?? false}-// Writes that should pass through in read-only mode. Two categories:+// Writes that should pass through in read-only mode. Three categories:// 1. Reads disguised as writes — /query serves HogQL / trends / funnels /// retention via POST because the payload is too large for a query string.// Block-listing it would make the entire app unusable.// 2. Passive telemetry that fires automatically on view/mount and should not// raise: /file_system/log_view, /insights/viewed, /insights/timing// (time-to-see-data), and /metalytics (side-panel scene view tracking).+// 3. PostHog AI (Max) conversations — the read-only toast tells users to+// "Use Max or the MCP to make this change", so Max must remain usable.+// Matches /conversations except the two ticket sub-features (`views` and+// `tickets`). Mount-path-agnostic — works under /environments/ or+// /projects/ — so the discriminator is the sub-feature, not the prefix.const READ_ONLY_ALLOWED_PATTERNS = [/\/query(?:\/|$|\?)/, // /api/environments/:team_id/query, /api/environments/:team_id/query/:queryId/log, etc./\/file_system\/log_view(?:\/|$|\?)/, // /api/environments/:team_id/file_system/log_view/\/insights\/viewed(?:\/|$|\?)/, // /api/environments/:team_id/insights/viewed — passive "recently viewed" telemetry/\/insights\/timing(?:\/|$|\?)/, // /api/projects/:team_id/insights/timing — time-to-see-data telemetry fired after every dashboard/insight load/\/metalytics(?:\/|$|\?)/, // /api/projects/:team_id/metalytics — side-panel scene view tracking (only accepts metric_name=viewed)+ /\/conversations(?!\/(?:views|tickets))(?:\/|$|\?)/, // /api/.../conversations[/:id[/queue|/append_message|/cancel|...]] — PostHog AI (Max), excluding /conversations/views and /conversations/tickets]function isReadDisguisedAsWrite(url: string): boolean {