Repair a job-runner state transition without changing its public API.

CONTEXT
An IT automation runner retries transient failures. Operators report extra attempts, jobs restarting after cancellation, and raw error text in saved state. Repair candidate.cjs. Do not edit grader.cjs. Add regression tests and a short explanation of the failure modes and tradeoffs.

API
module.exports = { transition };
transition(state, event, policy) returns the next state synchronously.
state: { id, status, attempts, nextRunAt, lastError }
status: pending | running | retry | succeeded | failed | cancelled
event: { type, now, retryable?, error? }; type: start | success | failure | cancel
policy: { maxAttempts, baseDelay, maxDelay }
Times and delays are integer milliseconds. Inputs are valid: positive policy integers, maxDelay >= baseDelay, nonnegative attempts, finite now. Initial pending jobs have attempts:0, nextRunAt:0, lastError:null. A running job has already consumed an attempt. No concurrency, persistence, clock synchronization, or real command execution is modeled.

CONTRACT
1. Never mutate state, event, or policy. Preserve id and any unrelated fields.
2. succeeded, failed, and cancelled are terminal: every later event leaves them unchanged.
3. cancel on a nonterminal job sets cancelled, nextRunAt:null, lastError:null; keep attempts.
4. start is allowed only from pending/retry at now >= nextRunAt. If attempts < maxAttempts, set running, increment attempts exactly once, and clear nextRunAt and lastError. If the budget is already exhausted, set failed, nextRunAt:null, lastError:ATTEMPTS_EXHAUSTED.
5. success only affects running jobs: set succeeded, nextRunAt:null, lastError:null.
6. failure only affects running jobs. retryable === true with attempts < maxAttempts schedules retry at now + min(maxDelay, baseDelay * 2 ** (attempts - 1)), with lastError:TRANSIENT. Otherwise set failed, nextRunAt:null, and lastError:TRANSIENT when retryable === true or PERMANENT otherwise.
7. Unknown or out-of-order events are no-ops. Never copy event.error into output; use only the codes above.

DELIVERABLES
The repaired candidate.cjs, added regression tests, and a concise explanation. Run node grader.cjs. Report what you actually tested and anything outside the task's scope.

SCORING
20 public behavior checks × 4 points = 80 automated points. Human review adds up to 20: regression-test quality (0–10) and explanation/change discipline (0–10). Automated 80/80 is not an overall pass. Tests and the reference are public; this is an inspectable portfolio exercise, not a hidden or adversarial benchmark. Do not present a reference run as a model result.
