fix(wallet): hold reservation on ambiguous x402 settlement (#128) - #138
Merged
Conversation
… releasing it An aborted or timed-out paid request may already have settled on-chain. postWithPayment now marks the reservation ambiguous once the signed request is dispatched; the reservation layer keeps the amount counted for a 30s grace window and prunes it on the next fresh balance fetch. The cap can only err tight, never loose. Closes #128
This was referenced Aug 29, 2026
…sent requests ambiguous Adversarial review follow-ups on #138: - grace window = request timeout + 30s margin (the gateway may settle when the paid work finishes, up to timeoutMs after our abort), pruned only by a real balance read that started after the window closed - a signal that aborted before the paid request was dispatched, or a connection-refused/DNS failure, releases normally (provably unsettled) - a paid 2xx whose body is cut off throws (ambiguous) instead of returning ok:true with an empty body and orphaning a sandbox - the Infinity RPC-failure fallback never prunes ambiguous entries - ModalCreate's insufficient-funds message reports what is actually held - postWithPayment + signer are test-injectable; 13 reservation tests
Contributor
Author
|
Follow-up commit after an adversarial pass on the first cut:
Not addressed here (pre-existing, flagged for follow-up): the SDK's Solana |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
postWithPaymenttracks whether the signed (paid) request was dispatched; if the call then aborts / times out, the wallet hold is marked ambiguous instead of being released by the caller'sfinally.WalletReservationkeeps ambiguous amounts counted against headroom for a 30s grace window and prunes them on the next fresh on-chain balance read after that window (which already reflects a real settlement). Cap errs tight, never loose; a genuinely-absent spend self-heals.test/reservation.local.mjs(3 tests) wired intonpm test.Closes #128
Test plan
npm test— 673/673 pass