Skip to content

feat: add opt-in max_pending admission cap#449

Merged
pratyush618 merged 8 commits into
masterfrom
feat/s26-max-pending
Jul 18, 2026
Merged

feat: add opt-in max_pending admission cap#449
pratyush618 merged 8 commits into
masterfrom
feat/s26-max-pending

Conversation

@pratyush618

@pratyush618 pratyush618 commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Opt-in per-queue admission cap (S26, Tier 4). Once a queue's pending backlog reaches max_pending, enqueue/enqueue_many raise instead of letting the backlog grow unbounded — the inflow companion to retention's backlog bound. Off by default; a queue absent from the config is uncapped with zero overhead.

Design

  • Enqueue bypasses the scheduler (any process can enqueue with no worker running), so the cap is enforced producer-side at the enqueue path, not in QueueConfig.
  • New lean core storage primitive count_pending_by_queue(queue) — a single-status sibling of count_running_by_task, on all three backends (SQLite/Postgres via the Diesel macro, Redis SINTERCARD on jobs:by_queue).
  • Non-atomic count-then-insert: brief overshoot under concurrent producers is accepted, the same soft guarantee as the rate limiter.

Cross-SDK surface

  • PythonQueue(max_pending={...}) ctor kwarg + set_queue_max_pending; raises QueueFullError(QueueError).
  • NodeconfigureQueue(q, { maxPending }); throws QueueFullError extends QueueError; public countPendingByQueue.
  • JavaTaskito.maxPending(q, n); QueueFullException; countPendingByQueue on the Taskito interface + InMemoryQueueBackend.

Tests

  • Rust: count_pending_by_queue unit test + cross-backend contract suite.
  • Python 8 · Node 6 · Java 4 admission tests. Full suites green; clippy / ruff / mypy / biome / tsc clean.

Summary by CodeRabbit

  • New Features
    • Added countPendingByQueue / count_pending_by_queue primitives for per-queue pending counts across storage backends and Java, Node.js, and Python SDKs.
    • Introduced opt-in per-queue pending admission caps (maxPending / max_pending) for Java, Node.js, and Python, rejecting enqueues via new queue-full errors/exceptions.
    • Enforced cap checks for both single and batch enqueues (all-or-nothing for enqueueMany/enqueue_many).
    • Added QueueFullException (Java), QueueFullError (Node/Python), and runtime configuration support for Python caps.
  • Tests
    • Added/extended unit tests validating pending counts, cap enforcement, uncapped behavior, batch semantics, and capacity recovery.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 22 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6eadb241-39b9-42ff-ac3a-d8dcd3a88038

📥 Commits

Reviewing files that changed from the base of the PR and between 50a159b and 3e0ceba.

📒 Files selected for processing (1)
  • sdks/python/tests/core/test_admission.py
📝 Walkthrough

Walkthrough

Adds count_pending_by_queue across storage and language bindings, then introduces optional per-queue pending admission caps for Java, Node, and Python queues with queue-full errors and single/batch enqueue tests.

Changes

Pending count storage and bindings

Layer / File(s) Summary
Storage pending-count primitive
crates/taskito-core/src/storage/...
Adds the Storage API and Diesel/Redis implementations for counting pending jobs by queue, with forwarding and Rust tests.
SDK pending-count bridges
crates/taskito-java/..., crates/taskito-node/..., crates/taskito-python/..., sdks/java/src/main/java/...
Exposes the count operation through JNI, N-API, Python bindings, Java backends, and public SDK APIs.

Java admission caps

Layer / File(s) Summary
Java admission enforcement
sdks/java/src/main/java/org/byteveda/taskito/...
Adds per-queue maxPending, producer-side rejection, QueueFullException, and pending-count delegation.
Java admission validation
sdks/java/src/test/..., sdks/java/test-support/...
Tests counting, uncapped queues, cap rejection, batch sizing, negative-cap validation, and per-queue isolation.

Node admission caps

Layer / File(s) Summary
Node admission enforcement
sdks/node/src/queue.ts, sdks/node/src/types.ts, sdks/node/src/errors.ts, sdks/node/src/index.ts
Adds optional queue limits, QueueFullError, single and all-or-nothing batch checks, and the public pending-count method.
Node admission validation
sdks/node/test/core/admission.test.ts
Tests pending counts, cap behavior, per-queue isolation, batch rejection, negative-cap validation, and error fields.

Python admission caps

