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.

feat(workflows): link create-ai-task results in workflow run logs (#88024)

Harley Alexander2f5726afd9d0
diff --git a/nodejs/src/cdp/services/hogflows/hogflow-executor.service.test.ts b/nodejs/src/cdp/services/hogflows/hogflow-executor.service.test.ts
index ad81e83d2bf7..4ee6c08503ab 100644
--- a/nodejs/src/cdp/services/hogflows/hogflow-executor.service.test.ts
+++ b/nodejs/src/cdp/services/hogflows/hogflow-executor.service.test.ts
@@ -2540,6 +2540,53 @@ describe('Hogflow Executor', () => {
// No variables should be set since no result was produced
expect(result.invocation.state.variables).toBeUndefined()
})
+
+ it('links a create-ai-task result to the task in the stored action result log', async () => {
+ // Mirrors the shape template-posthog-create-task returns on success: { id, run_id }.
+ // A non-empty inputs_schema sidesteps an insertRow quirk where an empty array param
+ // reaches the jsonb column as an empty object, not an empty array.
+ await insertHogFunctionTemplate(hub.postgres, {
+ id: 'template-posthog-create-task',
+ name: 'Create AI task',
+ code: `return { 'id': 'task-1234', 'run_id': 'run-5678' }`,
+ inputs_schema: [{ key: 'prompt', type: 'string', required: false }],
+ })
+
+ const hogFlow = new FixtureHogFlowBuilder()
+ .withWorkflow({
+ actions: {
+ trigger: {
+ type: 'trigger',
+ config: {
+ type: 'event',
+ filters: HOG_FILTERS_EXAMPLES.no_filters.filters ?? {},
+ },
+ },
+ action_1: {
+ type: 'function',
+ config: {
+ template_id: 'template-posthog-create-task',
+ inputs: {},
+ },
+ output_variable: { key: 'task', result_path: null },
+ } as any,
+ exit: {
+ type: 'exit',
+ config: {},
+ },
+ },
+ edges: [
+ { from: 'trigger', to: 'action_1', type: 'continue' },
+ { from: 'action_1', to: 'exit', type: 'continue' },
+ ],
+ })
+ .build()
+
+ const result = await executeToCompletion(hogFlow)
+
+ expect(result.invocation.state.variables?.task).toEqual({ id: 'task-1234', run_id: 'run-5678' })
+ expect(result.logs.some((l) => l.message.includes('task = [Task:task-1234|run-5678]'))).toBe(true)
+ })
})
describe('billing metrics', () => {
diff --git a/nodejs/src/cdp/services/hogflows/hogflow-executor.service.ts b/nodejs/src/cdp/services/hogflows/hogflow-executor.service.ts
index 99fd715cd313..ec60b4721ce7 100644
--- a/nodejs/src/cdp/services/hogflows/hogflow-executor.service.ts
+++ b/nodejs/src/cdp/services/hogflows/hogflow-executor.service.ts
@@ -889,11 +889,29 @@ export class HogFlowExecutorService {
}
const storedSummary = allStoredKeys
- .map((key) => `${key} = ${JSON.stringify(result.invocation.state.variables![key])}`)
+ .map((key) => `${key} = ${this.describeStoredVariable(action, result.invocation.state.variables![key])}`)
.join(', ')
this.log(result, 'debug', `Stored action result in variable(s): ${storedSummary}`)
}
+ // The create-ai-task destination's result variable is what lets a workflow author jump from a
+ // run's logs to the task it kicked off. Everything else stays plain JSON.
+ private describeStoredVariable(action: HogFlowAction, value: unknown): string {
+ const isCreateAiTaskAction =
+ action.type === 'function' && action.config.template_id === 'template-posthog-create-task'
+ if (
+ isCreateAiTaskAction &&
+ value &&
+ typeof value === 'object' &&
+ typeof (value as Record<string, unknown>).id === 'string' &&
+ (value as Record<string, unknown>).id !== ''
+ ) {
+ const runId = (value as Record<string, unknown>).run_id
+ return `[Task:${(value as Record<string, unknown>).id}|${typeof runId === 'string' ? runId : ''}]`
+ }
+ return JSON.stringify(value)
+ }
+
private logExecutionTriggerInfo(invocation: CyclotronJobInvocationHogFlow): MinimalLogEntry {
const hasCurrentAction = Boolean(invocation.state.currentAction)
const currentAction = hasCurrentAction ? `[Action:${invocation.state.currentAction!.id}]` : 'trigger'
diff --git a/products/workflows/frontend/Workflows/logs/log-utils.test.tsx b/products/workflows/frontend/Workflows/logs/log-utils.test.tsx
new file mode 100644
index 000000000000..72ab85b32add
--- /dev/null
+++ b/products/workflows/frontend/Workflows/logs/log-utils.test.tsx
@@ -0,0 +1,33 @@
+import { render } from '@testing-library/react'
+
+import { HogFlow } from '../hogflows/types'
+import { renderWorkflowLogMessage } from './log-utils'
+
+const workflow: HogFlow = {
+ id: 'flow-1',
+ team_id: 1,
+ version: 1,
+ name: 'Test workflow',
+ status: 'draft',
+ exit_condition: 'exit_only_at_end',
+ actions: [],
+ edges: [],
+ created_at: '2026-08-24T00:00:00Z',
+ updated_at: '2026-08-24T00:00:00Z',
+}
+
+describe('renderWorkflowLogMessage', () => {
+ it('links a [Task:id|run_id] token to the created task', () => {
+ const { container } = render(
+ renderWorkflowLogMessage(
+ workflow,
+ 'Stored action result in variable(s): task = [Task:8b70d61c-ca77-46fb-ba76-3330aaea3dad|80d1779f-6af1-4bfd-855b-556b3d7b2bc0]'
+ )
+ )
+
+ const link = container.querySelector('a')
+ expect(link?.getAttribute('href')).toContain('/code/task/8b70d61c-ca77-46fb-ba76-3330aaea3dad')
+ expect(link?.getAttribute('target')).toBe('_blank')
+ expect(link?.textContent).toContain('View task')
+ })
+})
diff --git a/products/workflows/frontend/Workflows/logs/log-utils.tsx b/products/workflows/frontend/Workflows/logs/log-utils.tsx
index bf8d2ba7b366..d9b9a801afbe 100644
--- a/products/workflows/frontend/Workflows/logs/log-utils.tsx
+++ b/products/workflows/frontend/Workflows/logs/log-utils.tsx
@@ -17,6 +17,7 @@ const PERSON_REGEX = /\[Person:([a-zA-Z0-9_-]+)\|(.*?)\]/
const EVENT_REGEX = /\[Event:([a-zA-Z0-9_-]+)\|(.*?)\|(.*?)\]/
const ACTOR_REGEX = /\[Actor:(.*?)\]/
const EMAIL_REGEX = /\[Email:([a-zA-Z0-9_-]+):([a-zA-Z0-9_-]*)\]/
+const TASK_REGEX = /\[Task:([a-zA-Z0-9-]+)\|([a-zA-Z0-9-]*)\]/
export const renderWorkflowLogMessage = (workflow: HogFlow, message: string): JSX.Element => {
// Modifies the rendered log message to auto-detect action or person parts and replace them with a link
@@ -85,6 +86,24 @@ export const renderWorkflowLogMessage = (workflow: HogFlow, message: string): JS
continue
}
+ const matchesTaskRegex = TASK_REGEX.exec(part)
+ if (matchesTaskRegex) {
+ const taskId = matchesTaskRegex[1]
+
+ elements.push(
+ <Link
+ key={part}
+ className="rounded p-1 -m-1 bg-border text-bg-primary"
+ to={urls.codeTaskLink(taskId)}
+ target="_blank"
+ targetBlankIcon
+ >
+ View task
+ </Link>
+ )
+ continue
+ }
+
const matchesEventRegex = EVENT_REGEX.exec(part)
if (matchesEventRegex) {
const eventUuid = matchesEventRegex[1]