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
@@ -107,6 +107,7 @@ Scripts choose between two call modes per invocation, mirroring the dual-mode da
- Each external system definition specifies a **timeout** (`TimeoutSeconds`) that applies to all method calls on that system. `0` means unset — the gateway's configured `DefaultHttpTimeout` applies instead. Editable via the Central UI External System form ("Timeout (seconds)", helper text "0 = use gateway default") and deployed to sites in the artifact alongside the rest of the definition.
- Error classification by HTTP response:
- **Transient failures** (connection refused, timeout, HTTP 408, 429, 5xx): Behavior depends on call mode — `CachedCall` buffers for retry; `Call` returns error to script.
- **A connection lost while reading the response body** (headers received, then a reset or truncation — `IOException`/`HttpIOException`/`HttpRequestException` from the body read) is **transient** when the status was a success or a transient code, exactly like a timeout at the same point (ESG-1, 2026-12; before, the raw `IOException` escaped into the script and `CachedCall` buffered nothing). With a permanent status the call stays permanent — losing the error body does not make it retryable.
- **Permanent failures** (HTTP 4xx except 408/429): Always returned to the calling script regardless of call mode. Logged to Site Event Logging. For `CachedCall`, the failure is additionally recorded as a terminal `Failed` tracking record — so even a never-buffered cached call has an authoritative status record.
- This classification ensures the S&F buffer is not polluted with requests that will never succeed.
- **Idempotency note**: `CachedCall` retries may result in duplicate delivery if the external system received the original request but the response was lost. Callers should use `CachedCall` only for operations that are idempotent or where duplicate delivery is acceptable.
@@ -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.