Skip to content

Commit 2fd3426

Browse files
ericallamTrigger.dev RepoOps
authored andcommitted
fix(webhooks): give session deliveries the whd_ delivery id and the provider's id
A webhook delivery routed to an agent session now carries both ids on its envelope: ```ts onAction: async ({ action }) => { action.deliveryId; // "whd_...": the delivery in the dashboard and deliveries API, new on a replay action.externalDeliveryId; // the provider's id, e.g. Stripe's "evt_...", the same across replays }, ``` `deliveryId` previously held the provider's id. It now matches the id `webhook()` tasks, waiters and the deliveries API use. Mono-RevId: bc4eb9c3b90fc4b3fe15e3084d637819467a24f7
1 parent dba857b commit 2fd3426

5 files changed

Lines changed: 30 additions & 7 deletions

File tree

‎apps/webapp/app/v3/webhookEngine.server.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ function createWebhookEngine() {
197197
source,
198198
headers,
199199
deliveryId,
200+
externalDeliveryId,
200201
partId,
201202
endpoint,
202203
triggerConfigTemplate,
@@ -243,13 +244,29 @@ function createWebhookEngine() {
243244
? {
244245
chatId: externalId,
245246
trigger: "submit-message",
246-
channelEvent: { connectorId, event, source, headers, deliveryId, endpoint },
247+
channelEvent: {
248+
connectorId,
249+
event,
250+
source,
251+
headers,
252+
deliveryId,
253+
externalDeliveryId,
254+
endpoint,
255+
},
247256
}
248257
: {
249258
chatId: externalId,
250259
trigger: "action",
251260
actionSource: "webhook",
252-
action: { type: actionType, event, source, headers, deliveryId, endpoint },
261+
action: {
262+
type: actionType,
263+
event,
264+
source,
265+
headers,
266+
deliveryId,
267+
externalDeliveryId,
268+
endpoint,
269+
},
253270
};
254271
const part = JSON.stringify({ kind: "message", payload });
255272

‎internal-packages/webhook-engine/src/engine/fanout.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ containerTestWithIsolatedRedisNoClickhouse(
239239
targetId: "agent-x:order-events",
240240
externalId: "cus_1",
241241
actionType: "order.event",
242-
deliveryId: "evt_fan_1",
242+
deliveryId: delivery.friendlyId,
243+
externalDeliveryId: "evt_fan_1",
243244
partId: `${deliveryId}:agent-x:order-events`,
244245
endpoint: endpointContext,
245246
});

‎internal-packages/webhook-engine/src/engine/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,8 @@ export class WebhookEngine {
19031903
event: delivery.parsedEvent,
19041904
source: endpoint.source,
19051905
headers: (delivery.headers as Record<string, string> | null) ?? {},
1906-
deliveryId: delivery.externalDeliveryId,
1906+
deliveryId: delivery.friendlyId,
1907+
externalDeliveryId: delivery.externalDeliveryId,
19071908
triggerConfigTemplate: target.triggerConfigTemplate,
19081909
idempotencyKey: delivery.idempotencyKey,
19091910
isSessionStart: this.#evaluateSessionStart(target.startOn, delivery, endpoint),

‎internal-packages/webhook-engine/src/engine/ingest.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,10 @@ containerTestWithIsolatedRedisNoClickhouse(
855855
expect(calls[0]?.taskIdentifier).toBe("agent-x");
856856
expect(calls[0]?.actionType).toBe("order.event");
857857
expect((calls[0]!.event as { id: string }).id).toBe(eventId);
858-
expect(calls[0]?.deliveryId).toBe(eventId);
859-
860858
const d = await prisma.webhookDelivery.findFirst({ where: { id: result.deliveryId } });
859+
expect(calls[0]?.deliveryId).toBe(d?.friendlyId);
860+
expect(calls[0]?.deliveryId).toMatch(/^whd_/);
861+
expect(calls[0]?.externalDeliveryId).toBe(eventId);
861862
expect(d?.runId).toBe("srun_1"); // the session's run, from the port
862863
} finally {
863864
await engine.quit();

‎internal-packages/webhook-engine/src/engine/types.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ export type DeliverWebhookToSessionParams = {
216216
event: unknown; // delivery.parsedEvent
217217
source: string; // provider tag
218218
headers: Record<string, string>;
219-
deliveryId: string; // externalDeliveryId, surfaced on the envelope
219+
/** The delivery's friendly id (`whd_`): new on a replay, the same across retries of one delivery. */
220+
deliveryId: string;
221+
/** The provider's id for the delivery (e.g. Stripe's `evt_`), the same across replays. */
222+
externalDeliveryId: string;
220223
triggerConfigTemplate?: Record<string, unknown>;
221224
idempotencyKey: string;
222225
// Evaluated startOn: true (default) allows creating a new session; false means resume-only, so a

0 commit comments

Comments
 (0)