# When something fails

> What happens, and what you see, when the database, the e-mail provider, a key, a provider or the engine itself fails.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://data.docs.sypnia.com/architecture/failures/

For agents: Failure modes: database unreachable → 503 database_unavailable with Retry-After, nothing half-written (one transaction per request), sessions stay valid until access tokens expire; connections exhausted → wait up to 2 s for a pooled connection then 503; e-mail provider down → the one-time token is kept, the call answers 202 email_queued_retry and the engine retries 3 times over 10 min, then audit email_failed and a console warning; bounce/complaint → address suppressed; Google/GitHub down → provider sign-in fails with provider_unavailable, other methods work; signing-key rotation → overlap in JWKS, no sign-outs; KMS unavailable → cached data keys keep signing, cold instances answer 503; engine crash → stateless, the next instance serves; refresh reuse → session revoked; Lambda throttled → 429/503 with Retry-After. No dead-letter queues: the engine has no queues; e-mail retries are rows in Postgres.

The engine keeps no state of its own and does every change in **one transaction**. So most failures end in a clean «try again», never in half-written data.

| What fails                            | What happens                                                                                                                                          | What callers see                                          | What you do                                                                                                    |
| ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| **The database is unreachable**       | Nothing is written. Already-issued access tokens keep working for the Data API only if the database is back; their own validity does not depend on it | `503 database_unavailable` with `Retry-After`             | Restore the database; nothing to clean up                                                                      |
| **All connections are busy**          | The request waits up to 2 seconds for one                                                                                                             | `503 pool_exhausted` after 2 s                            | Raise the pool or the database size ([Scaling](https://data.docs.sypnia.com/architecture/scaling-and-pooling)) |
| **The e-mail provider is down**       | The one-time token is kept; the e-mail is retried 3 times over 10 minutes from a row in Postgres                                                      | `202` with `email_queued_retry`; the person can ask again | Fix the provider; the console shows a warning and the audit log has `email_failed`                             |
| **An address bounces or complains**   | The address is suppressed for auth e-mails                                                                                                            | Later e-mails to it are skipped                           | The person updates their address                                                                               |
| **Google or GitHub is down**          | Provider sign-in cannot finish                                                                                                                        | `provider_unavailable` on the callback                    | Other sign-in methods still work                                                                               |
| **A signing key is rotated**          | The new key is published before it signs; the old one stays published until its tokens expire                                                         | Nothing                                                   | Nothing                                                                                                        |
| **KMS is unavailable**                | Instances already running keep their decrypted data key in memory and keep working; a new instance cannot start signing                               | `503 keys_unavailable` from cold instances only           | Wait for KMS; nothing is lost                                                                                  |
| **The engine crashes or is replaced** | It keeps nothing between requests; the next instance serves                                                                                           | At most the in-flight request fails                       | Nothing                                                                                                        |
| **A refresh token is used twice**     | Reuse after the window revokes the session                                                                                                            | `invalid_grant` (`refresh_token_reused`)                  | The person signs in again                                                                                      |
| **Too many requests**                 | Rate limits or the function's concurrency limit                                                                                                       | `429` or `503` with `Retry-After`                         | Raise limits, or find the client misbehaving in the audit log                                                  |

## No queues, no dead letters

The engine has no message queues, so there are no dead-letter queues to watch. The only background work — retrying e-mails and deleting expired one-time tokens, assertion ids and old audit rows — is driven by rows in Postgres and run by the engine on a schedule (every minute in Sypnia Cloud, from EventBridge; `sypnia-data tick` when self-hosted).

## What is alerted

In the AWS template, CloudWatch alarms fire on: function errors above 1 % for 5 minutes, throttles, database connections above 80 % of the limit, and e-mail failures above 5 in 10 minutes.
