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(workflows): fail task limits (#94991)

Ben Whitea04d42d96dbe
diff --git a/docs/internal/workflow-ai-task-limits.md b/docs/internal/workflow-ai-task-limits.md
index c4c85fb8ec90..4537a3d5a454 100644
--- a/docs/internal/workflow-ai-task-limits.md
+++ b/docs/internal/workflow-ai-task-limits.md
@@ -9,4 +9,6 @@ These defaults prevent a broadly matching event trigger from sustaining unbounde
Staff can override either limit for a project in Django admin under **Team workflows configs**. Leave a value blank to use the default. Set it to zero to pause new workflow-created tasks at that scope.
+When a limit blocks task creation, the Create AI task step records the API reason as an error. The workflow then follows the step's `on_error` configuration.
+
Keep both limits enabled when raising capacity. Set the per-workflow limit for the expected trigger volume and retain a higher project-wide ceiling as the final spend guardrail.
diff --git a/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.test.ts b/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.test.ts
index 7b161591a257..2540ba8c570d 100644
--- a/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.test.ts
+++ b/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.test.ts
@@ -181,22 +181,15 @@ describe('posthog create task template', () => {
expect(response.execResult).toEqual({ id: 'task-1', run_id: 'run-1' })
})
- it('skips instead of failing when the parallel task limit is hit', async () => {
+ it('fails with the limit reason when the parallel task limit is hit', async () => {
let response = await tester.invoke(fullInputs, undefined, workflowOptions)
response = await tester.invokeFetchResponse(response.invocation, {
status: 409,
body: { detail: 'This workflow already has 3 tasks running' },
})
- expect(response.error).toBeUndefined()
+ expect(response.error).toEqual('Failed to create task (409): This workflow already has 3 tasks running')
expect(response.finished).toBe(true)
- expect(response.execResult).toEqual({
- skipped: true,
- reason: 'This workflow already has 3 tasks running',
- })
- expect(response.logs.map((log) => log.message)).toContain(
- 'Task not created: This workflow already has 3 tasks running'
- )
})
it.each([
diff --git a/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.ts b/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.ts
index aa4648dcc13b..fb5f79b528b3 100644
--- a/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.ts
+++ b/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.ts
@@ -67,11 +67,6 @@ if (inputs.reply_in_slack_thread != false and event.event == '$slack_message_rec
let response := postHogCreateTask(payload)
-if (response.status == 409) {
- print(f'Task not created: {apiErrorMessage(response)}')
- return { 'skipped': true, 'reason': apiErrorMessage(response) }
-}
-
if (response.status >= 400) {
throw Error(f'Failed to create task ({response.status}): {apiErrorMessage(response)}')
}
@@ -169,9 +164,8 @@ return response.body
'The agent posts its updates as replies in the Slack thread that started this workflow. Replies in that thread are sent to the agent. The run stays open for about 2 minutes after the agent finishes so replies can reach it.',
},
{
- // The engine treats a 4xx as a step failure before the code above runs, unless the
- // status is listed here. 409 is the "task limit reached" reply, which the code turns
- // into a graceful skip.
+ // Allow 409 through to the template so it can surface the API's detailed limit
+ // message as the step error rather than the executor's generic fetch failure.
key: 'non_failure_status_codes',
type: 'non_failure_status_codes',
label: 'Non-failure status codes',
diff --git a/nodejs/src/cdp/workflows-e2e.serial.test.ts b/nodejs/src/cdp/workflows-e2e.serial.test.ts
index 8c15ce8738cb..bcfe3b0987a7 100644
--- a/nodejs/src/cdp/workflows-e2e.serial.test.ts
+++ b/nodejs/src/cdp/workflows-e2e.serial.test.ts
@@ -2492,7 +2492,7 @@ describe('Workflows E2E (postgres-v2)', () => {
expect(runMetricNames()).not.toContain('failed')
})
- it('completes the run without a failure when the task limit replies 409', async () => {
+ it('fails the run when the task limit replies 409', async () => {
mockFetch.mockResolvedValue({
status: 409,
headers: { 'Content-Type': 'application/json' },
@@ -2504,9 +2504,8 @@ describe('Workflows E2E (postgres-v2)', () => {
await triggerWorkflow(globals)
await waitForExpect(() => {
- expect(runMetricNames()).toContain('succeeded')
+ expect(runMetricNames()).toContain('failed')
}, 10000)
- expect(runMetricNames()).not.toContain('failed')
// 409 is terminal for the step: one request, no retry burning the engine's budget.
expect(mockFetch).toHaveBeenCalledTimes(1)
})
diff --git a/nodejs/tests/fixtures/hog-bytecode/ab39562ee747407e7d1364698e0cf2be2f097289c1af6cf8cd0cd4660290af3e.json b/nodejs/tests/fixtures/hog-bytecode/ab39562ee747407e7d1364698e0cf2be2f097289c1af6cf8cd0cd4660290af3e.json
new file mode 100644
index 000000000000..e94ded1d18f4
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/ab39562ee747407e7d1364698e0cf2be2f097289c1af6cf8cd0cd4660290af3e.json
@@ -0,0 +1 @@
+["_H",1,52,"apiErrorMessage",1,0,28,36,0,32,"body",45,32,"error",45,47,9,35,36,0,32,"body",45,32,"detail",45,47,6,35,36,0,32,"body",45,38,53,0,32,"prompt",32,"inputs",1,2,2,"empty",1,40,6,32,"Instructions are required",2,"Error",1,49,32,"prompt",32,"prompt",32,"inputs",1,2,32,"event",32,"event",1,1,42,2,32,"title",32,"inputs",1,2,2,"empty",1,5,40,11,36,1,32,"title",32,"title",32,"inputs",1,2,46,32,"model",32,"inputs",1,2,2,"empty",1,5,32,"model",32,"model",32,"inputs",1,3,2,"empty",1,5,3,2,40,40,36,1,32,"model",32,"model",32,"model",32,"inputs",1,3,46,32,"reasoning_effort",32,"model",32,"inputs",1,3,2,"empty",1,5,40,13,36,1,32,"reasoning_effort",32,"reasoning_effort",32,"model",32,"inputs",1,3,46,32,"repository",32,"inputs",1,2,2,"empty",1,5,40,11,36,1,32,"repository",32,"repository",32,"inputs",1,2,46,32,"connectors",32,"inputs",1,2,2,"empty",1,5,40,11,36,1,32,"connectors",32,"connectors",32,"inputs",1,2,46,32,"skills",32,"inputs",1,2,2,"empty",1,5,40,11,36,1,32,"skills",32,"skills",32,"inputs",1,2,46,32,"posthog_mcp_scopes",32,"inputs",1,2,2,"empty",1,5,40,11,36,1,32,"posthog_mcp_scopes",32,"posthog_mcp_scopes",32,"inputs",1,2,46,32,"max_parallel_tasks",32,"inputs",1,2,2,"empty",1,5,40,11,36,1,32,"max_parallel_tasks",32,"max_parallel_tasks",32,"inputs",1,2,46,30,32,"reply_in_slack_thread",32,"inputs",1,2,12,32,"$slack_message_received",32,"event",32,"event",1,2,11,32,"channel",32,"properties",32,"event",1,3,2,"empty",1,5,32,"ts",32,"properties",32,"event",1,3,2,"empty",1,5,3,4,40,102,36,1,32,"slack_context",32,"integration_id",32,"integration_id",32,"properties",32,"event",1,3,32,"channel",32,"channel",32,"properties",32,"event",1,3,32,"thread_ts",32,"thread_ts",32,"properties",32,"event",1,3,47,9,35,32,"ts",32,"properties",32,"event",1,3,32,"message_ts",32,"ts",32,"properties",32,"event",1,3,32,"slack_user_id",32,"user",32,"properties",32,"event",1,3,47,3,35,32,"",32,"slack_team_id",32,"slack_team_id",32,"properties",32,"event",1,3,47,3,35,32,"",32,"is_ext_shared_channel",32,"is_ext_shared_channel",32,"properties",32,"event",1,3,47,2,35,30,42,7,46,36,1,2,"postHogCreateTask",1,33,400,36,2,32,"status",45,14,40,22,32,"Failed to create task (",36,2,32,"status",45,32,"): ",36,2,36,0,54,1,2,"concat",4,2,"Error",1,49,36,2,32,"body",45,38,35,35,35]