Repository navigation
feat(workflows): let email waits count only the execution's own emails - #540
Open
joanproductivo wants to merge 6 commits into
Open
joanproductivo wants to merge 6 commits into
joanproductivo wants to merge 6 commits into
Conversation
The header that carries a workflow step's custom recipient was spelled out four times across the email service and the email processor. It is now one exported constant next to the other email header helpers, so the workflow engine can recognise these emails too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A WAIT_FOR_EVENT step resumes when the event is tracked on the contact, so a wait for email.open after a SEND_EMAIL resumed on an open of any email: a newsletter, a receipt, or a notification another step sent to a custom recipient, which is recorded under the contact. The step config takes an optional scope. With scope "execution", the email events a workflow email produces (email.sent, email.delivery, email.open, email.click, email.bounce, email.complaint) only count when the email was sent to the contact by the waiting execution. Without a scope, or for any other event, waits behave as before. trackEvent now hands its email id to handleEvent, and the email is looked up once per event by primary key, only when a scoped wait needs it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
For a wait on an email event a workflow email produces, the step dialog shows "Only emails from this execution", which saves scope "execution". The workflows concept page explains the default, the scope, and that emails sent to a custom recipient never count for a scoped wait. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the two conflicts with next: email-processor.ts, where the job body moved into processEmailJob, keeps the recipient override header as the RECIPIENT_OVERRIDE_HEADER constant; packages/shared/src/index.ts exports both delivery.js and workflow-events.js. handleEvent combines the scope check with the filter on cancelled executions from useplunk#545. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
joanproductivo
added a commit
to joanproductivo/plunk-lite
that referenced
this pull request
Oct 25, 2026
Merges the branch as published before it was brought up to date with upstream next, so none of next's newer changes come along. A wait on an email event can be limited to the emails its own execution sent to the contact, with the "Only emails from this execution" switch (useplunk#540). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # apps/api/src/services/EmailService.ts
5 of 13 tasks
# Conflicts: # apps/api/src/services/WorkflowExecutionService.ts
A wait that counts only its own run's emails never resumes if that email is never sent or opened, so the dialog now refuses to save one without a timeout. "Execution" is our internal term; the editor says "run". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #537
What changed
WAIT_FOR_EVENTconfig takes an optionalscope:"contact"(default) or"execution". With"execution",email.sent,email.delivery,email.open,email.click,email.bounceandemail.complaintonly resume the wait when the email was sent to the contact by the waiting execution; emails a step sent to a custom recipient never count. Without a scope, or for any other event, waits behave exactly as before.trackEventpasses its email id tohandleEvent. The email is looked up at most once per event, by primary key, and only when a scoped wait matches.X-Plunk-Recipient-Override), spelled out four times in the email service and processor, is now one constant (separate refactor commit).canScopeWaitToExecutionin@plunk/shareddecides which events accept the scope, for both the engine and the step dialog, which shows an "Only emails from this execution" switch for those events. The MCP server's copy of the step schema accepts the field.Verification
WorkflowExecutionService.waitScope.test.ts(6 tests): unscoped waits resume on any email and look nothing up; scoped waits ignore other emails, custom-recipient sends and events without an email, resume only the execution that sent the email, and ignore the scope for other events. Newworkflow-events.test.tsin@plunk/shared(11 tests).tsc --noEmitclean for api, web, mcp and shared;@plunk/sharedbuilds.🤖 Generated with Claude Code