bugger.
All challenges/Pythonmediumamazon-partial-batch-retry-v1
THE INVESTIGATION

The batch that retries successful messages

One failing queue message causes successful notifications to be delivered again.

Amazon-styleInterview practiceRetries

What’s going wrong

Original Amazon-style interview practice. This is not an actual Amazon interview question. Bugger does not provide an AI assistant.

A standard-queue worker correctly notices a failed message, but the next batch includes messages that already succeeded. Customers receive duplicate notifications while one unrelated message is retried.

Input is {"messages":[{"id":"a","failures":0}, ...],"maxAttempts":3}. Each message ID is unique. Its failures value is the number of its own processing attempts that must fail before its next attempt succeeds. In each round process every pending message in its current order, incrementing its attempt count. A success appends its ID to delivered and removes it permanently from future rounds; only failures remain pending. Stop after maxAttempts rounds or when no messages remain.

Print {"delivered":[...],"attempts":[{"id":"a","count":1},...],"pending":[...]}. Delivered IDs are in actual success order; attempts and pending preserve original message order. Input has at most 100 messages with nonempty ASCII IDs, failures is an integer from 0 to 5, and maxAttempts is an integer from 1 to 6. The input is a deterministic model of a standard SQS queue with partial batch responses enabled, not a FIFO queue. Repair process_batch so successful work is never replayed.

Expected behavior

Retry only messages that failed their current attempt; deliver each message once, with accurate attempt counts and pending work after the retry budget.

Reproduction

01 One success and one transient failure
{"messages":[{"id":"a","failures":0},{"id":"b","failures":1}],"maxAttempts":3}
{"delivered":["a","b"],"attempts":[{"id":"a","count":1},{"id":"b","count":2}],"pending":[]}
02 Every message succeeds immediately
{"messages":[{"id":"a","failures":0},{"id":"b","failures":0}],"maxAttempts":3}
{"delivered":["a","b"],"attempts":[{"id":"a","count":1},{"id":"b","count":1}],"pending":[]}
03 Stop with only the failed message pending
{"messages":[{"id":"a","failures":0},{"id":"b","failures":3}],"maxAttempts":2}
{"delivered":["a"],"attempts":[{"id":"a","count":1},{"id":"b","count":2}],"pending":["b"]}

Before you begin

  • Lists and dictionaries
  • Retry loops
  • Partial failures

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.