HANDOFF NOTE: project "queue" (target only)

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

2. Current configuration (after Updates 1-5)
- base_delay = 200
- exponential = false
- max_attempts = 4
- retryable_codes = [408, 503]
- cancel_wins = false
- dedup_key = "key"
- fifo_ties = false
- priority_high_first = false
- dead_order = "input"
- delay_cap = 400
- stale_after = 1000
- stale_inclusive = true

Values set only by Updates 1-5 are authoritative. Updates 1-5 did not set stale_after before Update 5, and the only value in force is 1000. The notes about archive-* projects are unrelated and were discarded.

3. Algorithm contract
a. Dedup: group jobs by the field named by dedup_key (currently "key"). Keep the last job for each value, and retain its actual original index in the input. That index is used for all later "original index" ordering.
b. Retryable: last_code is in retryable_codes.
c. Cancelled: a job with cancelled set goes to cancelled if cancel_wins is true or the job is not retryable. With cancel_wins = false, a cancelled retryable job is not placed in cancelled and continues through the later steps.
d. Dead: a job is dead if any of these holds:
 - now - created >= stale_after (when stale_inclusive is true; otherwise strictly >)
 - attempt >= max_attempts
 - last_code is nonzero and not retryable
e. Otherwise compute due. A retryable job's due becomes 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. With the current config the delay is a flat 200, and the cap of 400 has no effect.
f. If due > now, the job goes to waiting with at = due. Otherwise it goes to ready.

4. Ordering
- ready: sort by priority ascending when priority_high_first is false (descending when true). Ties are broken by created descending when fifo_ties is false (ascending when true). Further ties are broken by selected original index.
- dead: sort by original index when dead_order is "input" (by id when dead_order is "id").
- waiting and cancelled: always by selected original index.

5. Unresolved or ambiguous items
- It is not specified whether a cancelled retryable job (with cancel_wins = false) should also be subject to dead checks. The contract order implies yes (it falls through to the dead check), so follow that.
- The ordering of a job that has no failure but a nonzero last_code is covered by the dead rule only if the code is nonretryable.
- No tests or examples were given.
- Later updates may change keys, and each replaces only the keys it names.