Skip to content

fix: batch-mode pause, weighted batch claim loss, undecodable rows in the reaper and MySQL claims - #93

Merged
CodingAnarchy merged 3 commits into
masterfrom
fix/bug-hunt-2.1.x
Oct 11, 2026
Merged

CodingAnarchy merged 3 commits into
masterfrom
fix/bug-hunt-2.1.x

Conversation

@CodingAnarchy

Copy link
Copy Markdown
Owner

Four bugs found in an adversarial pass over the code added since 2.0.0 (batch claims and batch-mode workers) and its interactions. Each fix has a regression test that fails without it. All fixes are non-breaking and target a 2.1.x patch release.

Bugs fixed

1. Pausing a queue doesn't stop a batch-mode worker from starting the jobs it holds (medium)

Worker::run_batch_until_done checked the pause only at claim time, then started every job of the batch it held. Pausing a queue therefore let up to batch_size more jobs start, which contradicts the docs ("paused queues are honoured").

Fix: before starting a held job, the worker checks the pause, at most once per poll interval. If the queue is paused, it hands the unstarted jobs back with release_job_run, without counting an attempt, as it does on shutdown. Running jobs finish. The worker docs and docs/batch-operations.md describe the new behaviour.

Test: batch_dequeue_tests::worker::{postgres,mysql}_tests::pause_releases_unstarted_jobs. Without the fix it fails on both backends with timed out waiting for 2 Pending jobs: {"Completed": 1, "Running": 2}.

2. A weighted batch claim drops the jobs it already claimed when a later level fails (medium)

With weighted priorities, dequeue_batch_leased claims one priority level at a time, and each claim commits separately. If a later level's claim failed (a dropped connection, or a MySQL deadlock past its retries), ? returned the error and dropped the jobs claimed from earlier levels. Those jobs stayed Running until their leases expired, with an attempt spent, so a job on its last attempt went to Dead without ever running. The trait's default implementation already documented and did the right thing.

Fix: both backends now share queue::fill_weighted_batch. It returns the jobs already claimed and logs the error. If nothing was claimed, it still returns the error.

Test: the unit test queue::tests::weighted_batch_keeps_claimed_jobs_when_a_later_claim_fails. It fails when the ? behaviour is restored.

3. One undecodable row stops the stale job reaper for every queue (medium)

A row the library can't decode stops requeue_stale_jobs entirely: no stale job is reclaimed anywhere while that row exists. Such rows come from corrupt data, or from a newer version's data during a rolling upgrade (for example, a retry_strategy variant this version doesn't know).

  • MySQL: any undecodable stale row breaks the reaper. It called into_job()? on every candidate, so the error rolled back the whole pass.
  • PostgreSQL: an undecodable row that is out of attempts breaks the reaper the same way, because it is decoded before the Dead-path side effects run.

Fix: the reaper reclaims these rows from their raw columns. For a Dead row it skips only the side effects that need the decoded job, and logs a warning saying so.

Test: undecodable_row_tests::{postgres,mysql}_reaper_reclaims_undecodable_rows. Without the fix, requeue_stale_jobs returns an error on both backends.

4. An undecodable row blocks a MySQL queue forever (medium)

MySQL left an undecodable row Pending at the head of its queue. Every single claim failed on it, and a batch claim of one job came back empty forever, so nothing behind it ever ran. PostgreSQL instead claims such a row: it stays Running until its lease expires, then the reaper handles it, so the queue keeps moving.

Fix: MySQL single and batch claims now claim the row too, matching PostgreSQL. A single claim returns the decoding error after the claim commits; a batch claim skips the row and logs it.

Test: undecodable_row_tests::{postgres,mysql}_undecodable_rows_do_not_block_claims. It fails on MySQL without the fix.

Verification

  • PostgreSQL CI-style: cargo test --workspace --all-features --no-fail-fast -- --include-ignored --skip mysql: 1954 passed, 0 failed.
  • MySQL CI-style: --include-ignored mysql, with both URLs pointing at MySQL: 198 passed, 0 failed.
  • Doctests: cargo test -p hammerwork --doc passes.
  • Lint and format: cargo fmt --all --check and cargo clippy --workspace --all-targets --all-features --locked -- -D warnings are clean, as is the feature-combination clippy for every CI matrix entry.
  • Timing: the new worker test waits on conditions with 20–30 s deadlines. Its one fixed sleep (300 ms) is a lower bound past the 50 ms poll interval, so slower runs only make it more certain.

🤖 Generated with Claude Code

CodingAnarchy and others added 3 commits October 11, 2026 00:32
… claims

The stale job reaper decoded every reclaimed row (MySQL) or every row out of
attempts (PostgreSQL) and failed the whole pass on one it could not decode,
so no stale job was reclaimed while that row existed. It now reclaims such
rows from their raw columns and skips only the side effects that need the
decoded job.

MySQL claims left an undecodable row Pending at the head of its queue, so
single claims failed on it forever and batch claims of one job came back
empty. They now claim it like PostgreSQL does, so the queue moves on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a later level fails

dequeue_batch_leased with weighted priorities claims one level at a time,
each claim committing on its own. An error claiming a later level was
returned with `?`, dropping the jobs claimed from earlier levels: they
stayed Running until their leases expired, with an attempt spent, so a job
on its last attempt went Dead without running. Both backends now share
fill_weighted_batch, which returns the claimed jobs and logs the error, as
the trait's default implementation already did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A batch-mode worker checked the pause only when claiming, then started every
job of the batch it held, so pausing a queue let up to batch_size more jobs
start. Before starting a held job it now checks the pause at most once per
poll interval and, if the queue is paused, releases the unstarted jobs with
release_job_run (no attempt counted), as it does on shutdown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CodingAnarchy
CodingAnarchy merged commit 4ced15a into master Oct 11, 2026
17 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.

1 participant