Files
buzz/schema/tables
Tom Brow eae69483fd fix(push-gateway): retry, don't drop, a delivery replayed while its first attempt is in flight (#9802)
The relay gives up on a push gateway delivery call after 2 seconds and
retries the same `request_id` with a fresh NIP-98 event. A gateway send
can take much longer than that: an FCM token mint has a 15 second
deadline, and the APNs and FCM sends each have a 15 second timeout. A
retry that arrived while the first attempt was still sending hit the
request replay fence and got `404 invalid_grant`. The relay reads a 404
on a retry as "the earlier attempt already finished" and completes the
wake. If the first attempt then failed retryably, nothing ever sent the
wake, and the notification was silently lost.

This change makes the gateway tell an in-flight request apart from a
finished one:

- Admission records the request id as in flight. A terminal outcome
marks it finished, and a retryable outcome releases it, as before.
- A replay of an in-flight id now gets `503
{"status":"retry","retry_after_seconds":5}`. Nothing is sent and no
quota is charged, so the relay's existing 503 path retries with backoff.
- A replay of a finished id still gets 404, so the relay's existing
handling of a finished attempt is unchanged.

Postgres gets a `finished` column on
`push_gateway_delivery_request_replays` (gateway migration 0009,
mirrored in relay migration 0105). It defaults to `true`, and the
gateway writes `false` explicitly on admission. Rows written before this
migration, or by an older gateway during a rollout or rollback,
therefore keep today's behavior. The constant default adds the column
without rewriting the table.

### Validation

-
[`replay_while_first_attempt_is_in_flight_is_retried_not_dropped`](3deaefb2b8/crates/buzz-push-gateway/src/http_delivery_tests.rs)
holds a first send open in the transport. It checks that a retry of the
same request gets 503 retry without sending, that the first attempt's
retryable failure releases the id so the next retry sends, and that a
finished id still answers 404.
-
[`replay_of_unfinished_request_is_in_flight_until_it_finishes`](3deaefb2b8/crates/buzz-push-gateway/src/authority.rs)
covers the in-memory store, and
[`unfinished_request_replay_is_in_flight_on_real_postgres`](3deaefb2b8/crates/buzz-push-gateway/src/postgres.rs)
covers Postgres, including that an in-flight replay charges no quota.
- The gateway's Postgres suite, including the desired-state schema
parity test, ran against a local PostgreSQL 17.

### Regressions

- A gateway that crashes mid-send now leaves the request id in flight
until the request expires, so the relay keeps retrying until its attempt
limit (8 attempts, about 10.5 minutes) or the request expiry, whichever
comes first. Before this change it got a 404 and dropped the wake.
- Admission now runs one more indexed primary-key read inside the
transaction that already locks the installation row.

---------

Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
2026-11-20 14:37:26 -05:00
..