Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Retrying operations that aren't idempotent card 5 of 6

BETTER: one key per payment, made once

**BETTER:** build one key per logical payment *before* the loop and pass it on every attempt. The provider stores key → result and returns the first result instead of charging again. A subtle tell: `uuid4()` created *inside* the loop, which makes each attempt a new payment. **Later cost:** the same double charge the key was meant to prevent. If the provider has no keys, look up the charge by order reference before retrying.
// Python
key = f"order-{order.id}-charge"
for attempt in range(3):
    try:
        return pay.charge(order.total, card, idempotency_key=key)
    except Timeout:
        time.sleep(2 ** attempt)
raise PaymentError("charge status unknown")
Terms on this card
uuid4()
Python function returning a new random UUID on every call.
tell
An observable sign in a diff, transcript or summary that suggests a shortcut or an error.
later cost
The concrete damage a shortcut causes after merge, such as a hidden bug or corrupted data.
pass
Python statement that does nothing; used as a body, it makes a function or handler an empty shell.
Learn this step by step on Bytewise
Lesson goal: Spot retry loops the agent wrapped around payments, POSTs, emails or queue publishes. Explain how they cause duplicates when the first attempt actually succeeded but its response was lost, and how an idempotency key or deduplication makes the retry safe. · the whole lesson