Repository navigation
fix(billing): idempotent retries, no double charge for a repeated call - #7
Merged
Merged
Conversation
A tool call repeated with the same license, tool, credits and inputs within DEDUP_TTL (300 s) reuses the first call's idempotency key, so the KeyFlint gateway replays the debit instead of charging again (client timeout + retry). A refunded call frees its key; a failing replay never refunds the paid call. Fake gateway now mirrors the real ledger (is_cached, 409 on refunded keys). Tests: duplicate call charges once, different inputs and expired window charge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R4cLjc9YmCMKwUdVsFcsGE
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R4cLjc9YmCMKwUdVsFcsGE
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.
Requested by Arcee · project thread
Problem
Billing.chargegenerated a freshuuid4idempotency key per tool call, so a client retry after a timeout was charged twice even though the gateway ledger is idempotent per key.Fix
Same license + tool + credits + inputs within
DEDUP_TTL(300 s) reuses the first key → gateway replays the debit. Refunded keys are freed; a failing replay never refunds the paid call._paidfingerprintsurl+ args;compare_seofingerprints the fetched URLs. Fake gateway mirrors the real ledger. The concurrency/overdraw test setsDEDUP_TTL=0because it fires 40 identical calls on purpose.Tests
Duplicate call charges once; different inputs and expired window charge; retry after refunded failure billed once.
pytest -q: 34 passed.Generated by Claude Code