🪢 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: Accept any 2xx status for webhooks (#9439)
Marc Klingenc7de984fb1bd
diff --git a/worker/src/__tests__/webhooks.test.ts b/worker/src/__tests__/webhooks.test.tsindex ba68594b41..de30d5e0a4 100644--- a/worker/src/__tests__/webhooks.test.ts+++ b/worker/src/__tests__/webhooks.test.ts@@ -67,6 +67,17 @@ class WebhookTestServer {);}),+ // 201 Created response endpoint (GitLab use case)+ http.post("https://webhook-201.example.com/*", async ({ request }) => {+ this.receivedRequests.push({+ url: request.url,+ method: request.method,+ headers: Object.fromEntries(request.headers.entries()),+ body: JSON.stringify(await request.json()),+ });+ return HttpResponse.json({ success: true }, { status: 201 });+ }),+// Timeout endpointhttp.post("https://webhook-timeout.example.com/*", () => {return HttpResponse.error();@@ -351,6 +362,81 @@ describe("Webhook Integration Tests", () => {expect(execution?.status).toBe(ActionExecutionStatus.PENDING);});+ it("should accept 201 status code as success (GitLab use case)", async () => {+ // Get the full prompt for the payload+ const fullPrompt = await prisma.prompt.findUnique({+ where: { id: promptId },+ });++ const action = await prisma.action.findUnique({+ where: { id: actionId },+ });++ if (!action) {+ throw new Error("Action not found");+ }++ // Update action to use 201 endpoint+ await prisma.action.update({+ where: { id: actionId },+ data: {+ projectId,+ type: "WEBHOOK",+ config: {+ ...(action.config as WebhookActionConfigWithSecrets),+ url: "https://webhook-201.example.com/test",+ },+ },+ });++ await prisma.automationExecution.create({+ data: {+ id: executionId,+ projectId,+ triggerId,+ automationId,+ actionId,+ status: ActionExecutionStatus.PENDING,+ sourceId: v4(),+ input: {+ promptName: "test-prompt",+ promptVersion: 1,+ action: "created",+ type: "prompt-version",+ },+ },+ });++ const webhookInput: WebhookInput = {+ projectId,+ automationId,+ executionId,+ payload: {+ prompt: PromptDomainSchema.parse(fullPrompt),+ action: "created",+ type: "prompt-version",+ },+ };++ await executeWebhook(webhookInput, { skipValidation: true });++ // Verify webhook request was made+ const requests = webhookServer.getReceivedRequests();+ expect(requests).toHaveLength(1);++ const request = requests[0];+ expect(request.url).toBe("https://webhook-201.example.com/test");+ expect(request.method).toBe("POST");++ // Verify execution was marked as completed (not error)+ const execution = await prisma.automationExecution.findUnique({+ where: { id: executionId },+ });+ expect(execution?.status).toBe(ActionExecutionStatus.COMPLETED);+ expect(execution?.startedAt).toBeDefined();+ expect(execution?.finishedAt).toBeDefined();+ });+it("should handle webhook endpoint returning error", async () => {const fullPrompt = await prisma.prompt.findUnique({where: { id: promptId },@@ -413,7 +499,7 @@ describe("Webhook Integration Tests", () => {});expect(execution?.status).toBe(ActionExecutionStatus.ERROR);expect(execution?.error).toContain(- `Webhook does not return 200: failed with status 500 for url https://webhook-error.example.com/test and project ${projectId}`,+ `Webhook does not return 2xx status: failed with status 500 for url https://webhook-error.example.com/test and project ${projectId}`,);expect(execution?.output).toMatchObject({httpStatus: 500,@@ -488,7 +574,7 @@ describe("Webhook Integration Tests", () => {expect(execution?.status).toBe(ActionExecutionStatus.ERROR);expect(execution?.error).toContain(- `Webhook does not return 200: failed with status 500 for url https://webhook-error.example.com/test and project ${projectId}`,+ `Webhook does not return 2xx status: failed with status 500 for url https://webhook-error.example.com/test and project ${projectId}`,);}diff --git a/worker/src/queues/webhooks.ts b/worker/src/queues/webhooks.tsindex d4a69890a2..9aa65e08e6 100644--- a/worker/src/queues/webhooks.ts+++ b/worker/src/queues/webhooks.ts@@ -206,12 +206,12 @@ async function executeWebhookAction({httpStatus = res.status;responseBody = await res.text();- if (res.status !== 200) {+ if (!res.ok) {logger.warn(- `Webhook does not return 200: failed with status ${res.status} for url ${webhookConfig.url} and project ${projectId}. Body: ${responseBody}`,+ `Webhook does not return 2xx status: failed with status ${res.status} for url ${webhookConfig.url} and project ${projectId}. Body: ${responseBody}`,);throw new Error(- `Webhook does not return 200: failed with status ${res.status} for url ${webhookConfig.url} and project ${projectId}`,+ `Webhook does not return 2xx status: failed with status ${res.status} for url ${webhookConfig.url} and project ${projectId}`,);}} catch (error) {