Skip to content

Prevent deferred worker items from starving ready work - #51

Open
Thom Chiovoloni (thomcc-work) wants to merge 2 commits into
mainfrom
activity-admission-progress
Open

Thom Chiovoloni (thomcc-work) wants to merge 2 commits into
mainfrom
activity-admission-progress

Conversation

@thomcc-work

Copy link
Copy Markdown

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 0027 changes both session-aware and non-session fetches to order
eligible rows by visible_at, id. A deferred item therefore goes behind work
that was already ready, even after its delay expires.

  • Add a matching index on worker_queue(visible_at, id).
  • Preserve session ownership, tag filtering, peek-lock semantics, and attempt accounting.
  • Add regression tests covering expired deferrals across session/non-session and tagged/untagged work.
  • Update the changelog and migration guidance.

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

  • Replaces fetch_work_item without changing its signature or return shape.
  • Builds the new index non-concurrently, blocking queue writes during the build.
    Plan migration time accordingly for large queues.
  • Already-running older providers can use the updated function. Older binaries
    reject the new migration version on startup, so coordinate migration and
    worker rollout.

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>
Thom Chiovoloni (thomcc-work) added a commit that referenced this pull request Nov 2, 2026
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>
Thom Chiovoloni (thomcc-work) added a commit that referenced this pull request Nov 2, 2026
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>
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