HANDOFF NOTE: project "queue" (target only)

SCOPE
Implement evaluate(payload) -> {ready:[id], waiting:[{id,at}], dead:[id], cancelled:[id]}. Archived records for other projects (archive-*) are unrelated and were discarded. Only Updates 1-5 for queue apply.

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

All settings are now specified; none are unresolved. Later updates replace only the keys they name.

FIXED ALGORITHM CONTRACT
Input: now (integer) and jobs, each with id, key, priority, created, attempt, last_code, cancelled, due, failed_at. All numbers are nonnegative integers. last_code 0 means no failure. Do not mutate the input.

1. Dedup by the dedup_key field, keeping the last occurrence's value and its actual original index. With the current setting, dedup is by "id", not "key".
2. Retryable job: last_code is in retryable_codes.
3. Cancelled job: goes to cancelled if cancel_wins is true, or if the job is not retryable. With cancel_wins true, every cancelled job goes to cancelled.
4. Otherwise dead if any of: stale (now-created >= stale_after when stale_inclusive, else >); attempt >= max_attempts; or last_code nonzero and not retryable.
5. Otherwise, for a retryable job with a failure: due = max(due, failed_at + min(base_delay * (2**max(0, attempt-1) if exponential else 1), delay_cap)). Jobs without failure keep their due.
6. If due > now, the job goes to waiting as {id, at: due}; otherwise ready.
7. Ordering:
   - ready: priority descending if priority_high_first (currently true), else ascending; then created ascending if fifo_ties (currently true), else descending; then selected original index.
   - dead: by id if dead_order = "id" (currently), else by original index.
   - waiting and cancelled: always by selected original index.

NOTES FOR NEXT SESSION
- "Selected original index" means the index of the kept (last) duplicate.
- Dead-check order matters: cancelled first, then dead, then due computation.
- With the current values, the retry delay is min(100 * 2^(attempt-1), 150): attempt 1 gives 100, attempt 2 or more gives 150. Attempt is below 3 for any non-dead job.
- Wait for further updates and apply them as key-level replacements.
- Do not write code unless asked.