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(cdp): thread groups into hog flow function inputs (#64346)

Abigail68508bbb8da4
diff --git a/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.consumer.ts b/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.consumer.ts
index b861cde4850b..a2150c1ddd0a 100644
--- a/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.consumer.ts
+++ b/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.consumer.ts
@@ -99,6 +99,7 @@ export class CdpCyclotronWorkerHogFlow extends CdpCyclotronWorker {
state: hogFlowInvocationState,
hogFlow,
person: person ?? undefined,
+ groups,
filterGlobals,
})
})
diff --git a/nodejs/src/cdp/services/hogflows/actions/hog_function.test.ts b/nodejs/src/cdp/services/hogflows/actions/hog_function.test.ts
index 5199bf5b2edf..4722225d0c72 100644
--- a/nodejs/src/cdp/services/hogflows/actions/hog_function.test.ts
+++ b/nodejs/src/cdp/services/hogflows/actions/hog_function.test.ts
@@ -194,6 +194,53 @@ describe('HogFunctionHandler', () => {
expect(invocationResult.logs[0].message).toContain('[Action:function] Function completed')
})
+ describe('with groups', () => {
+ beforeEach(() => {
+ invocation.groups = {
+ organization: {
+ id: 'org_key',
+ type: 'organization',
+ index: 0,
+ url: '',
+ properties: { owner_name: 'Chris McNeill' },
+ },
+ }
+ })
+
+ it('should forward groups to the hog function invocation globals', async () => {
+ const buildHogFunctionInvocationSpy = jest.spyOn(mockHogFlowFunctionsService, 'buildHogFunctionInvocation')
+
+ const invocationResult = createInvocationResult<CyclotronJobInvocationHogFlow>(invocation, {
+ queue: 'hog',
+ queuePriority: 0,
+ })
+
+ await hogFunctionHandler.execute({ invocation, action, result: invocationResult })
+
+ const passedGlobals = buildHogFunctionInvocationSpy.mock.calls[0][2]
+ expect(passedGlobals.groups).toEqual(invocation.groups)
+ })
+
+ it('should render a group property referenced in a function input template', async () => {
+ // {groups.organization.properties.owner_name} compiled to hog bytecode
+ action.config.inputs.name = {
+ value: '{groups.organization.properties.owner_name}',
+ templating: 'hog',
+ bytecode: ['_H', 1, 32, 'owner_name', 32, 'properties', 32, 'organization', 32, 'groups', 1, 4],
+ }
+
+ const invocationResult = createInvocationResult<CyclotronJobInvocationHogFlow>(invocation, {
+ queue: 'hog',
+ queuePriority: 0,
+ })
+
+ const handlerResult = await hogFunctionHandler.execute({ invocation, action, result: invocationResult })
+
+ expect(handlerResult.error).toBeUndefined()
+ expect(mockFetch.mock.calls[0][1].body).toContain('"name":"Chris McNeill"')
+ })
+ })
+
it('should throw an error if template is not found', async () => {
const action = findActionByType(invocation.hogFlow, 'function')!
action.config.template_id = 'template_123'
diff --git a/nodejs/src/cdp/services/hogflows/actions/hog_function.ts b/nodejs/src/cdp/services/hogflows/actions/hog_function.ts
index fb727fb4e368..f80a36d1ddd7 100644
--- a/nodejs/src/cdp/services/hogflows/actions/hog_function.ts
+++ b/nodejs/src/cdp/services/hogflows/actions/hog_function.ts
@@ -90,6 +90,7 @@ export class HogFunctionHandler implements ActionHandler {
{
event: invocation.state.event,
person: invocation.person,
+ groups: invocation.groups,
variables: invocation.state.variables,
}
)
diff --git a/nodejs/src/cdp/types.ts b/nodejs/src/cdp/types.ts
index 07931cb45621..b9987f900128 100644
--- a/nodejs/src/cdp/types.ts
+++ b/nodejs/src/cdp/types.ts
@@ -322,6 +322,7 @@ export type CyclotronJobInvocationHogFlow = CyclotronJobInvocation & {
state?: HogFlowInvocationContext
hogFlow: HogFlow
person?: CyclotronPerson
+ groups?: HogFunctionInvocationGlobals['groups']
filterGlobals: HogFunctionFilterGlobals
}