fix(cost): race-free settlement attach + unblock CI formatting#12
Merged
Conversation
added 2 commits
June 23, 2026 23:22
Use the dict _capture_settlement() returns instead of re-reading self._last_settlement, which a concurrent call on a shared client could overwrite — making the per-call settlement field as race-free as cost_usd.
Pre-existing formatting drift that fails CI's black --check; unrelated to the cost change but blocks this PR's pipeline.
VickyXAI
pushed a commit
that referenced
this pull request
Jun 26, 2026
Streaming analogue of ChatResponse.cost_usd: _iter_and_archive / _aiter_and_archive (Base + Solana) now set chunk.cost_usd = cost_usd on every paid-path chunk. It rides on the per-call chunk object, so it is race-free under shared-client concurrency, unlike client._last_call_cost. Free / 200-first streams skip the signer and carry no cost_usd. Lets blockrun-litellm report the real wallet deduction on streamed calls instead of a token×list-price estimate (blockrun-litellm #12).
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.
Follow-up to #11.
What
_handle_payment_and_retry(sync + async) now attachessettlementfrom the dict_capture_settlement()returns instead of re-readingself._last_settlement. A concurrent call on a shared client could overwrite that shared field between capture and read; using the return value makes the per-callsettlementas race-free ascost_usdalready is. No behavior change for the single-call path.black --check .and was blocking feat(cost): attach real per-call x402 charge to ChatResponse #11's pipeline. Unrelated to the cost change.Verification
black --check .clean (57 files)ruff check blockrun_llm/cleanpytest tests/unit268 passed