Skip to content

refactor(auth): email senders drop or send through one path - #584

Merged
PiquelChips merged 2 commits into
mainfrom
refactor/544-operations-email-sender
Nov 21, 2026
Merged

PiquelChips merged 2 commits into
mainfrom
refactor/544-operations-email-sender

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Part of #544. Stacked on #579: its base is refactor/544-operations-shutdown.

The email, announcement and invitation senders each repeated the same three steps: drop the delivery while email is disabled, drop it once nothing is left to send, and otherwise compose and send. EmailSender::mail now holds them once. It takes the lookup as a future, so a disabled relay still reads nothing from the database. deliver, announce and invite keep their names and docs, since the tests call them, and each now calls mail.

Five places also built DeliveryError::Retryable { failure, retry_after: None } by hand. DeliveryError::retryable(failure) builds it now.

  • Tests merged or removed: none. The test files still build the variant by hand; their fixtures belong to the test-setup thread (S1).
  • Files edited outside the Operations area: none.
  • Proof that behaviour is unchanged:
    • Each drop logs the same message as before; the {gone} text is formatted into the same string.
    • The lookup future is lazy, so the order of checks is unchanged.
    • The insta snapshots under deliveries/email/snapshots are unchanged, and no .snap.new appeared.
    • just db test: 495 of 497 pass. The two failures are the keys::tests statement timeouts that fail the same way on main.

Checks: just fmt, cargo clippy with and without --all-features (-D warnings), cargo doc -D warnings, just db test.

Note

Written by Claude Opus 5.5 in Claude Code and reviewed by Claude Opus 5.5 (via T3 Code)

🤖 Generated with Claude Code

Scope: auth-service deliveries and jobs (5 files, +73/−74).

Email delivery (deliveries/email/mod.rs, +23/−28 in file set):

  • Adds a shared mail method for account emails, announcements, and invitations.
  • mail drops delivery without a lookup when email is disabled.
  • mail drops delivery when content is absent, and logs the supplied reason.
  • Otherwise mail composes and sends the message.
  • Content lookups are passed as futures, so a disabled relay performs no database read.
  • Replaces manual Retryable { retry_after: None } construction with DeliveryError::retryable.

Error constructor (deliveries/mod.rs):

  • Adds pub(crate) const fn retryable(failure: Failure) -> DeliveryError.
  • Replaces direct Retryable construction in the send-timeout fallback.

Shutdown handling (deliveries/mod.rs, jobs/mod.rs):

  • Adds Shutdown::unless, which races work against shutdown with a biased select. It returns None when shutdown wins.
  • Replaces biased tokio::select! waits in the worker claim, polling, backlog-tick, and backlog-query paths.
  • The exclusive-job loop uses it for interval ticks and lock acquisition. Cleanup uses it for the inter-batch pause.

Transport and signing (deliveries/outbound.rs, deliveries/backchannel.rs):

  • transport_error uses retryable for resolution, timeout, and connection failures. Forbidden resolutions stay permanent. Builder errors stay permanent.
  • Backchannel signing failures use retryable(Failure::Signing).

Not verified: test results and snapshot status were not checked against the current head.

@PiquelChips
PiquelChips marked this pull request as draft November 20, 2026 07:55
@github-project-automation github-project-automation Bot moved this to Needs Triage in sourceorigin.dev Nov 20, 2026
@PiquelChips PiquelChips added apps/auth-service Origin Auth at auth.sourceorigin.dev, its settings and developer console, and the operator CLI refactor No behviour changes labels Nov 20, 2026
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 46 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3a8da1f1-9dc3-4e61-b63a-1e87f785f376
Commits

Reviewing files that changed from the base of the PR and between 90a2a4d and 5840617.

Files selected for processing: 4

  • apps/auth-service/src/deliveries/backchannel.rs
  • apps/auth-service/src/deliveries/email/mod.rs
  • apps/auth-service/src/deliveries/mod.rs
  • apps/auth-service/src/deliveries/outbound.rs

No actionable comments were generated in the recent review.

Walkthrough

The auth service now constructs retryable delivery errors through a shared method, routes several email types through shared content handling, and uses a shutdown-aware wait helper in delivery and job loops.

Changes: Auth service delivery and shutdown

