TARGET PROJECT: queue — HANDOFF NOTE

Purpose / fixed interface:
Implement evaluate(payload) -> {ready:[id], waiting:[{id,at}], dead:[id], cancelled:[id]}.
Input includes integer `now` and jobs having: id, key, priority, created, attempt, last_code, cancelled, due, failed_at.
All values are nonnegative integers except where the configuration below states otherwise. Zero last_code means no failure. Do not mutate the input.

CURRENT CONFIGURATION (final, after all target-project updates; superseded and unrelated-project values discarded):
{
  "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
}

ALGORITHM CONTRACT:
1. Deduplicate jobs by the field named by dedup_key (currently "key"), keeping the last occurrence and its actual original index for ordering.
2. A job is retryable when its last_code is in retryable_codes (currently 408 or 503).
3. Cancellation is checked first: a cancelled job goes to `cancelled` if cancel_wins is true OR if it is not retryable. With current cancel_wins=false, cancelled retryable jobs do not go to `cancelled` and continue to the dead/ready/waiting checks.
4. Otherwise, a job is `dead` if any applies:
   - Stale: now - created >= stale_after when stale_inclusive is true (otherwise >). Current threshold: >= 1000.
   - attempt >= max_attempts (currently >= 4).
   - last_code is nonzero and non-retryable.
5. Otherwise, for a retryable job with a failure, its effective due becomes:
   max(due, failed_at + min(base_delay * (2 ** max(0, attempt-1) if exponential else 1), delay_cap)).
   With current settings, the delay component is min(200 * 1, 400) = 200. Jobs without failure keep their original due.
6. If effective due > now, place in `waiting` as {id, at} where at is the effective due; otherwise place in `ready`.

SORTING:
- ready: by priority descending iff priority_high_first, otherwise ascending; then by created ascending iff fifo_ties, otherwise descending; then by selected original index. Current effect: priority ascending, created descending, then selected original index.
- dead: by id iff dead_order="id", else by selected original index. Current dead_order="input", so selected original index.
- waiting and cancelled: always by selected original index.

UNRESOLVED ITEMS: None stated for target project queue.