fix(notify,esg): classify dropped SMTP connections, OAuth2 token-endpoint outages and body-read connection loss as transient (NTF-2, ESG-1, WP4 task 4.6)

This commit is contained in:
Joseph Doherty
2026-12-03 09:58:10 -05:00
parent 5f7b850af2
commit 11992075e8
8 changed files with 210 additions and 14 deletions
@@ -144,7 +144,8 @@ A small `SmsErrorClassifier` mirrors the External System Gateway pattern:
### Error Classification (Email)
Each `Deliver(...)` call returns one of `success | transient failure | permanent failure`, consistent with the External System Gateway pattern. There is **no synchronous permanent-failure return to the script** — `Send()` returns immediately, before any delivery is attempted.
- **Transient failures** (connection refused, timeout, SMTP 4xx temporary errors): The Notification Outbox moves the row to `Retrying` and schedules another attempt per the SMTP configuration's retry settings.
- **Transient failures** (connection refused, timeout, SMTP 4xx temporary errors, a connection dropped mid-session — MailKit's `IOException`, including one wrapping a `SocketException` — a TLS handshake that failed mid-way, and an OAuth2 token-endpoint outage: no response, HTTP 5xx/408/429, or the token request timing out): The Notification Outbox moves the row to `Retrying` and schedules another attempt per the SMTP configuration's retry settings. (NTF-2, 2026-12: before this the dropped connection, the handshake failure and the token-endpoint outage fell through as unclassified and were parked at once with `RetryCount` 0.) `SmtpErrorClassifier` walks the inner-exception chain for the socket/timeout/IO causes.
- **Broken credentials stay permanent**: a 4xx other than 408/429 from the OAuth2 token endpoint, or a malformed credential triple, parks the row — retrying a bad secret only burns token-endpoint calls.
- **Permanent failures** (SMTP 5xx permanent errors, e.g., mailbox not found): The Notification Outbox moves the row to `Parked` with the error in `LastError`. The notification will never deliver, and an operator can review or discard it on the Central UI Notification Outbox page.
- Retries exhausted on a transient failure also result in a `Parked` row.
- A script observes failures only by calling `Notify.Status(id)` and seeing a `Parked` status — not as a synchronous exception.