Repository navigation
fix(den-api): surface invite email failures instead of silently dropping - #1483
Merged
Merged
Conversation
added 3 commits
April 17, 2026 16:31
…owing Loops failures in sendDenOrganizationInvitationEmail and sendDenVerificationEmail were being caught and logged at warn level, so the HTTP handlers still returned 201 'Invitation created' even when no email ever left the process. Ben observed this with two live invitations: the DB row was pending, the UI showed it, but one of two recipients never received the email and clicking resend re-ran the same silent-failure path. Root cause (from an explore audit): - email.ts:129,132 swallowed non-2xx Loops responses and fetch throws. - invitations.ts awaited the send and unconditionally returned 2xx. - There is no 'skip email if user already exists' branch anywhere; the Slack hypothesis was wrong. The failure mode is provider-side and was invisible because of the swallow. Changes: - Introduce DenEmailSendError with a stable reason tagged union (loops_not_configured | loops_rejected | loops_network). - sendDenOrganizationInvitationEmail and sendDenVerificationEmail now throw DenEmailSendError on failure. Dev-mode short-circuit is preserved (still logs the payload and returns cleanly). - POST /v1/orgs/:orgId/invitations catches DenEmailSendError, logs via console.error with a stable [auth][invite_email_failed] prefix (greppable across deployments), and returns 502 invitation_email_failed with a human-readable message and the invitationId so the UI can correlate and offer a retry. The row is left pending intentionally so the next submit becomes a real resend. - Document the 502 response in the OpenAPI describeRoute. Operator note: if LOOPS_TRANSACTIONAL_ID_DEN_VERIFY_EMAIL is unset the signup OTP endpoint will now return a real error instead of silently stranding the user at the OTP screen forever. This is intentional; the previous behavior was a latent signup-breaking bug.
PR #1476 introduced a build step that reads apps/desktop/package.json to bake in a default latest-app-version, but packaging/docker/Dockerfile.den does not ship the Tauri desktop sources. As a result, the den-dev Docker stack fails to build after the PR landed. Gracefully fall back to 0.0.0 (matching the runtime default) when the file is absent, and allow a DEN_API_LATEST_APP_VERSION env override so deployers can still pin a real value.
scripts/smoke-email-failures.mjs exercises the DenEmailSendError paths against the built dist/ of den-api. Ships with instructions so a reviewer can rerun it inside the docker-compose den-dev container with a single command. Also parameterises OPENWORK_DEV_MODE in the den compose service so the failure paths can be reached from outside the container when needed (defaults to 1; override with OPENWORK_DEV_MODE=0 at compose time).
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
benjaminshafii
pushed a commit
that referenced
this pull request
May 15, 2026
…ing (#1483) * fix(den-api): surface invitation email send failures instead of swallowing Loops failures in sendDenOrganizationInvitationEmail and sendDenVerificationEmail were being caught and logged at warn level, so the HTTP handlers still returned 201 'Invitation created' even when no email ever left the process. Ben observed this with two live invitations: the DB row was pending, the UI showed it, but one of two recipients never received the email and clicking resend re-ran the same silent-failure path. Root cause (from an explore audit): - email.ts:129,132 swallowed non-2xx Loops responses and fetch throws. - invitations.ts awaited the send and unconditionally returned 2xx. - There is no 'skip email if user already exists' branch anywhere; the Slack hypothesis was wrong. The failure mode is provider-side and was invisible because of the swallow. Changes: - Introduce DenEmailSendError with a stable reason tagged union (loops_not_configured | loops_rejected | loops_network). - sendDenOrganizationInvitationEmail and sendDenVerificationEmail now throw DenEmailSendError on failure. Dev-mode short-circuit is preserved (still logs the payload and returns cleanly). - POST /v1/orgs/:orgId/invitations catches DenEmailSendError, logs via console.error with a stable [auth][invite_email_failed] prefix (greppable across deployments), and returns 502 invitation_email_failed with a human-readable message and the invitationId so the UI can correlate and offer a retry. The row is left pending intentionally so the next submit becomes a real resend. - Document the 502 response in the OpenAPI describeRoute. Operator note: if LOOPS_TRANSACTIONAL_ID_DEN_VERIFY_EMAIL is unset the signup OTP endpoint will now return a real error instead of silently stranding the user at the OTP screen forever. This is intentional; the previous behavior was a latent signup-breaking bug. * fix(den-api): tolerate missing apps/desktop/package.json in Docker build PR #1476 introduced a build step that reads apps/desktop/package.json to bake in a default latest-app-version, but packaging/docker/Dockerfile.den does not ship the Tauri desktop sources. As a result, the den-dev Docker stack fails to build after the PR landed. Gracefully fall back to 0.0.0 (matching the runtime default) when the file is absent, and allow a DEN_API_LATEST_APP_VERSION env override so deployers can still pin a real value. * test(den-api): add smoke script for invite email failure paths scripts/smoke-email-failures.mjs exercises the DenEmailSendError paths against the built dist/ of den-api. Ships with instructions so a reviewer can rerun it inside the docker-compose den-dev container with a single command. Also parameterises OPENWORK_DEV_MODE in the den compose service so the failure paths can be reached from outside the container when needed (defaults to 1; override with OPENWORK_DEV_MODE=0 at compose time).
benjaminshafii
pushed a commit
that referenced
this pull request
May 15, 2026
…ing (#1483) * fix(den-api): surface invitation email send failures instead of swallowing Loops failures in sendDenOrganizationInvitationEmail and sendDenVerificationEmail were being caught and logged at warn level, so the HTTP handlers still returned 201 'Invitation created' even when no email ever left the process. Ben observed this with two live invitations: the DB row was pending, the UI showed it, but one of two recipients never received the email and clicking resend re-ran the same silent-failure path. Root cause (from an explore audit): - email.ts:129,132 swallowed non-2xx Loops responses and fetch throws. - invitations.ts awaited the send and unconditionally returned 2xx. - There is no 'skip email if user already exists' branch anywhere; the Slack hypothesis was wrong. The failure mode is provider-side and was invisible because of the swallow. Changes: - Introduce DenEmailSendError with a stable reason tagged union (loops_not_configured | loops_rejected | loops_network). - sendDenOrganizationInvitationEmail and sendDenVerificationEmail now throw DenEmailSendError on failure. Dev-mode short-circuit is preserved (still logs the payload and returns cleanly). - POST /v1/orgs/:orgId/invitations catches DenEmailSendError, logs via console.error with a stable [auth][invite_email_failed] prefix (greppable across deployments), and returns 502 invitation_email_failed with a human-readable message and the invitationId so the UI can correlate and offer a retry. The row is left pending intentionally so the next submit becomes a real resend. - Document the 502 response in the OpenAPI describeRoute. Operator note: if LOOPS_TRANSACTIONAL_ID_DEN_VERIFY_EMAIL is unset the signup OTP endpoint will now return a real error instead of silently stranding the user at the OTP screen forever. This is intentional; the previous behavior was a latent signup-breaking bug. * fix(den-api): tolerate missing apps/desktop/package.json in Docker build PR #1476 introduced a build step that reads apps/desktop/package.json to bake in a default latest-app-version, but packaging/docker/Dockerfile.den does not ship the Tauri desktop sources. As a result, the den-dev Docker stack fails to build after the PR landed. Gracefully fall back to 0.0.0 (matching the runtime default) when the file is absent, and allow a DEN_API_LATEST_APP_VERSION env override so deployers can still pin a real value. * test(den-api): add smoke script for invite email failure paths scripts/smoke-email-failures.mjs exercises the DenEmailSendError paths against the built dist/ of den-api. Ships with instructions so a reviewer can rerun it inside the docker-compose den-dev container with a single command. Also parameterises OPENWORK_DEV_MODE in the den compose service so the failure paths can be reached from outside the container when needed (defaults to 1; override with OPENWORK_DEV_MODE=0 at compose time).
This branch was successfully deployed
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.
Summary
Traces an issue Ben hit this week: he invited Jan and Omar to OpenWork Cloud; Jan received the email, Omar never did. Resending changed nothing and the UI kept showing Omar as pending. The Slack hypothesis was that invites to an existing user silently fail.
An audit (notes in the commit) shows there is no existing-user branch anywhere on the invite path. The actual bug is that
sendDenOrganizationInvitationEmailinee/apps/den-api/src/email.tscaught every Loops failure withconsole.warnand returned cleanly, soPOST /v1/orgs/:orgId/invitationsalways returned201 Created. The DB row was persisted, the UI showed it as pending, and nobody noticed the email provider had rejected the send.This PR stops swallowing the failure.
Changes
DenEmailSendErrorwith a stablereasontagged union (loops_not_configured|loops_rejected|loops_network) plustemplate,recipient, and optionaldetail.sendDenOrganizationInvitationEmailandsendDenVerificationEmailnow throwDenEmailSendErrorinstead of console-warning and swallowing. The dev-mode short-circuit is preserved —OPENWORK_DEV_MODE=1still logs the payload and returns cleanly, so local dev and CI are unaffected.POST /v1/orgs/:orgId/invitationscatchesDenEmailSendError, logs viaconsole.errorwith a stable[auth][invite_email_failed] organization=… invitation=… email=… reason=… detail=…prefix (greppable across deployments), and returns502 invitation_email_failedwith a human-readablemessageplus theinvitationIdso the UI can correlate and retry. The invitation row is intentionally left pending so the next submit becomes a real resend.describeRoute.ee/apps/den-api/scripts/smoke-email-failures.mjsso a reviewer can verify both failure paths without a real Loops account.Operator note:
sendDenVerificationEmailnow throws on Loops failure too. Previously, a missingLOOPS_TRANSACTIONAL_ID_DEN_VERIFY_EMAILwould silently drop the OTP and leave users stuck at the verification screen forever. It will now return a real error upstream — that's intentional.Testing
All runs performed against `packaging/docker/den-dev-up.sh` at commit $(git -C _repos/openwork-worktrees/invite-email-surface-failures rev-parse --short HEAD) with the den-api stack rebuilt.
1. Happy path (dev mode on, `OPENWORK_DEV_MODE=1`)
Signed up `[email protected]`, created org "Invite Test Org", invited `[email protected]`. UI flipped the Invitations tab counter to 1. `docker logs` showed:
```
[auth] dev organization invite email payload for [email protected]: {...}
```
No regression from the pre-refactor behaviour.
2. loops_not_configured path (dev mode off, Loops env unset)
```bash
docker cp ee/apps/den-api/scripts/smoke-email-failures.mjs :/app/ee/apps/den-api/scripts/smoke-email-failures.mjs
docker exec -e OPENWORK_DEV_MODE=0 node /app/ee/apps/den-api/scripts/smoke-email-failures.mjs [email protected]
```
Output:
```
[smoke] ok loops_not_configured {
reason: 'loops_not_configured',
template: 'organization_invite',
recipient: '[email protected]',
detail: undefined
}
```
3. loops_rejected path (dev mode off, Loops env set to bogus values)
```bash
docker exec -e OPENWORK_DEV_MODE=0 -e LOOPS_API_KEY=bogus \
-e LOOPS_TRANSACTIONAL_ID_DEN_ORG_INVITE_EMAIL=bogus \
node /app/ee/apps/den-api/scripts/smoke-email-failures.mjs [email protected]
```
Output:
```
[smoke] ok loops_rejected {
reason: 'loops_rejected',
template: 'organization_invite',
recipient: '[email protected]',
detail: 'Invalid API key'
}
```
`detail` is the real message from Loops, so both the server log and the UI `message` field will surface it.
4. What I did not run end-to-end in Chrome MCP
I did not drive the 502 response through the browser. Flipping `OPENWORK_DEV_MODE=0` inside the Den dev stack breaks the Better Auth cookie flow (401 on `/v1/me/orgs` once dev mode is off), which is a pre-existing dev-stack-only issue unrelated to this PR. The end-to-end UI verification for production traffic is:
How this helps the original Omar/Jan incident
The next time an invite silently fails in prod, operators now get:
Whether the original trigger for Omar was a Loops recipient-allowlist, a domain-block from a prior bounce, or a transactional-id typo, any of those will now be diagnosable immediately.
Related
Out of scope