fix: audit 2026-05-02 P1 follow-ups#108
Merged
pratyush618 merged 5 commits intomasterfrom May 2, 2026
Merged
Conversation
Sourcing status integers from the enum variant guarantees the build fails if `JobStatus` is reordered, instead of silently archiving or purging the wrong buckets. Same anti-pattern fixed across `archival.rs` and `jobs/maintenance.rs`.
`result()` / `aresult()` could raise `TimeoutError` even when the job had already failed/died/cancelled, when the terminal state landed during the final poll. A defensive re-poll inside the deadline branch lets the caller see the real exception class.
The Failure branch fetched the job up to three times — once for the queue context, once for `!should_retry` DLQ move, once for retry-exhausted DLQ move. One fetch is enough; subsequent uses hand the same `Option<&Job>` to a small DLQ closure.
Previously hit `asyncio.run() cannot be called from a running event loop`, which doesn't tell a user calling sync API from async code what to do. Detect the running-loop case explicitly and raise a taskito-specific error that points at the async API and `await`.
Previously the counter incremented before the factory ran and decremented in the failure branch. Restructured so the increment runs once we hold an instance — failure path simply releases the semaphore. Fixes a possible negative `active` in `stats()` and stops counting failed attempts as acquisitions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Five P1 follow-up fixes from the 2026-05-02 pre-release audit, after the four P0s shipped (#104, #105, #106, #107). One commit per fix.
archive_old_jobs,purge_completed,purge_completed_with_ttl,reap_stale_jobs,expire_pending_jobsnow castJobStatus::Foo as i32instead of using magic numbers. Reordering the enum will fail the build instead of silently archiving the wrong buckets.result()/aresult()— re-poll once inside the deadline branch so a terminal failure that landed during the previous poll surfaces asTaskFailedError/MaxRetriesExceededError/TaskCancelledError, notTimeoutError.result_handler.rs—Failurebranch fetchedget_jobup to three times per call (queue context + two DLQ moves). Restructured to one fetch + a small DLQ closure.run_maybe_async— explicit detection of a running event loop with a clear taskito-specific error, instead of the crypticasyncio.run() cannot be called from a running event loop.ResourcePool._active_count— increment moved to after the factory call returns successfully. Failure path no longer needs (or has) a decrement, so a wedged factory can't underflowactive. Failed attempts also stop counting againsttotal_acquisitions.Test plan
cargo test --workspace— 89 Rust tests passcargo check --workspace --features postgres— cleancargo check --workspace --features redis— cleancargo clippy --workspace -- -D warnings— cleanuv run python -m pytest tests/python/ -v— 496 passed, 9 skipped (was 488; +8 new acrosstest_result_race.py,test_run_maybe_async.py,test_resource_system_full.py::test_pool_factory_failure_does_not_underflow_active_count)uv run ruff check py_src/ tests/— cleanuv run mypy py_src/taskito/ --no-incremental— clean