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.
Catch plausible-but-wrong code card 5 of 6

Four traps, four checks

builds on: Happy-path code: the edge cases it skipped, Text, time and money: classic data traps, Fine on test data, broken at scale, Unawaited async work and floating promises, Leaked resources: files, connections, goroutines, Races introduced by plausible concurrent code, Retrying operations that aren't idempotent, Half-finished changes: the call sites it missed, Refactors that quietly change behavior, Invented APIs, flags, config keys and packages
Summary: *'Refunds retried on timeout, tested with 3 orders.'* - `Order.objects.get` in the loop runs one query per order. Read the query log with 5,000 orders. Later cost: big batches crawl and time out. - `* 0.9` brings in a float. A float `total` drifts by cents. A `Decimal` one raises `TypeError`. Test with a real amount and use `Decimal('0.9')`. - A retry after a timeout refunds twice if the first call went through. Test that case, then send an idempotency key. Later cost: double payouts. - After 3 timeouts the amount is still appended to `refunded`. Test with every call timing out. Later cost: a failed refund is reported as done.
// Python
def refund_all(order_ids):
    refunded = []
    for oid in order_ids:
        order = Order.objects.get(id=oid)
        amt = order.total * 0.9
        for _ in range(3):
            try:
                gateway.refund(oid, amt)
                break
            except TimeoutError:
                continue
        refunded.append(amt)
    return refunded
Terms on this card
query log
A record of every database query the code sends. It shows when one query per loop item turns into thousands of queries.
idempotency key
A unique ID sent with a request so the server performs it only once, even if the request is retried.
Decimal
Python's exact base-10 number type (`decimal.Decimal`), used for money. Mixing it with a float in arithmetic raises `TypeError`.
TypeError
Python exception raised when an operation gets an unsupported type, for example `Decimal * float`.
float
Binary floating-point number. It cannot store most decimal fractions such as 0.1 exactly, so money sums drift.
Learn this step by step on Bytewise
Lesson goal: Find bugs in code that compiles, reads well and passes its tests: skipped edge cases, text, time and money traps, scale problems, unawaited async work, leaked resources, races, unsafe retries, missed call sites, behaviour-changing refactors and invented APIs. Choose the check that would expose each one. · the whole lesson