Charged Twice On Retry (2)
An agent pipeline runs on a durable workflow engine. Support reports that some users' prepaid balances drop twice for a single generation. It happens on maybe 2 percent of requests, and always on slow ones.
@activity.defn
async def generate_and_charge(user_id: str, prompt: str) -> str:
text = await llm.complete(prompt) # p99 latency 41s
tokens = count_tokens(prompt, text)
await billing.debit(user_id, tokens) # INSERT into ledger, UPDATE balance
return text
The activity is configured with a 45 second start-to-close timeout and the engine's default retry policy.
What is the correct fix?
Sign in to answer questions and track your progress
Sign In