Skip to content

fix(cost): race-free settlement attach + unblock CI formatting#12

Merged
VickyXAI merged 2 commits into
mainfrom
harden-cost-settlement
Jun 24, 2026
Merged

fix(cost): race-free settlement attach + unblock CI formatting#12
VickyXAI merged 2 commits into
mainfrom
harden-cost-settlement

Conversation

@VickyXAI

Copy link
Copy Markdown
Contributor

Follow-up to #11.

What

  • client.py_handle_payment_and_retry (sync + async) now attaches settlement from the dict _capture_settlement() returns instead of re-reading self._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-call settlement as race-free as cost_usd already is. No behavior change for the single-call path.
  • tests/unit/test_image_parameter_validation.py — black-format only. Pre-existing drift (landed with 1.4.5) that fails CI's 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/ clean
  • pytest tests/unit 268 passed

1bcMax 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 VickyXAI merged commit 0bfe5bd into main Jun 24, 2026
3 checks passed
@VickyXAI VickyXAI deleted the harden-cost-settlement branch June 24, 2026 06:24
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).
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