Skip to content

fix: the job_row_decode bench feeds the fence epoch today's decoder reads - #619

Merged
rcbevans merged 2 commits into
mainfrom
fix/bench-runner-rot
Sep 30, 2026
Merged

rcbevans merged 2 commits into
mainfrom
fix/bench-runner-rot

Conversation

@rcbevans

Copy link
Copy Markdown
Contributor

Red proof

python benchmarks/run_bench.py on origin/main @ 7a244081 dies in the rows group:

  File "benchmarks/run_bench.py", line 150, in run_benches
    results.extend(fn())
  File "benchmarks/bench_hotspots.py", line 679, in bench_job_row_decode
    a_out = [_job_row_from_record(r) for r in rows[:2]]
  File "src/taskq/backend/_records.py", line 310, in _job_row_from_record
    claim_epoch=rec["claim_epoch"],
  File "benchmarks/bench_hotspots.py", line 556, in __getitem__
    return dict.__getitem__(self, key)
KeyError: 'claim_epoch'

Broken surfaces, named:

  • run_bench.py full suite — hard crash (KeyError: 'claim_epoch'); the rows group never completes, so --json, --save-baseline, --check are all unreachable on a real run.
  • run_bench.py --only rows — same crash.
  • Everything else was verified live and is NOT rot: --only di, --only jsonb, --only decode, --only cron, --only retry, --only evict, --stall, --check (gate renders and exits correctly against the committed baseline), standalone bench_hotspots.py, and profile_hotspot.py all ran clean pre-fix.
  • The committed artifacts under benchmarks/results/ are untouched and remain valid — this is runner rot only.

Root cause

claim_epoch (the terminal-write fence column from 01.00.18_02_pre_claim_epoch.sql, #369) was added to the jobs table, JobRow, and _job_row_from_record on 2026-09-20. The bench's FakeRecord in bench_job_row_decode was last touched 2026-09-19 — one day before — and was never updated, so the fake record rows stopped satisfying the contract of the real decoder they are fed to. Classic instrumentation drift: the source of truth moved, the fixture didn't.

Fix

benchmarks/bench_hotspots.py only:

  1. make_record now emits claim_epoch=1 — honest for the fixture (status running, attempt 1: the epoch the dispatch claim just bumped to), and the key _job_row_from_record reads today.
  2. The B variant (b_decode) now decodes claim_epoch=rec["claim_epoch"] too. It previously built JobRow without the field, meaning B was silently skipping decode work A must do — the speedup number would have been a lie once the crash was papered over.
  3. The correctness assertion now compares a.claim_epoch == b.claim_epoch.
  4. FakeRecord's lookup type corrected from -> object to -> Any on a dict[str, Any] base — it models asyncpg.Record, whose lookups are Any. This is a type-level fix only and drops the file's pyright noise from 73 to 32 errors; no runtime meaning changes.

No metric was renamed: no metric's meaning changed — every key the harness reads is a key the instrumentation still emits; the missing direction (fixture → decoder) was the rot. Baseline names are unchanged, so the committed baseline.json still merges.

Proof: two green runs (full suite, final code state)

Run 1:

job_row_decode[1000 rows] A B     6.77 ms   5.64 ms   1.20x  OK  B = tightened decode (pre-validated)
retry_policy_reconstruct A B      1.68 us      815 ns 2.06x  OK  B = model_copy, skips re-validation
evict_keyed[10000 entries] A B    95.94 us     170 ns 564.35x OK  A linear scan; B heap-index pop (one-shot)

(all 19 benches OK — full table in the run history; every group completes, no KeyError)

Run 2:

job_row_decode[1000 rows] A B     6.79 ms   6.01 ms   1.13x  OK  B = tightened decode (pre-validated)
retry_policy_reconstruct A B      1.71 us      810 ns 2.11x  OK  B = model_copy, skips re-validation
evict_keyed[10000 entries] A B    97.72 us     161 ns 606.98x OK  A linear scan; B heap-index pop (one-shot)

Stable: job_row_decode A within 0.3% across runs; every verdict OK in both.

Magnitude vs the committed benchmarks/results/baseline.json (same machine class): job_row_decode baseline 5.04 ms → now 6.6–6.8 ms — same order of magnitude, and A now legitimately decodes one more field (the claim_epoch fence) than when the baseline was captured. cron_next_fire 541 µs → ~625 µs, evict_keyed 74 µs → ~97 µs: comparable. --check against the committed baseline runs end-to-end and renders the full verdict table.

Also exercised: --stall (probes captured and parsed), standalone bench_hotspots.py, profile_hotspot.py. The suite is in-process (no bench group opens a DSN); a PG18 container was up regardless to rule out hidden DB coupling.

Gates

  • ruff check benchmarks/bench_hotspots.py — clean.
  • ruff format --check benchmarks/bench_hotspots.py — clean.
  • pyright benchmarks/bench_hotspots.py — 32 errors, down from 73 on main, and none on any line this PR touches; the residue is pre-existing typing noise in untouched benches (DI stubs, retry, evict). Note: benchmarks/ is outside the project's pyright gate (include = ["src", "tests", "examples"]; CI runs pyright src/taskq tests).
  • Test suite fast tier untouched — no src/ or tests/ files changed.

…eads

_job_row_from_record has bound claim_epoch into every JobRow since
01.00.18_02_pre_claim_epoch.sql (#369), but the bench's FakeRecord was
frozen the day before that landed and never grew the key, so every
run_bench.py pass over the rows group died with KeyError: 'claim_epoch'.

The fake record now carries claim_epoch=1 (a mid-claim running row, so
the epoch the dispatch claim just bumped to), the B variant decodes the
same fence field instead of silently skipping work A must do, and the
correctness check compares it. FakeRecord's lookup type is fixed to
match what it models (asyncpg.Record lookups are Any, not object), which
drops the file's pyright noise from 73 to 32 errors, none on touched
lines. No metric was renamed: the meaning of every number is unchanged.
@rcbevans
rcbevans merged commit c5268ba into main Sep 30, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants