Skip to content

feat: include amountSat and feesPaidMsat on interrupted payment error#334

Merged
rolznz merged 1 commit into
masterfrom
feat/fees-on-payment-error
Jul 22, 2026
Merged

feat: include amountSat and feesPaidMsat on interrupted payment error#334
rolznz merged 1 commit into
masterfrom
feat/fees-on-payment-error

Conversation

@rolznz

@rolznz rolznz commented Jul 22, 2026

Copy link
Copy Markdown
Member

Follow-up to #333, found while consuming the error in getAlby/cli#59: the thrown error lost the payment's cost details, so the CLI could not surface complete payment info to the agent.

Changes

  • Rename Fetch402PaymentErrorFetch402InterruptedError. The old name implied the payment failed, but the error actually means the fetch402 flow was interrupted without a response: with paid: true the payment succeeded and only the follow-up request failed; with paid: false the outcome is unknown (it may still settle). The name discriminator is updated to match.
  • Add amountSat — decoded from the invoice in the constructor exactly like paymentHash, so it is always present (0 when the invoice cannot be decoded).
  • Add feesPaidMsat — from the wallet's fees_paid, present on the paid: true throw. Previously invResp.fees_paid was in scope at the throw site but dropped, so a caller rebuilding PaymentInfo from the error had no routing fee.
  • Version bumped to 9.0.1.

Note: the rename changes a public export and the documented name === "..." match, which is technically breaking - but 9.0.0 shipped only hours before this, so real-world impact should be nil.

Tests

166 passed. The L402 post-payment-failure test now pays with fees_paid: 3000 and asserts amountSat: 402 / feesPaidMsat: 3000; the payInvoice-failure test asserts amountSat is set while feesPaidMsat is not.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved recovery handling for interrupted payment flows.
    • Recovery errors now identify the interrupted state and include payment amount and applicable fees.
    • Preserved retry and resume information, including credentials, pending payment details, and preimages.
  • Documentation

    • Updated recovery guidance and examples to reflect the new interrupted-payment error details.
  • Chores

    • Updated the package version to 9.0.1.

- Rename Fetch402PaymentError to Fetch402InterruptedError: the name wrongly
  implied the payment failed. The error means the fetch402 flow was
  interrupted without a response: with paid:true the payment succeeded but
  the follow-up request failed; with paid:false the payment outcome is
  unknown (it may still settle).
- Add amountSat, decoded from the invoice in the constructor exactly like
  paymentHash, so it is always present.
- Add feesPaidMsat from the wallet's fees_paid, present when paid - so a
  caller surfacing the payment info (e.g. the Alby CLI's paymentRecovery
  error output) no longer loses the routing fee.
- Bump version to 9.0.1.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 402 payment failure error is renamed to Fetch402InterruptedError, with amountSat and optional feesPaidMsat added to its payload. Payment-flow tests, recovery documentation, and the package version are updated accordingly.

Changes

402 interruption error update

Layer / File(s) Summary
Expanded interruption error contract
src/402/utils.ts
Defines Fetch402InterruptedError with decoded payment amount and optional payment fees.
Payment flow propagation and validation
src/402/utils.ts, src/402/l402/l402.test.ts, src/402/mpp/mpp.test.ts, src/402/x402/x402.test.ts
Payment and post-payment request failures now use the renamed error, with tests covering reconciliation fields and payment state.
Recovery documentation and release metadata
README.md, package.json
Documents the renamed error and recovery payload, and increments the package version to 9.0.1.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: bumi, reneaaron

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding amountSat and feesPaidMsat to the interrupted payment error.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/fees-on-payment-error

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@rolznz
rolznz marked this pull request as ready for review July 22, 2026 08:15

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@package.json`:
- Line 3: Preserve backward compatibility for the public Fetch402PaymentError
export and its serialized name discriminator by adding a legacy alias or
deserialization handler for existing consumers; otherwise update the package
version from 9.0.1 to 10.0.0 to mark the breaking change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dc053904-b1b7-4918-b032-bf610172b346

📥 Commits

Reviewing files that changed from the base of the PR and between 9dd4496 and 35d4f4e.

📒 Files selected for processing (6)
  • README.md
  • package.json
  • src/402/l402/l402.test.ts
  • src/402/mpp/mpp.test.ts
  • src/402/utils.ts
  • src/402/x402/x402.test.ts

Comment thread package.json
{
"name": "@getalby/lightning-tools",
"version": "9.0.0",
"version": "9.0.1",

@coderabbitai coderabbitai Bot Jul 22, 2026

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## package.json version\n'
rg -n '"version"\s*:' package.json || true

printf '\n## Fetch402 names\n'
rg -n 'Fetch402(Payment|Interrupted)Error|name\s*=\s*[\'"]Fetch402' . || true

printf '\n## exports / public API surfaces\n'
rg -n 'export .*Fetch402|Fetch402.*export|from .*Fetch402' . || true

Repository: getAlby/js-lightning-tools

Length of output: 292


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo 'package.json:'
cat package.json | sed -n '1,40p'

echo
echo 'matches for Fetch402PaymentError / Fetch402InterruptedError:'
rg -n 'Fetch402PaymentError|Fetch402InterruptedError' .

Repository: getAlby/js-lightning-tools

Length of output: 3046


🏁 Script executed:

#!/bin/bash
set -euo pipefail
pwd
ls

Repository: getAlby/js-lightning-tools

Length of output: 381


Keep Fetch402PaymentError compatibility, or bump to 10.0.0. If this change replaces the public export and serialized name discriminator, it breaks existing imports and JSON-based recovery; add a legacy alias/handler or ship it as a major release.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` at line 3, Preserve backward compatibility for the public
Fetch402PaymentError export and its serialized name discriminator by adding a
legacy alias or deserialization handler for existing consumers; otherwise update
the package version from 9.0.1 to 10.0.0 to mark the breaking change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

v9.0.0 was released today, it's a quick follow-up fix.

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.

@rolznz, understood. Since 9.0.0 is already published, consumers can still receive 9.0.1 as a patch update and have existing Fetch402PaymentError imports break. I’d retain a deprecated compatibility alias (and accept the legacy name where relevant) for this release, or publish the rename as 10.0.0.

@rolznz
rolznz merged commit 863f7bb into master Jul 22, 2026
4 checks passed
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.

1 participant