: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
feat(cohorts): strip compiled bytecode from cohorts-retrieve mcp output (#62636)
Georgiy Tarasovadbf0b7c1767
diff --git a/products/cohorts/mcp/tools.yaml b/products/cohorts/mcp/tools.yamlindex 1ed793c395c1..7674212aec04 100644--- a/products/cohorts/mcp/tools.yaml+++ b/products/cohorts/mcp/tools.yaml@@ -205,6 +205,14 @@ tools:id:cast: string-intui_app: cohort+ response:+ exclude:+ - filters.properties.values.*.values.*.bytecode+ - filters.properties.values.*.values.*.bytecode_error+ - filters.properties.values.*.values.*.conditionHash+ - filters.properties.values.*.bytecode+ - filters.properties.values.*.bytecode_error+ - filters.properties.values.*.conditionHashcohorts-rm-person-from-static-cohort-partial-update:operation: cohorts_remove_person_from_static_cohort_partial_updateenabled: truediff --git a/services/mcp/src/tools/generated/cohorts.ts b/services/mcp/src/tools/generated/cohorts.tsindex 7e516f6cd87d..f6f3bad6f856 100644--- a/services/mcp/src/tools/generated/cohorts.ts+++ b/services/mcp/src/tools/generated/cohorts.ts@@ -15,7 +15,7 @@ import {} from '@/generated/cohorts/api'import { withUiApp } from '@/resources/ui-apps'import { castStringToInt } from '@/tools/cast-helpers'-import { withPostHogUrl, pickResponseFields, type WithPostHogUrl } from '@/tools/tool-utils'+import { withPostHogUrl, pickResponseFields, omitResponseFields, type WithPostHogUrl } from '@/tools/tool-utils'import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'const CohortsAddPersonsToStaticCohortPartialUpdateSchema = CohortsAddPersonsToStaticCohortPartialUpdateParams.omit({@@ -177,7 +177,15 @@ const cohortsRetrieve = (): ToolBase<typeof CohortsRetrieveSchema, WithPostHogUrmethod: 'GET',path: `/api/projects/${encodeURIComponent(String(projectId))}/cohorts/${encodeURIComponent(String(params.id))}/`,})- return await withPostHogUrl(context, result, `/cohorts/${result.id}`)+ const filtered = omitResponseFields(result, [+ 'filters.properties.values.*.values.*.bytecode',+ 'filters.properties.values.*.values.*.bytecode_error',+ 'filters.properties.values.*.values.*.conditionHash',+ 'filters.properties.values.*.bytecode',+ 'filters.properties.values.*.bytecode_error',+ 'filters.properties.values.*.conditionHash',+ ]) as typeof result+ return await withPostHogUrl(context, filtered, `/cohorts/${filtered.id}`)},})diff --git a/services/mcp/tests/unit/utils.test.ts b/services/mcp/tests/unit/utils.test.tsindex 466822628563..b3b5240eb057 100644--- a/services/mcp/tests/unit/utils.test.ts+++ b/services/mcp/tests/unit/utils.test.ts@@ -273,6 +273,99 @@ describe('utils', () => {omitResponseFields(obj, ['extra'])expect(obj).toEqual({ id: 1, name: 'test', extra: { nested: true } })})++ it('strips compiled HogQL artifacts from cohort filter conditions (cohorts-retrieve)', () => {+ const cohort = {+ id: 350280,+ name: 'sibling cohort',+ filters: {+ properties: {+ type: 'OR',+ values: [+ {+ type: 'OR',+ values: [+ {+ type: 'person',+ key: 'organization_id',+ operator: 'exact',+ value: ['uuid-a', 'uuid-b'],+ bytecode: ['_H', 1, 32, 'organization_id'],+ bytecode_error: null,+ conditionHash: '3fb4902b4bac10d2',+ },+ ],+ },+ ],+ },+ },+ }+ const paths = [+ 'filters.properties.values.*.values.*.bytecode',+ 'filters.properties.values.*.values.*.bytecode_error',+ 'filters.properties.values.*.values.*.conditionHash',+ 'filters.properties.values.*.bytecode',+ 'filters.properties.values.*.bytecode_error',+ 'filters.properties.values.*.conditionHash',+ ]+ expect(omitResponseFields(cohort, paths)).toEqual({+ id: 350280,+ name: 'sibling cohort',+ filters: {+ properties: {+ type: 'OR',+ values: [+ {+ type: 'OR',+ values: [+ {+ type: 'person',+ key: 'organization_id',+ operator: 'exact',+ value: ['uuid-a', 'uuid-b'],+ },+ ],+ },+ ],+ },+ },+ })+ })++ it('strips compiled artifacts from a single-level (flattened) cohort filter group', () => {+ const cohort = {+ filters: {+ properties: {+ type: 'AND',+ values: [+ {+ type: 'behavioral',+ key: 'signed up',+ value: 'performed_event',+ bytecode: ['_H', 1],+ conditionHash: 'abc123',+ },+ ],+ },+ },+ }+ const paths = [+ 'filters.properties.values.*.values.*.bytecode',+ 'filters.properties.values.*.values.*.bytecode_error',+ 'filters.properties.values.*.values.*.conditionHash',+ 'filters.properties.values.*.bytecode',+ 'filters.properties.values.*.bytecode_error',+ 'filters.properties.values.*.conditionHash',+ ]+ expect(omitResponseFields(cohort, paths)).toEqual({+ filters: {+ properties: {+ type: 'AND',+ values: [{ type: 'behavioral', key: 'signed up', value: 'performed_event' }],+ },+ },+ })+ })})describe('withPostHogUrl', () => {