Layer / File(s) Summary
Retryable delivery errors
apps/auth-service/src/deliveries/mod.rs, apps/auth-service/src/deliveries/backchannel.rs, apps/auth-service/src/deliveries/email/mod.rs, apps/auth-service/src/deliveries/outbound.rs
A new constructor creates retryable errors with no requested retry delay. Signing, database, timeout, lookup, and connection failures use it. Permanent error classifications remain unchanged.
Shared email content handling
apps/auth-service/src/deliveries/email/mod.rs
Account emails, announcements, and invitations delegate content resolution and sending to a shared method. The method skips content lookup when email is disabled and succeeds when content is absent.
Shutdown-aware waits
apps/auth-service/src/jobs/mod.rs, apps/auth-service/src/deliveries/mod.rs
Shutdown::unless races work against shutdown. Delivery and job loops use it for their waits and stop when shutdown wins.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Merge Risk: Minimal · previous review 90a2a

This change refactors email delivery and shutdown handling without intending to change behavior. No actionable merge-blocking risk was found in the supplied context.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title is a conventional commit that names the main change: the email senders (account, announcement, invitation) now share one send path, and rarely-used drop logic is consolidated. It matches the…
Description check Passed The description follows the template's main sections. The title block is not applicable here. The What and why section explains the shared mail path and the retryable constructor, and it cites the par…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title is a conventional commit that names the main change: the email senders (account, announcement, invitation) now share one send path, and rarely-used drop logic is consolidated. It matches the changeset and the objectives, which describe the shared EmailSender::mail path and the DeliveryError::retryable helper. The title does not mention the retryable constructor or the shutdown changes, but it covers the primary change.

Full details: Description check

Explanation

The description follows the template's main sections. The title block is not applicable here. The What and why section explains the shared mail path and the retryable constructor, and it cites the parent issue (#544) and the stacked base. It does not include a 'Closes #' line, since this is part of #544. The Testing section lists commands run, the two known failing tests, and what was not changed. The Checklist is absent. The description does not check the surface-coverage items or confirm that generated files are regenerated. It also does not state whether 'just validate' passed; it lists fmt, clippy, doc and db test, but not validate.

Resolution

Optional: add the template checklist, state whether just validate passed, and confirm no generated files need regeneration. The surface-coverage item may need a note saying it does not apply (auth-service internal change).

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the mail at dawn
The quiet queue rolls safely on
No letter needs a needless search
Retry notes keep their proper perch
When shutdown calls, the loops grow still
And carrots wait beside the sill

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 782c58ed-5137-4d77-a94f-182462786956
Commits

Reviewing files that changed from the base of the PR and between b234969 and 90a2a4d.

Files selected for processing: 5

  • apps/auth-service/src/deliveries/backchannel.rs
  • apps/auth-service/src/deliveries/email/mod.rs
  • apps/auth-service/src/deliveries/mod.rs
  • apps/auth-service/src/deliveries/outbound.rs
  • apps/auth-service/src/jobs/mod.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@PiquelChips
PiquelChips marked this pull request as ready for review November 20, 2026 08:26
@PiquelChips
PiquelChips marked this pull request as draft November 21, 2026 14:00
@PiquelChips
PiquelChips marked this pull request as ready for review November 21, 2026 15:01
Base automatically changed from refactor/544-operations-shutdown to main November 21, 2026 17:38
@github-project-automation github-project-automation Bot moved this from Needs Triage to Ready in sourceorigin.dev Nov 21, 2026
The email, announcement and invitation senders each repeated the same
checks: drop while email is disabled, drop once nothing is left to send,
else compose and send. EmailSender::mail holds them, and
DeliveryError::retryable builds a retryable failure without Retry-After.
@PiquelChips
PiquelChips force-pushed the refactor/544-operations-email-sender branch from 90a2a4d to 5840617 Compare November 21, 2026 17:52
@PiquelChips
PiquelChips added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit 7f1c829 Nov 21, 2026
14 checks passed
@PiquelChips
PiquelChips deleted the refactor/544-operations-email-sender branch November 21, 2026 18:26
@github-project-automation github-project-automation Bot moved this from Ready to Done in sourceorigin.dev Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apps/auth-service Origin Auth at auth.sourceorigin.dev, its settings and developer console, and the operator CLI refactor No behviour changes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant