Files

4.3 KiB

id, title, kind, expected_rounds
id title kind expected_rounds
debuglog-sched Find why a job scheduler loses jobs from a production log, fix it and write it up debug 20-50

debuglog-sched

Notes for the orchestrator (not sent to Codex).

  • Seed: sched/ (a lease-based job scheduler: queue, store, leases, dedupe, retry, metrics, a discrete-event simulator, about 780 lines with run_sim.py), 31 visible unit tests (green on the seed) and logs/service.log (4730 lines, 417 KB, generated by gen_log.py from the seed code; gen_log.py is not part of the seed). Reading the log with grep/sed in slices is the realistic way; cat-ing it whole would be about 150k tokens, so context growth towards 100k tokens depends on how much of the log the agent pages through.
  • The defect: sched/ids.py masks the id sequence to 12 bits (ID_MASK), so ids repeat after 4096 jobs. A long-running export job that still holds its lease gets its id issued again to a new job; JobStore.put overwrites the record, so the first ack / heartbeat / claim after that finds nothing (ack for unknown job, claim of unknown job ... dropped, job ... vanished: lease expired while running), and the client's retry is swallowed by dedupe.py (dedupe hit ... not enqueued). The log shows the sequence going j-fff -> j-000 (line 927-928), heartbeats of the old job before the reuse, and four incidents (lines 986/1009, 1456/1655, 2870/3055, 3991/4058).
  • Red herrings in the log: transient failed attempt retries, queue_depth counter drifted warnings (a harmless hand-kept gauge), slow-job warnings, two dead after 3 attempts errors, and one frozen worker whose lease expires (line 2857) which also yields an ack for unknown job-like pattern (claim of unknown job j-194), but with a lease expired line before it and no id reuse.
  • Acceptance (accept.py): (1) the pristine visible tests (hidden/tests, copied over tests/) pass on the agent's code; (2) tests/test_regression.py exists and passes; (3) the same file FAILS against the original sched/ (hidden/orig/sched), so a test that cannot detect the bug is rejected; (4) two hidden stress simulations (140,000 jobs / 3 workers, 100,000 jobs / 5 workers, different seeds and traffic) run with the pristine sim.py on top of the agent's service code and must lose and duplicate nothing (about 5 s each); (5) FINDINGS.md names ids.py and next_id/IdGenerator, talks about wrap/reuse/collision, and cites a number within 2 of an evidence line (hidden/evidence.json, written by gen_log.py). Any fix that stops ids from colliding passes (removing the mask, skipping ids in use, a wider counter, uuid-like ids that keep the pristine tests green). Because the pristine sim.py is used, a fix must keep the Scheduler constructor and method signatures.
  • The original code loses 18 jobs in stress a and 27 in stress b; the reference fix (reference/overlay) loses none. Deterministic: seeded virtual-clock simulation, no wall clock, no network; Python 3.9 .. 3.14.
  • To regenerate the log (not needed): python3 gen_log.py writes seed/logs/service.log and hidden/evidence.json; the output is byte-identical on Python 3.9 and 3.12.

Prompt

Production lost some jobs. Customers are complaining that some of their jobs never completed, and on-call saw ack for unknown job warnings and vanished errors in the scheduler log. The log of the incident is logs/service.log (about 4,700 lines, so use grep and sed to look at slices of it rather than printing the whole file). The scheduler code is in sched/; run_sim.py replays a synthetic workload through the same code on a virtual clock (python3 run_sim.py --help), and the unit tests run with python3 -m unittest discover -s tests.

Please:

  1. Find the root cause of the lost jobs. The log has enough information to localise it.
  2. Fix it in the code. Keep the existing tests green.
  3. Add a regression test in tests/test_regression.py that fails on the old code and passes with your fix.
  4. Write FINDINGS.md in the repository root with the root cause (file and function), the evidence (line numbers in logs/service.log) and the fix you made.

There is no network here and only the Python 3 standard library is available (no pytest). When you are done, reply with a short summary of the root cause and the fix.