Skip to content

fix: a settlement receipt beats a skip marker; false/0/no/none are not a skip - #96

Merged
VickyXAI merged 1 commit into
mainfrom
fix/settlement-skip-receipt-wins
Oct 27, 2026
Merged

VickyXAI merged 1 commit into
mainfrom
fix/settlement-skip-receipt-wins

Conversation

@VickyXAI

Copy link
Copy Markdown
Contributor

Port of the TypeScript SDK's #92 (from the review of its skip-booking change, which #94 here mirrors).

Problem

tx_log.settlement_skipped() reads any X-Settlement-Skipped value, or X-Payment-Waived when present, as "no money moved", and every booking site then books $0. Two gaps:

  1. A marker can hide a real charge. If a response carries a skip marker and a receipt proving settlement (a transaction or a positive charge), the session total, the cost log and the spend limit all record $0 for money that moved. The gateways never send both today, but nothing pinned that.
  2. Opposite values count as a skip. X-Settlement-Skipped: false (or 0, no, none) was a skip.

Change

  • settlement_skipped() ignores a marker whose value is false / 0 / no / none.
  • A marker is also ignored when the response proves settlement: a PAYMENT-RESPONSE that did not fail (success is not false) and names a transaction (via decode_settlement_header, which reads transaction / signature / …) or a positive amount / extra.chargedAmount, or a non-empty X-Payment-Receipt. The conflict is written to stderr and the call is booked.
  • Gateway check: blockrun.ai's free-fallback answer is PAYMENT-RESPONSE {success: true, transaction: ""} with no amount and no X-Payment-Receipt (blockrun chat/completions/route.ts ~4742–4777). The pm empty-result and rpc unexecuted routes return before settling. So every skip sent today still books $0, and the real free-fallback shape is a test case.
  • Kept as fix: book $0 for paid calls the gateway served without settling #94 designed it: an empty X-Payment-Waived still counts as a skip (presence is enough).

Tests

  • tests/unit/test_settlement_skipped.py: these now book the quote: negative values; marker + receipt with a transaction / Solana signature / chargedAmount / amount; marker + X-Payment-Receipt. A conflict writes to stderr. A free-fallback receipt and a failed receipt stay skipped and write nothing.
  • 8 fail on main. black and ruff are clean. pytest tests/unit: 1431 passed. Two test_solana_poll_ownership.py tests failed once under machine load (a different test each run), then passed 64/64 twice on rerun; they don't touch this code.

…t a skip

Port of @blockrun/llm #92 (review of the TS #89 port): settlement_skipped()
ignores a marker when the response proves the payment settled (PAYMENT-RESPONSE
not failed with a transaction or a positive amount / extra.chargedAmount, or
X-Payment-Receipt), writing the conflict to stderr; negative values are not a
marker. blockrun.ai's free-fallback receipt ({success: true, transaction: ""},
no amount) stays skipped. 8 new helper tests fail on main.
@VickyXAI
VickyXAI merged commit f03b2a8 into main Oct 27, 2026
6 checks passed
VickyXAI pushed a commit that referenced this pull request Oct 27, 2026
A settlement receipt beats a skip marker; false/0/no/none are not a skip (#96).
First PyPI release of 1.21.2's change (#94): 1.21.2 was never published.
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