Skip to content

test(messaging): pin the retry verdict for the SMTP replies a project's server sends - #14544

Merged
levivannoort merged 1 commit into
mainfrom
fix/mails-retry-transient-smtp
Oct 15, 2026
Merged

levivannoort merged 1 commit into
mainfrom
fix/mails-retry-transient-smtp

Conversation

@levivannoort

Copy link
Copy Markdown
Member

What

The only change is tests. The mails worker already classifies SMTP failures the way this work asked for (7160cca211, "retry a project's SMTP that failed for now, end one that refused for good"):

  • The SMTP adapter (packages/messaging/src/Adapter/Email/SMTP.php, permanent()) marks a result permanent only for a 5xx reply class (Utopia\SMTP\Outcome::fromCode), a missing required capability, or a login refused with a 5xx.
  • Workers/Mails.php throws PermanentFailure for a permanent refusal from a project's own SMTP. Any other failure throws a plain Exception, which is retriable.

This PR covers the reply codes the existing data provider did not, each spoken by a real socket through ScriptedSmtpServer:

Reply / condition Where in the session Verdict
421 in place of the login answer (the case seen from smtp.hostinger.com in sgp1) retriable
421 at RCPT retriable
451 at MAIL FROM retriable
451 after DATA (greylisting) retriable
452 at RCPT retriable
no greeting (read timeout) connect retriable
553 at MAIL FROM (sender rejected) permanent
550 5.1.1 at RCPT (mailbox unknown) permanent
554 after DATA permanent

Already covered before this PR: 535 login, 554 greeting, 551 EHLO+HELO, 550 sender domain, 550 RCPT (permanent); 454 login, 421 greeting, 450 RCPT, 450 / 421 EHLO, hang-up, closed port (retriable); no STARTTLS when required (permanent); a multi-host list is permanent only when every host refused for good.

Seen red

I mutated SMTP::permanent() and the per-recipient Outcome::Permanent checks two ways and ran SMTPRefusalTest:

  • Everything permanent: 15 failures, including every new retriable case and the never-greets test.
  • Everything retriable: 11 failures, including the new 553, 550 5.1.1 and 554-after-DATA cases.

With the source restored, all 28 cases pass (bin/monorepo test messaging --linked: 142 unit tests OK), and bin/monorepo check messaging passes Pint, PHPStan and Rector.

Why production still dead-letters a 421

The 421 in sgp1 was thrown as Exception (retriable), and it still went to the dead stream at attempt 1/1. Every production region runs the mails queue with maxDeliver=1 and no backoff (application-configuration cloud/production/cloud/*.yaml, _APP_CONNECTIONS_QUEUE_MAILS). A retriable failure cannot be retried until that changes. The proposed change is ackWait=60&maxDeliver=3&backoff=60,300. It is tracked separately in appwrite-labs/cloud#6559 and not made here.

Not covered

No unit test sits on the worker's PermanentFailure/Exception mapping, because AGENTS.md keeps workers out of the unit suite. No E2E drives a project SMTP that answers 4xx through the mails worker and the NATS queue.

Related: appwrite-labs/cloud#6448

…project's SMTP sends

421 at the login and at RCPT, 451 at MAIL FROM and after DATA, 452 at RCPT
and a host that never greets are worth repeating; 553 for the sender, 550
for the mailbox and 554 after DATA are final. Each is spoken by a real
socket, as the existing cases are.
@luxor-code-review

luxor-code-review Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR extends SMTPRefusalTest with new data-provider cases for 5xx permanent refusals (sender rejected, unknown recipient, message refused after DATA) and 4xx transient conditions (421 session closes at login and RCPT, 451/452 lookups and storage, greylisting after DATA), plus a new test asserting that a listening-but-silent host yields a retryable No SMTP host answered result.

Files Change
packages/messaging/tests/Adapter/Email/SMTPRefusalTest.php Adds eight provider cases distinguishing permanent from retryable SMTP replies and a new real-socket test for a host that never sends a greeting.

Reviewed commit: beb30e8

@ghost

ghost commented Oct 15, 2026

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Adds SMTP refusal cases for additional temporary and permanent replies, including a timeout when the server never sends a greeting. The tests assert each failure’s retry verdict through the messaging SMTP adapter.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 1
File Change
packages/messaging/tests/Adapter/Email/SMTPRefusalTest.php Adds reply-code cases and a never-greets timeout case to lock down retry verdicts.

Reviewed beb30e8 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/mails-retry-transient-smtp (after).

Metric Before After Change
🚀 Requests/sec 210.71 211.97 ⚪ +0.6%
⏱️ Latency P50 80.2 ms 81.73 ms ⚪ +1.9%
⏱️ Latency P95 192.74 ms 192.34 ms ⚪ -0.2%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 81.73 192.34 13,623 211.97 -0.4
Account 152.53 312.58 717 11.87 +27.91
TablesDB 78.8 149.05 7,409 118.21 +4.58
Storage 74.72 168.02 3,585 58.52 -7.44
Functions 118.55 234.61 1,912 31.87 -13.57

Top API waits (after)

API request Max wait (ms)
account.name.update 424.1
account.prefs.update 364.61
functions.create 349.75
tablesdb.rows.create 347.7
account.get 347.55

@levivannoort
levivannoort merged commit a1e7cdb into main Oct 15, 2026
32 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant