feat: resume fetch support#333
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
📝 WalkthroughWalkthroughAdds shared 402 payment reuse, resumption, and structured failure handling across L402, MPP, and x402 flows, with tests covering payment failures and recovery paths and README documentation for reconciliation. Changes402 payment recovery
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant fetchWith402
participant payAndFetch
participant Wallet
participant Server
Client->>fetchWith402: Request protected resource
fetchWith402->>payAndFetch: Invoice and pending payment data
payAndFetch->>Wallet: payInvoice
Wallet-->>payAndFetch: Preimage or payment failure
payAndFetch->>Server: Retry request with payment credentials
Server-->>Client: Response or follow-up request failure
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
wondering about best practices in such cases for 402 in general. makes things tricky. |
|
I hit this again today:
|
|
@bumi I cannot think of any better way to do it. All other options have worse downsides.
This is a fundamental issue of 402 flow that payment and fetching are not an atomic operation. It's made worse that we have so many moving parts: NWC relay, lightning, HTTP - all do not have a 100% success rate. Since we decided to push retries to the client, and I think especially because the agent needs to know what is really going on, I believe this PR is the best option. |
|
I think this is also unique to lightning - on other blockchains there is no concept of stuck payments. 😅 |
|
How lnget does it: it uses a local store https://github.com/lightninglabs/lnget/blob/main/docs/architecture.md#pending-token-pattern Note: Even though it mentions it, I don't think lnget handles pending payments. We do in this PR by checking the status of the transaction by payment hash. |
|
@rolznz I also can't think of a better way. it's nicely implemented. |
This enables an agent to recover without repaying in two cases:
Currently BOTH of these scenarios result in the caller not receiving credentials.
See getAlby/cli#55
This adds enables the agent to resolve most common payment issues and fetch the resource without having to re-pay, at the cost of some extra complexity.
After #332 is merged this PR needs to be updated (amount and fee renaming)
Summary by CodeRabbit
New Features
Bug Fixes