Skip to content

fix(billing): idempotent retries, no double charge for a repeated call - #7

Merged
ArceeDev merged 2 commits into
mainfrom
claude/project-thread-kjui4o
Nov 15, 2026
Merged

ArceeDev merged 2 commits into
mainfrom
claude/project-thread-kjui4o

Conversation

@ArceeDev

Copy link
Copy Markdown
Owner

Requested by Arcee · project thread

Problem

Billing.charge generated a fresh uuid4 idempotency 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. _paid fingerprints url + args; compare_seo fingerprints the fetched URLs. Fake gateway mirrors the real ledger. The concurrency/overdraw test sets DEDUP_TTL=0 because 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

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
@ArceeDev
ArceeDev merged commit 28f9f18 into main Nov 15, 2026
6 checks passed
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.

2 participants