Skip to content

Return error if session closed with a failure#1132

Closed
arminsabouri wants to merge 3 commits intopayjoin:masterfrom
arminsabouri:return-err-in-replay
Closed

Return error if session closed with a failure#1132
arminsabouri wants to merge 3 commits intopayjoin:masterfrom
arminsabouri:return-err-in-replay

Conversation

@arminsabouri
Copy link
Collaborator

Returning the current state encourages developers to repeat the action that caused the failure. Instead we should error out during session replays.

Blocked by #1129 . Drafting for now. There is a TODO as well that I'd like to address. As of now, IIRC the application never recieves the error that fatally closed the session on a replay. If we include a stringified version of the error that would provide some visibility that previously TerminalFailure(String) provided. Please correct me if my assumption about this is incorrect.

Pull Request Checklist

Please confirm the following before requesting review:

Returning the current state encourages developers to repeat the action
that caused the failure. Instead we should error out during session
replays.
We can get rid of the hacky `ProtocolError` variant off
`InternalReplayError` if we seperate event processing events from replay
errors.
@arminsabouri arminsabouri self-assigned this Oct 2, 2025
@arminsabouri arminsabouri added this to the payjoin-1.0 milestone Oct 2, 2025
@arminsabouri arminsabouri marked this pull request as ready for review October 2, 2025 16:55
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 18199861996

Details

  • 60 of 82 (73.17%) changed or added relevant lines in 6 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.07%) to 84.636%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/core/error.rs 10 11 90.91%
payjoin/src/core/receive/v2/mod.rs 2 4 50.0%
payjoin/src/core/send/v2/mod.rs 1 4 25.0%
payjoin-cli/src/app/v2/mod.rs 0 4 0.0%
payjoin/src/core/receive/v2/session.rs 42 46 91.3%
payjoin/src/core/send/v2/session.rs 5 13 38.46%
Files with Coverage Reduction New Missed Lines %
payjoin-cli/src/app/v2/mod.rs 1 61.45%
Totals Coverage Status
Change from base Build 18176477486: 0.07%
Covered Lines: 8720
Relevant Lines: 10303

💛 - Coveralls

@DanGould
Copy link
Contributor

DanGould commented Oct 2, 2025

I suppose this implies the presence of a closed event is insufficient to display failure in UI? On its face it doesn't seem like a closed session should throw an error which semantically describes exceptions.

@spacebear21
Copy link
Collaborator

the presence of a closed event is insufficient to display failure in UI?

The closed event describes the outcome (e.g. failure) but no details about how it occurred. To do that we need the session history. The current approach is to return the current_state on replay of a Closed event, but @arminsabouri described in OP that it may be a footgun to keep returning the same state. There were two proposed solutions:

  1. Re-introduce the TerminalFailure unit variant - this is simpler but also a bit of a hack as it's not a true state in the state machine and can only be reached by replaying the event log.
  2. Return an error with the SessionHistory included, so that failure reason can be reconstructed. That's what this PR does

@spacebear21
Copy link
Collaborator

#1136 shows the alternative approach of re-introducing a closed variant to the ReceiveSession state machine. In hindsight that does feel cleaner so Approach NACK on this PR in favor of #1136.

@arminsabouri
Copy link
Collaborator Author

superseded by #1132

@arminsabouri arminsabouri deleted the return-err-in-replay branch October 2, 2025 18:47
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.

4 participants