🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(prompt-automations): prompt creations no longer trigger webhooks for unfiltered event actions (#13000)
Mark Salpeterd04e02710719
diff --git a/web/src/__tests__/server/prompts.v2.servertest.ts b/web/src/__tests__/server/prompts.v2.servertest.tsindex 92a599abd1..5007423464 100644--- a/web/src/__tests__/server/prompts.v2.servertest.ts+++ b/web/src/__tests__/server/prompts.v2.servertest.ts@@ -69,7 +69,7 @@ const setupTriggerAndAction = async (projectId: string) => {id: v4(),projectId: projectId,eventSource: "prompt",- eventActions: ["updated"],+ eventActions: [],filter: [],status: "ACTIVE",},diff --git a/worker/src/__tests__/promptVersionProcessor.test.ts b/worker/src/__tests__/promptVersionProcessor.test.tsindex 12487a73d0..a9ec424613 100644--- a/worker/src/__tests__/promptVersionProcessor.test.ts+++ b/worker/src/__tests__/promptVersionProcessor.test.ts@@ -1,39 +1,94 @@-import { describe, it, expect, beforeEach, beforeAll, afterAll } from "vitest";+import { describe, it, expect, beforeEach } from "vitest";import { v4 } from "uuid";import {ActionExecutionStatus,JobConfigState,TriggerEventSource,- TriggerEventAction,PromptType,} from "@langfuse/shared";import {createOrgProjectAndApiKey,- redis,EntityChangeEventType,} from "@langfuse/shared/src/server";import { ActionType, prisma } from "@langfuse/shared/src/db";import { promptVersionProcessor } from "../features/entityChange/promptVersionProcessor";describe("promptVersionChangeWorker", () => {- let orgId: string;let projectId: string;- let auth: string;beforeEach(async () => {- // Create test organization and projectconst result = await createOrgProjectAndApiKey();- orgId = result.orgId;projectId = result.projectId;- auth = result.auth;});- describe("successful trigger execution", () => {- it("should execute webhook for matching prompt created event", async () => {- // Create a prompt+ it.each([+ // eventActions only+ {+ description: "should execute webhook for matching prompt created event",+ trigger: { eventActions: ["created"], nameFilter: null },+ event: { promptName: "test-prompt", action: "created" as const },+ expected: 1,+ },+ {+ description: "should execute webhook for matching prompt updated event",+ trigger: { eventActions: ["updated"], nameFilter: null },+ event: { promptName: "test-prompt", action: "updated" as const },+ expected: 1,+ },+ {+ description: "should execute webhook for matching prompt deleted event",+ trigger: { eventActions: ["deleted"], nameFilter: null },+ event: { promptName: "test-prompt", action: "deleted" as const },+ expected: 1,+ },+ {+ description: "should not execute when action filter doesn't match",+ trigger: { eventActions: ["deleted"], nameFilter: null },+ event: { promptName: "test-prompt", action: "created" as const },+ expected: 0,+ },+ {+ description:+ "should execute webhook when eventActions and filters are empty",+ trigger: { eventActions: [] as string[], nameFilter: null },+ event: { promptName: "test-prompt", action: "updated" as const },+ expected: 1,+ },+ // eventActions + name filter combinations+ {+ description:+ "should execute webhook when eventActions is empty and name filter matches",+ trigger: { eventActions: [] as string[], nameFilter: "target-prompt" },+ event: { promptName: "target-prompt", action: "created" as const },+ expected: 1,+ },+ {+ description:+ "should execute webhook when eventActions and name filter both match",+ trigger: { eventActions: ["created"], nameFilter: "target-prompt" },+ event: { promptName: "target-prompt", action: "created" as const },+ expected: 1,+ },+ {+ description:+ "should not execute when eventActions matches but name filter does not",+ trigger: { eventActions: ["created"], nameFilter: "target-prompt" },+ event: { promptName: "different-prompt", action: "created" as const },+ expected: 0,+ },+ {+ description:+ "should not execute when eventActions does not match but name filter does",+ trigger: { eventActions: ["deleted"], nameFilter: "target-prompt" },+ event: { promptName: "target-prompt", action: "created" as const },+ expected: 0,+ },+ ])(+ "$description",+ async ({ trigger, event: { promptName, action }, expected }) => {+ const { eventActions, nameFilter } = trigger;const promptId = v4();- // Create a webhook actionconst actionId = v4();await prisma.action.create({data: {@@ -49,47 +104,47 @@ describe("promptVersionChangeWorker", () => {},});- // Create a trigger that matches prompt created eventsconst triggerId = v4();await prisma.trigger.create({data: {id: triggerId,projectId,eventSource: TriggerEventSource.Prompt,+ eventActions,status: JobConfigState.ACTIVE,- filter: [- {- column: "action",- operator: "=",- value: "created",- type: "string",- },- ],+ filter: nameFilter+ ? [+ {+ column: "Name",+ operator: "=",+ value: nameFilter,+ type: "string",+ },+ ]+ : [],},});- // Create automation linking trigger and actionconst automationId = v4();await prisma.automation.create({data: {id: automationId,- name: "prompt-created-automation",+ name: `automation-${v4()}`,projectId,triggerId,actionId,},});- // Create the event to processconst event: EntityChangeEventType = {entityType: "prompt-version",projectId,promptId,- action: "created",+ action,prompt: {id: promptId,projectId,- name: "test-prompt",+ name: promptName,version: 1,prompt: { messages: [{ role: "user", content: "Hello" }] },config: null,@@ -104,296 +159,17 @@ describe("promptVersionChangeWorker", () => {},};- // Execute the workerawait promptVersionProcessor(event);- // Verify automation execution was createdconst executions = await prisma.automationExecution.findMany({- where: {- projectId,- automationId,- triggerId,- actionId,- },- });-- expect(executions).toHaveLength(1);- expect(executions[0].status).toBe(ActionExecutionStatus.PENDING);- expect(executions[0].sourceId).toBe(promptId);- });-- it("should execute webhook for matching prompt updated event", async () => {- // Create a prompt- const promptId = v4();-- // Create a webhook action- const actionId = v4();- await prisma.action.create({- data: {- id: actionId,- projectId,- type: ActionType.WEBHOOK,- config: {- type: "WEBHOOK",- url: "https://webhook.example.com/test",- headers: {},- method: "POST",- },- },- });-- // Create a trigger that matches prompt updated events- const triggerId = v4();- await prisma.trigger.create({- data: {- id: triggerId,- projectId,- eventSource: TriggerEventSource.Prompt,- status: JobConfigState.ACTIVE,- filter: [- {- column: "action",- operator: "=",- value: "updated",- type: "string",- },- ],- },- });-- // Create automation linking trigger and action- const automationId = v4();- await prisma.automation.create({- data: {- id: automationId,- name: "prompt-updated-automation",- projectId,- triggerId,- actionId,- },- });-- // Create the event to process- const event: EntityChangeEventType = {- entityType: "prompt-version",- projectId,- promptId,- action: "updated",- prompt: {- id: promptId,- projectId,- name: "test-prompt",- version: 2,- prompt: { messages: [{ role: "user", content: "Hello updated" }] },- config: null,- tags: [],- labels: [],- type: PromptType.Chat,- isActive: true,- createdBy: "test-user",- createdAt: new Date(),- updatedAt: new Date(),- commitMessage: null,- },- };-- // Execute the worker- await promptVersionProcessor(event);-- // Verify automation execution was created- const executions = await prisma.automationExecution.findMany({- where: {- projectId,- automationId,- triggerId,- actionId,- },+ where: { projectId, automationId },});- expect(executions).toHaveLength(1);- expect(executions[0].status).toBe(ActionExecutionStatus.PENDING);- });- });-- it("should not execute when action filter doesn't match", async () => {- // Create a prompt- const promptId = v4();-- // Create a webhook action- const actionId = v4();- await prisma.action.create({- data: {- id: actionId,- projectId,- type: ActionType.WEBHOOK,- config: {- url: "https://webhook.example.com/test",- headers: {},- method: "POST",- },- },- });-- // Create a trigger that only matches DELETED events- const triggerId = v4();- await prisma.trigger.create({- data: {- id: triggerId,- projectId,- eventSource: TriggerEventSource.Prompt,- status: JobConfigState.ACTIVE,- filter: [- {- column: "action",- operator: "=",- value: "deleted",- type: "string",- },- ],- },- });-- // Create automation linking trigger and action- const automationId = v4();- await prisma.automation.create({- data: {- id: automationId,- name: "prompt-deleted-automation",- projectId,- triggerId,- actionId,- },- });-- // Create a CREATED event (which shouldn't match the DELETED filter)- const event: EntityChangeEventType = {- entityType: "prompt-version",- projectId,- promptId,- action: "created",- prompt: {- id: promptId,- projectId,- name: "test-prompt",- version: 1,- prompt: { messages: [{ role: "user", content: "Hello" }] },- config: null,- tags: [],- labels: [],- type: PromptType.Chat,- isActive: true,- createdBy: "test-user",- createdAt: new Date(),- updatedAt: new Date(),- commitMessage: null,- },- };-- // Execute the worker- await promptVersionProcessor(event);-- // Verify no automation execution was created- const executions = await prisma.automationExecution.findMany({- where: {- projectId,- automationId,- },- });-- expect(executions).toHaveLength(0);- });-- it("should not execute when prompt name filter doesn't match", async () => {- // Create a prompt- const promptId = v4();-- // Create a webhook action- const actionId = v4();- await prisma.action.create({- data: {- id: actionId,- projectId,- type: ActionType.WEBHOOK,- config: {- url: "https://webhook.example.com/test",- headers: {},- method: "POST",- },- },- });-- // Create a trigger that matches CREATED events but only for specific prompt name- const triggerId = v4();- await prisma.trigger.create({- data: {- id: triggerId,- projectId,- eventSource: TriggerEventSource.Prompt,- status: JobConfigState.ACTIVE,- filter: [- {- column: "action",- operator: "=",- value: "created",- type: "string",- },- {- column: "name",- operator: "=",- value: "target-prompt",- type: "string",- },- ],- },- });-- // Create automation linking trigger and action- const automationId = v4();- await prisma.automation.create({- data: {- id: automationId,- name: "specific-prompt-automation",- projectId,- triggerId,- actionId,- },- });-- // Create event with different prompt name- const event: EntityChangeEventType = {- entityType: "prompt-version",- projectId,- promptId,- action: "created",- prompt: {- id: promptId,- projectId,- name: "different-prompt",- version: 1,- prompt: { messages: [{ role: "user", content: "Hello" }] },- config: null,- tags: [],- labels: [],- type: PromptType.Chat,- isActive: true,- createdBy: "test-user",- createdAt: new Date(),- updatedAt: new Date(),- commitMessage: null,- },- };-- // Execute the worker- await promptVersionProcessor(event);-- // Verify no automation execution was created- const executions = await prisma.automationExecution.findMany({- where: {- projectId,- automationId,- },- });-- expect(executions).toHaveLength(0);- });+ expect(executions).toHaveLength(expected);+ if (expected > 0) {+ expect(executions[0].status).toBe(ActionExecutionStatus.PENDING);+ expect(executions[0].sourceId).toBe(promptId);+ }+ },+ );});diff --git a/worker/src/features/entityChange/promptVersionProcessor.ts b/worker/src/features/entityChange/promptVersionProcessor.tsindex 41136d07d9..77dd3b2c44 100644--- a/worker/src/features/entityChange/promptVersionProcessor.ts+++ b/worker/src/features/entityChange/promptVersionProcessor.ts@@ -1,5 +1,6 @@import {type TriggerEventAction,+ type FilterState,jsonSchemaNullable,InternalServerError,} from "@langfuse/shared";@@ -68,10 +69,27 @@ export const promptVersionProcessor = async (}};+ // Merge eventActions into the filter so InMemoryFilterService handles+ // everything in one place. Done here rather than in convertTriggerToDomain+ // because that function also serves the UI — injecting a synthetic condition+ // there would corrupt the edit form and write it back to the DB on save.+ const mergedFilter: FilterState =+ trigger.eventActions.length > 0+ ? [+ ...trigger.filter,+ {+ column: "action",+ operator: "any of",+ type: "stringOptions",+ value: trigger.eventActions,+ },+ ]+ : trigger.filter;+// Use InMemoryFilterService for all filtering including actionsconst eventMatches = InMemoryFilterService.evaluateFilter(eventData,- trigger.filter,+ mergedFilter,fieldMapper,);