Skip to content

Report mailroom storage errors as server errors - #2070

Open
Christopherdominic wants to merge 1 commit into
payjoin:masterfrom
Christopherdominic:mailroom-db-error-status
Open

Christopherdominic wants to merge 1 commit into
payjoin:masterfrom
Christopherdominic:mailroom-db-error-status

Conversation

@Christopherdominic

@Christopherdominic Christopherdominic commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #420.

put_payjoin_v1 mapped every storage error to 400 Bad Request, so a failing backend showed up as a malformed client request in the response status, the request metrics (status_code label) and the logs (a warn! "Bad request" instead of an error!). post_mailbox mapped every storage error to 500, including a full mailbox store, which mailbox reads already report as 503.

This moves the mapping that handle_peek already had into a shared handle_db_error and uses it for both writes:

Storage error put_payjoin_v1 post_mailbox reads (unchanged)
Operational 400 → 500 500 500
OverCapacity 400 → 503 500 → 503 503
V1SenderUnavailable 400 → 410 n/a 410

With the files backend, post_v1_response only returns V1SenderUnavailable, so in practice the visible change there is 400 → 410 for a receiver replying after the v1 sender left. The Operational mapping matters for any other Db implementation.

Client impact: handler errors leave the gateway unencapsulated, so clients see these as the outer HTTP status. This is a behavior change on the v1 response path: receivers treat 4xx as fatal and 5xx as transient, so an operational storage failure that used to abort on 400 now retries on 500. Retrying a backend failure is intended. With the files backend, post_v1_response only returns V1SenderUnavailable, so the visible change there is 400 → 410, which stays fatal.

Tests

  • put_v1_response_with_no_waiting_sender_returns_gone: a PUT through the gateway with no waiting sender returns 410. It fails with 400 against the old mapping.
  • storage_errors_map_to_server_side_statuses: unit test of handle_db_error for each variant.

Adds a payjoin-mailroom/changelog.d/storage-error-statuses.md fragment.

Checked locally: cargo fmt --all -- --check, cargo clippy --all-targets --keep-going --all-features -- -D warnings, cargo test -p payjoin-mailroom --all-features, contrib/release/changelog-fragments.sh payjoin-mailroom/changelog.d. codespell didn't complete locally (nix shell timed out), so I'm relying on CI for that.

Reviewer: @DanGould

AI disclosure: the change, commit message and this description were drafted with AI assistance (Claude Code). A local AI review of the branch was run against the AGENTS.md criteria with no findings.

Pull Request Checklist

Please confirm the following before requesting review:

@coveralls

coveralls commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 47002240871

Coverage increased (+0.1%) to 87.887%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: 2 uncovered changes across 1 file (25 of 27 lines covered, 92.59%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
payjoin-mailroom/src/directory.rs 27 25 92.59%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 18591
Covered Lines: 16339
Line Coverage: 87.89%
Coverage Strength: 103.16 hits per line

💛 - Coveralls

@caarloshenriq caarloshenriq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Concept ACK 72f9177

Mapping looks right: V1SenderUnavailable reaches put_payjoin_v1 intact through the db service layer, and reverting that call to BadRequest makes the new 410 test fail. Responses stay empty, so the unexpected-variant message only goes to the log.

One thing before ACK: the receiver treats 4xx as fatal and 5xx as transient, so moving operational errors on the v1 response from 400 to 500 changes receiver behavior from aborting to retrying. That's probably what we want, but the commit message and changelog should describe it as a change (inline). Happy to ACK once that's updated.

Comment thread payjoin-mailroom/src/directory.rs Resolved
put_payjoin_v1 mapped every storage error to 400 Bad Request, so a
failing backend looked like a malformed client request in the response
status, the request metrics, and the logs. post_mailbox mapped every
storage error to 500, including a full mailbox store, which mailbox
reads already report as 503.

Move the mapping that handle_peek already had into a shared
handle_db_error and use it for both writes. Operational failures become
500, a full store 503, and a v1 response for a sender that is no longer
waiting 410, matching what reads return.

This changes v1 receiver behavior on operational storage failures.
Receivers treat 4xx as fatal and 5xx as transient, so a v1 response
that previously aborted on 400 now retries on 500; retrying a backend
failure is intended. With the files backend post_v1_response only
reports V1SenderUnavailable, so the status observed there moves from
400 to 410 and remains fatal.

Closes payjoin#420.

This branch has not been deployed

No deployments
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.

directory should not leak operational errors to client

3 participants