Files
leleka/scripts/e2e/codex/tasks/debuglog-sched/reference/overlay/FINDINGS.md
T

2.6 KiB

Findings: jobs lost in production

Root cause

sched/ids.py, IdGenerator.next_id(): the id sequence is masked to 12 bits (ID_MASK), so after j-fff the counter wraps around to j-000 and every id is handed out again after 4096 jobs. Nothing checks whether the id is still in use. A long-running job (the export jobs on w4/w5/w6 run for 30-60 minutes and keep their lease alive with heartbeats) is therefore still alive when a new job is accepted with the same id. JobStore.put silently overwrites the record of the old job, the lease table and the dedupe table are keyed by the same id, and from then on the two jobs share one record:

  • when the old job acks or the new one acks, the first ack deletes the shared record and the other side finds nothing: ack for unknown job, claim of unknown job ... dropped, or, at its next heartbeat, job ... vanished: lease expired while running;
  • the client of the lost job retries with the same key, dedupe.py still maps the key to the reused id and swallows the resubmission (dedupe hit ... not enqueued), so the job never completes.

Evidence (logs/service.log)

  • lines 927-928: accepted job=j-fff is followed by accepted job=j-000, the id sequence wrapped.
  • lines 123, 357, 553, 769: heartbeats lease renewed job=j-014 worker=w4; the export j-014 is running and leased.
  • line 986: accepted job=j-014 kind=thumbnail - the same id is issued again while the export still holds it.
  • line 1000: ack job=j-014 worker=w4 attempts=0 (the export acks, but the record it deletes is the new job's, attempts=0).
  • line 1009: claim of unknown job j-014 by w1, dropped; line 1496: dedupe hit key=k-d3f091db job=j-014, not enqueued (the client retry of the lost thumbnail job is swallowed).
  • line 1456: accepted job=j-0a3 while the export on w5 is leased; line 1655: job j-0a3 vanished: lease expired while running.
  • line 2870: accepted job=j-280 while the export on w6 is leased; line 3055: ack for unknown job j-280 worker=w2.
  • line 3991: accepted job=j-3c7 reuses the id of the export on w4; line 4058: job j-3c7 vanished.

Unrelated noise: the queue_depth counter drifted warnings, the transient failed attempt retries, the two dead after 3 attempts errors and the lease expiry of j-194 (line 2857, a frozen worker) are different things.

Fix

IdGenerator.next_id() no longer masks the sequence, so ids are never reused (they just grow to four hex digits and more). JobStore.put now refuses to overwrite a record of a different job, so a future id collision fails loudly at submit time instead of corrupting a running job. Regression tests: tests/test_regression.py.