Repository navigation
Prevent deferred worker items from starving ready work - #51
Thom Chiovoloni (thomcc-work) wants to merge 2 commits into
Conversation
Order eligible worker items by visibility time, then queue ID, so expired deferrals cannot repeatedly overtake work that was already ready. Add migration 0027 and a matching index, preserving session ownership, tag filtering, locking, and attempt accounting. Add regression tests for session/non-session and tagged/untagged work, and document rollout impact.
Renumber the migration to 0029 and add its baseline-0016 diff. Centralize rollout guidance, including concurrent index preparation and the SHARE lock retained even when the build is skipped. Reject invalid prebuilt indexes without changing the migration ledger, fetch function, or queued work. Add red/green regression coverage, enforce unique increasing embedded versions in a unit test, refresh the embed marker, and reuse panic-safe test schema cleanup. Validation: 301 related unit, provider, and migration tests passed (one skipped); targeted regressions passed from fresh Cargo target directories. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
aca6832 to
9ae067b
Compare
Keep the database message in ordinary migration error display while retaining the SQLx source for SQLSTATE retry classification. Add a red/green regression that also proves failed migration statements leave the ledger, stored function, and durable rows unchanged. State that migration 0030 must not ship before the 0027-0029 prerequisites, including the dependency of #51 on #32. Addresses review items 41-N6 and 41-N7. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Match #51's associated load_migrations and parse_version functions, including the failed-unlock regression added by #41. This keeps the standalone branch buildable and avoids E0599 when the prerequisite changes are combined. Retain b33a3f2's connection-reuse behavior without changing pool sizing or tuning for the upstream barrier-based test. Addresses review item 41-N11. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pinned to 9ae067b, alongside the merged duroxide revision. Changes: - Updated the provider dependency and lockfile. - Advanced WORKER_SCHEMA_VERSION to 4 for the bundled migrations. - Added a 500-request backlog regression. - Updated migration, rollout, and behavior documentation.
Todd J. Green (tjgreen42)
left a comment
There was a problem hiding this comment.
Review by GPT-6.1 Sol.
No actionable correctness findings in this revision. Reviewed the visibility-first dequeue ordering, claim/session eligibility and locking, migration registration and validation, and starvation regression coverage.
Release coordination note: do not ship/apply migration 0029 before #32 supplies 0027/0028; a later combined build would reject that applied ledger as a non-prefix. This dependency is already documented in #41, but would also be useful in this PR description, which still calls the migration 0027.
Scope: static review at 9ae067b. No PostgreSQL integration tests were run. Local nextest validation was blocked by the resolved uuid dependency requiring Rust 1.89 while the available toolchain was 1.88.
|
Review by GPT-6.1 Sol: The PR description is stale relative to the current diff. Please update it to:
The core ordering behavior and provider compatibility summary remain accurate. |
Summary
Prevent a backlog of deferred activities from starving unrelated ready work.
Previously, worker fetches selected eligible rows by queue ID alone. Deferred
items retained their original IDs, so if their retry delays expired before the
backlog drained, they could repeatedly be selected ahead of newer ready work.
Migration
0029changes both session-aware and non-session fetches to ordereligible rows by
visible_at, id. A deferred item therefore goes behind workthat was already ready, even after its delay expires.
idx_worker_ready_orderonworker_queue(visible_at, id).showing the function changes against baseline
0016and the new index.This is the PostgreSQL-provider companion to microsoft/duroxide#74. It does
not change activity admission APIs or introduce a Duroxide dependency bump.
Migration and compatibility
The migration replaces
fetch_work_itemwithout changing its signature orreturn shape.
By default, the index is built non-concurrently inside the migration
transaction. For busy or large queues, pre-build the matching index with
CREATE INDEX CONCURRENTLY, outside a transaction, in each target schemabefore applying the migration. The migration will then skip the expensive
index build.
Even when reusing a prebuilt index, the migration takes a
SHARElock onworker_queueand holds it until transaction commit. This blocks workerfetch, acknowledge, abandon, and lock renewal, as well as orchestration
acknowledgements that write worker rows. The migration sets no
lock_timeout,so lock acquisition can wait indefinitely unless a deployment-session
lock_timeoutis configured. Prebuilding reduces the work performed whileholding the lock; it does not make the migration lock-free.
Invalid prebuilt indexes, including those left by failed or cancelled
concurrent builds, are rejected without changing the migration ledger,
fetch function, or queued work.
See the rollout notes
for prebuild, verification, and repair instructions.
Already-running older providers can use the updated function. Older binaries
reject the new migration version on startup, so coordinate migration and
worker rollout.
Validation
Local validation at
9ae067b: 301 related unit, provider-validation, andmigration tests passed; one skipped.
Regression coverage includes:
and tagged/untagged combinations.
before/after snapshots proving the migration ledger, fetch function,
queued work, and index state remain unchanged.
that the existing index is reused.
strictly increasing.
The worker progress tests now reuse panic-safe schema cleanup.