Layer / File(s) Summary
Python admission enforcement
sdks/python/taskito/app.py, sdks/python/taskito/mixins/runtime_config.py, sdks/python/taskito/exceptions.py
Adds constructor and runtime cap configuration, producer-side single and batch checks, batched-task flush checks, and QueueFullError.
Python API and validation
sdks/python/taskito/__init__.py, sdks/python/taskito/_taskito.pyi, sdks/python/tests/core/test_admission.py
Exports the new error, declares pending counting, and tests cap configuration, atomic batches, queue scoping, validation, and capacity recovery.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Queue
  participant Storage
  participant JobsTable
  Queue->>Storage: count_pending_by_queue(queue)
  Storage->>JobsTable: count Pending rows for queue
  JobsTable-->>Storage: pending count
  Storage-->>Queue: pending count
  Queue->>Queue: compare count with maxPending
  Queue-->>Queue: enqueue or raise QueueFullError
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding an opt-in max_pending admission cap.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/s26-max-pending

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java`:
- Around line 297-298: Extend the admission-cap enforcement from dispatchEnqueue
to enqueueMany: before calling backend.enqueueMany, validate the target queue’s
capacity against the current pending count plus the full batch size. Update or
reuse rejectIfQueueFull and the enqueueMany flow so the entire batch is rejected
before serialization or insertion when it would exceed the configured cap.
- Around line 151-173: Update maxPending(String queue, int cap) to validate that
cap is non-negative before storing it in maxPending. Reject negative values
immediately and leave the existing configuration unchanged; preserve the fluent
return behavior and allow zero as a valid cap.

In `@sdks/java/src/main/java/org/byteveda/taskito/spi/QueueBackend.java`:
- Around line 45-47: Update QueueBackend.countPendingByQueue to be a default
optional capability that throws the established unsupported-operation exception,
matching other optional methods and preserving existing implementations. Ensure
callers invoke it only when maxPending is configured, while retaining the
pending-count behavior when that setting is enabled.

In `@sdks/node/src/queue.ts`:
- Around line 473-476: Update enqueueMany in sdks/node/src/queue.ts at lines
473-476 to count jobs by target queue and reject each queue when its current
pending count plus the batch count exceeds its cap, while preserving
all-or-nothing behavior. Add the requested admission test in
sdks/node/test/core/admission.test.ts at lines 51-60 covering pending=1, cap=3,
and a five-job batch that throws.

In `@sdks/python/taskito/app.py`:
- Around line 927-930: Update the batch admission precheck around
_reject_if_queue_full in sdks/python/taskito/app.py: aggregate requested rows by
queue and reject when each queue’s pending count plus its requested rows exceeds
max_pending, before inserting any rows. Add a regression test in
sdks/python/tests/core/test_admission.py covering a batch larger than the
remaining capacity and assert that no rows are inserted.
- Around line 695-696: Ensure producer-side batched tasks enforce the configured
queue cap before dispatching accumulated items: update the batching flow around
`_dispatch_batched_payload()` so it invokes `_reject_if_queue_full()` for the
target queue before calling `_inner.enqueue()`. Preserve the existing
single-task check and apply the same default-queue fallback when no queue is
specified.

In `@sdks/python/tests/core/test_admission.py`:
- Around line 87-102: Strengthen test_cap_frees_after_drain by using a small
pending cap and enough queued work to fill it, asserting an additional enqueue
raises QueueFullError. Wait for the admitted jobs to complete, then enqueue one
more job and verify it succeeds, proving completed jobs release admission
capacity.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2cd5ef1e-56ff-43f5-b63d-f21c15a61afe

📥 Commits

Reviewing files that changed from the base of the PR and between e0f08c7 and 295793e.

📒 Files selected for processing (28)
  • crates/taskito-core/src/storage/diesel_common/jobs.rs
  • crates/taskito-core/src/storage/mod.rs
  • crates/taskito-core/src/storage/redis_backend/jobs/query.rs
  • crates/taskito-core/src/storage/sqlite/tests.rs
  • crates/taskito-core/src/storage/traits.rs
  • crates/taskito-core/tests/rust/storage_tests.rs
  • crates/taskito-java/src/queue/inspect.rs
  • crates/taskito-node/src/queue/mod.rs
  • crates/taskito-python/src/py_queue/mod.rs
  • sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
  • sdks/java/src/main/java/org/byteveda/taskito/Taskito.java
  • sdks/java/src/main/java/org/byteveda/taskito/errors/QueueFullException.java
  • sdks/java/src/main/java/org/byteveda/taskito/internal/JniQueueBackend.java
  • sdks/java/src/main/java/org/byteveda/taskito/internal/NativeQueue.java
  • sdks/java/src/main/java/org/byteveda/taskito/spi/QueueBackend.java
  • sdks/java/src/test/java/org/byteveda/taskito/core/AdmissionTest.java
  • sdks/java/test-support/src/main/java/org/byteveda/taskito/test/InMemoryQueueBackend.java
  • sdks/node/src/errors.ts
  • sdks/node/src/index.ts
  • sdks/node/src/queue.ts
  • sdks/node/src/types.ts
  • sdks/node/test/core/admission.test.ts
  • sdks/python/taskito/__init__.py
  • sdks/python/taskito/_taskito.pyi
  • sdks/python/taskito/app.py
  • sdks/python/taskito/exceptions.py
  • sdks/python/taskito/mixins/runtime_config.py
  • sdks/python/tests/core/test_admission.py

Comment thread sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
Comment thread sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java Outdated
Comment thread sdks/java/src/main/java/org/byteveda/taskito/spi/QueueBackend.java Outdated
Comment thread sdks/node/src/queue.ts Outdated
Comment thread sdks/python/taskito/app.py
Comment thread sdks/python/taskito/app.py Outdated
Comment thread sdks/python/tests/core/test_admission.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sdks/python/tests/core/test_admission.py`:
- Line 150: Update the worker cleanup in the test around worker.join to assert
that worker.is_alive() is false after the timed join, ensuring the test fails
when the worker remains stuck.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 98c96943-b3a9-4c29-8a48-3007b3d0aef7

📥 Commits

Reviewing files that changed from the base of the PR and between 295793e and 50a159b.

📒 Files selected for processing (8)
  • sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
  • sdks/java/src/main/java/org/byteveda/taskito/spi/QueueBackend.java
  • sdks/java/src/test/java/org/byteveda/taskito/core/AdmissionTest.java
  • sdks/node/src/queue.ts
  • sdks/node/test/core/admission.test.ts
  • sdks/python/taskito/app.py
  • sdks/python/taskito/mixins/runtime_config.py
  • sdks/python/tests/core/test_admission.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • sdks/python/taskito/mixins/runtime_config.py
  • sdks/node/test/core/admission.test.ts
  • sdks/node/src/queue.ts
  • sdks/python/taskito/app.py

Comment thread sdks/python/tests/core/test_admission.py
@pratyush618
pratyush618 merged commit 8df8819 into master Jul 18, 2026
35 checks passed
@pratyush618
pratyush618 deleted the feat/s26-max-pending branch July 18, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant