Skip to content

fix: Add Mailroom manager logic to more closely match reference - #194

Merged
ValeraFinebits merged 2 commits into
ValeraFinebits:masterfrom
benalleng:relay-block-on-error
Oct 12, 2026
Merged

ValeraFinebits merged 2 commits into
ValeraFinebits:masterfrom
benalleng:relay-block-on-error

Conversation

@benalleng

@benalleng benalleng commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

The btcpay plugin was not properly rejecting ohttp-relays when a call out resulted in a transient error meaning that if some error occured, in this case selecting the same server for mailroom and relay instead of dropping the relay for the remainder of the seession it just kept retrying. This adds the appropriate logic to drop the relay allowing a new relay to be selected avoiding the problems of that particular relay for the session.

This is pretty critical logic as it prevents errors that WILL occur whenever a relay and directory are chosen as the same server. depending on the server defaults chosen this could be a pretty high % of all sessions

Here was the error my directory saw.

2026-10-09T07:11:56.219037Z  WARN payjoin_mailroom::directory: Rejected OHTTP request from same-instance relay
2026-10-09T07:11:56.219217Z  WARN payjoin_mailroom::directory: Forbidden: Relay and gateway must be operated by different entities

and the implementation just saw this. but really any error should just drop a relay for a session and move on.

Unexpected response size 0, expected 8192

This was quickly vibed together but I wanted to post it this way rather than an issue as a demonstration of the problem + a possible fix. Feel free to close this in favor of a better fix or push additional changes to clean this up.

@benalleng benalleng added the bug Something isn't working label Oct 9, 2026
@benalleng
benalleng force-pushed the relay-block-on-error branch from 6df8980 to 4179fc7 Compare October 9, 2026 13:44
The btcpay plugin was not properly rejecting ohttp-relays when a
call out resulted in a transient error meaning that if some error
occured, in this case selecting the same server for mailroom and relay
instead of dropping the relay for the remainder of the seession it just
kept retrying. This adds the appropriate logic to drop the relay
allowing a new relay to be selected avoiding the problems of that
particular relay for the session.
@benalleng
benalleng force-pushed the relay-block-on-error branch from 4179fc7 to 1e2da17 Compare October 9, 2026 13:53
@benalleng

benalleng commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator Author

I am also working now to merge payjoin/rust-payjoin#1696 and some subsequent commits to fully bring the mailroom management logic into the core library so it may not be necessary for long. But as it stands now this is a bug in prod for this plugin.

@ValeraFinebits

Copy link
Copy Markdown
Owner

@benalleng Thanks for putting this together. I tested the receiver polling flow and found a few cases that still need attention: the same-instance rejection currently removes the session before another relay can be tried, downstream wallet errors can mark a healthy relay as failed, and temporary network failures can leave the session unable to retry after recovery.
I’ll build on your changes and take care of these follow-ups: narrow the error handling, make relay exclusions temporary and appropriately scoped, and add regression tests covering the session processor and recovery paths.

Copilot AI 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.

🟡 Changes recommended

Session-specific relay failures expire after ten minutes instead of remaining blocked for the session lifetime.

1 open finding
What changed in this PR

Adds session-aware OHTTP relay quarantine and failover to prevent repeated polling through an incompatible relay.

Changes:

  • Distinguishes session-specific HTTP/protocol failures from global transport failures.
  • Adds relay quarantine lifecycle management and HTTP status validation.
  • Adds extensive unit and end-to-end relay-flow coverage.
File Description
PayjoinReceiverStateProcessor.cs Quarantines relays after transient protocol failures.
PayjoinReceiverSessionStore.cs Clears quarantine when sessions are removed.
PayjoinReceiverSessionProcessor.cs Documents deferred storage recovery.
PayjoinReceiverRelayRequestSender.cs Adds session-aware selection and failure classification.
PayjoinReceiverRelayClient.cs Validates HTTP status before reading bodies.
PayjoinReceiverProposalFinalizer.cs Documents deferred POST recovery.
PayjoinMailroomManager.cs Implements session relay quarantine and injectable time.
Plugin.cs Injects the mailroom manager into session storage.
PayjoinReceiverStateProcessorTests.cs Tests truncated poll-response handling.
PayjoinReceiverRelayRequestSenderTests.cs Tests quarantine scope, expiry, and cancellation.
PayjoinReceiverRelayFlowTests.cs Adds full receiver relay-flow scenarios.
PayjoinReceiverRelayClientTests.cs Tests status validation and body timeouts.
PayjoinMailroomManagerTests.cs Tests session quarantine behavior.
PayjoinReceiverSessionStoreRelationalTests.cs Tests quarantine cleanup after deletion.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ValeraFinebits

Copy link
Copy Markdown
Owner

@benalleng Thanks for catching this and providing the initial fix! I’ve prepared a follow-up based on your changes.
It keeps relay failover while making quarantine temporary, so a transient failure cannot exclude the only configured relay for the rest of the session. HTTP rejections affect only the current session, transport failures use the global cooldown, and local wallet/storage errors no longer mark a relay as failed. HTTP status is now checked before reading the response body.
I also added regression coverage for quarantine expiry, session isolation, cancellation during body reads, native object lifetime across async processing, and retrying an HTTP-rejected POST without re-signing.
The separate session recovery issues involving storage failures and POST error classification across FFI are tracked in #198. Those remain for a separate change to keep this PR focused.

@ValeraFinebits
ValeraFinebits marked this pull request as ready for review October 10, 2026 10:49
@ValeraFinebits
ValeraFinebits requested a review from chavic October 10, 2026 10:49

@chavic chavic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ACK

@ValeraFinebits
ValeraFinebits merged commit 879f105 into ValeraFinebits:master Oct 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants