Skip to content

Remove cli loops#1734

Open
xstoicunicornx wants to merge 2 commits into
payjoin:masterfrom
xstoicunicornx:remove-cli-loops
Open

Remove cli loops#1734
xstoicunicornx wants to merge 2 commits into
payjoin:masterfrom
xstoicunicornx:remove-cli-loops

Conversation

@xstoicunicornx

@xstoicunicornx xstoicunicornx commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Replace the loops in the v2 sender and receiver flows with a driver: each step function performs one state transition and returns the next SendSession or ReceiveSession state, and process_sender_session/process_receiver_session loop over dispatch until the session terminates. This is now feasible because the transient errors return the next state to be processed.

This was created as a suggested follow up from #1724 (comment).

Claude Fable was used to assist in creating these code changes.

Pull Request Checklist

Please confirm the following before requesting review:

@xstoicunicornx xstoicunicornx marked this pull request as draft July 13, 2026 16:01
@coveralls

coveralls commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 29265799698

Coverage increased (+0.2%) to 86.174%

Details

  • Coverage increased (+0.2%) from the base build.
  • Patch coverage: 63 uncovered changes across 1 file (83 of 146 lines covered, 56.85%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
payjoin-cli/src/app/v2/mod.rs 146 83 56.85%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15861
Covered Lines: 13668
Line Coverage: 86.17%
Coverage Strength: 344.09 hits per line

💛 - Coveralls

Replace the loops in the v2 sender and
receiver flows with a driver: each step function performs one
state transition and returns the next SendSession or ReceiveSession
state, and process_sender_session/process_receiver_session loop over
dispatch until the session terminates.
Wrap process_receiver_session in a select against the interrupt
channel in receive_payjoin, mirroring how send_payjoin guards the
sender driver. This is safe at any phase: transitions persist to the
event log with no await between transition and save, so an
interrupted session resumes from its last saved state via the resume
command. The interrupt message now includes the session id, and
read_from_directory becomes a plain single-step function like the
other state handlers.
@xstoicunicornx xstoicunicornx marked this pull request as ready for review July 13, 2026 16:37

@bc1cindy bc1cindy 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.

nice refactor!

the driver reads much cleaner than the recursion, and moving the interrupt select! up to wrap the whole receive session is a good improvement

};

match session.process_error_response(&err_bytes, err_ctx).save(persister) {
Ok(_) => Ok(ReceiveSession::Closed(ReceiverSessionOutcome::Aborted)),

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.

success here returns Closed(Aborted) and driver maps it to Err("Session closed") (L809)

this path returned Ok(()) before

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.

3 participants