HANDOFF NOTE: project "queue" (only this project; archived records for other projects were discarded as unrelated)

INTERFACE
evaluate(payload) -> {ready:[id], waiting:[{id,at}], dead:[id], cancelled:[id]}
Payload: integer "now" plus jobs. Each job has id, key, priority, created, attempt, last_code, cancelled, due, failed_at. All values are nonnegative integers. last_code 0 means no failure. The input must not be mutated.

CURRENT CONFIG (after Updates 1-5, merged)
- base_delay = 100
- exponential = true
- max_attempts = 3
- retryable_codes = [429, 500]
- cancel_wins = true (Update 2 set false; Update 4 restored true)
- dedup_key = "id" (Update 2 set "key"; Update 5 set "id")
- fifo_ties = true (Update 2 set false; Update 5 set true)
- priority_high_first = true (Update 2 set false; Update 4 set true)
- dead_order = "id"
- delay_cap = 150
- stale_after = 2000
- stale_inclusive = false (stale means now-created > stale_after)

No config key was left without a value. Every key above has been set by an update.

ALGORITHM (fixed contract)
1. Deduplicate by the field named by dedup_key (currently "id"). Keep the last occurrence's value, along with its actual original input index. That index is the "selected original index" used for ordering below.
2. A job is retryable if last_code is in retryable_codes.
3. Cancelled job: goes to cancelled if cancel_wins, or if it is not retryable. Otherwise it continues through the checks below.
4. Dead if any of these holds:
   - stale: now-created >= stale_after when stale_inclusive, otherwise now-created > stale_after
   - attempt >= max_attempts
   - last_code is nonzero and not retryable
5. Otherwise, for a retryable job, due = max(due, failed_at + min(base_delay * (2**max(0, attempt-1) if exponential else 1), delay_cap)). Jobs without a failure keep their due.
6. If due > now, the job goes to waiting with at = due. Otherwise it goes to ready.

ORDERING
- ready: priority descending if priority_high_first (currently true), otherwise ascending. Then created ascending if fifo_ties (currently true), otherwise descending. Then selected original index.
- dead: sorted by id if dead_order = "id" (current), otherwise by original index.
- waiting and cancelled: always by selected original index.

CURRENT EFFECTIVE BEHAVIOR (derived)
- With exponential, base 100 and cap 150, the delay is 100 for attempt 1 and 150 for attempt 2 or more (capped).
- Since max_attempts = 3, retryable jobs with attempt >= 3 are dead.

UNRESOLVED / NOTES
- No unresolved questions or exceptions have been stated.
- Ambiguities left as the contract words them:
  - Whether the dedup_key = "id" duplicate handling applies before the cancelled check. The contract lists dedup first, so apply it first.
  - The precedence between the cancelled branch and dead checks follows the order above.
- Further updates, which replace the listed keys and leave others unchanged, and later questions are not yet available. Apply any new update as an override on the CURRENT CONFIG above.