Skip to content

feat(java): add enqueue interception#350

Merged
pratyush618 merged 4 commits into
masterfrom
feat/java-interception
Jul 1, 2026
Merged

feat(java): add enqueue interception#350
pratyush618 merged 4 commits into
masterfrom
feat/java-interception

Conversation

@pratyush618

@pratyush618 pratyush618 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

What

Adds org.byteveda.taskito.interception — a producer-side hook that inspects each enqueue before serialization and decides its fate, using a sealed strategy type.

  • Interceptor (@FunctionalInterface) — intercept(taskName, payload) returns an Interception.
  • Interception (sealed interface + pattern-matching switch):
    • Pass — enqueue unchanged.
    • Convert(payload) — replace the payload (e.g. with a proxy reference).
    • Redirect(taskName, payload) — enqueue a different task instead.
    • Reject(reason) — block the enqueue (InterceptionException).
  • Wired into the single enqueue point DefaultTaskito.dispatchEnqueue, ordered interceptors → onEnqueue middleware → predicate gate, so a redirect/convert is seen by middleware and the final gate. Taskito.intercept(interceptor) registers one (CopyOnWriteArrayList).

Pairs with proxies (#349): an interceptor can Convert a non-serializable arg into a signed ProxyRef. No hard dependency — interception stays decoupled.

Test

InterceptionTest — each strategy (pass/convert/redirect/reject) plus ordering: an interceptor's rewrite is visible to onEnqueue middleware and the gate.

./gradlew build green (JDK 17 build leg + 21/25 test legs).

Summary by CodeRabbit

  • New Features

    • Added enqueue interception support, allowing submitted tasks to be transformed, redirected, or rejected before being queued.
    • Introduced a new interception API for registering custom interceptors.
    • Added support for reporting enqueue rejection errors.
  • Tests

    • Added coverage for payload conversion, task redirection, and enqueue rejection behavior.

Taskito.intercept(...) runs an Interceptor over each enqueue before
serialization, returning Pass / Convert(payload) / Redirect(task,payload)
/ Reject(reason). Convert pairs with proxies; Reject throws
InterceptionException. Explicit transform over the typed payload.
Convert, redirect, and reject.
@coderabbitai

coderabbitai Bot commented Jul 1, 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: 36 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: 6263ac6a-1273-4550-95c0-bc4093a9be65

📥 Commits

Reviewing files that changed from the base of the PR and between a4d9ffc and c744f69.

📒 Files selected for processing (2)
  • sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
  • sdks/java/src/test/java/org/byteveda/taskito/InterceptionTest.java
📝 Walkthrough

Walkthrough

This PR adds a producer-side interception mechanism to Taskito. New Interception sealed interface and Interceptor functional interface allow pass/convert/redirect/reject outcomes before enqueue. DefaultTaskito.dispatchEnqueue runs interceptors before middleware, with a new intercept() registration method and InterceptionException for rejections.

Changes

Producer-side enqueue interception

Layer / File(s) Summary
Interception contracts and exception
sdks/java/.../interception/Interception.java, sdks/java/.../interception/Interceptor.java, sdks/java/.../errors/InterceptionException.java, sdks/java/.../interception/package-info.java
Defines sealed Interception outcomes (Pass, Convert, Redirect, Reject), the Interceptor functional interface, InterceptionException, and package-level documentation.
Public API and registration
sdks/java/.../Taskito.java, sdks/java/.../DefaultTaskito.java
Adds intercept(Interceptor) to the Taskito interface and its DefaultTaskito implementation, backed by a new interceptors list.
Enqueue dispatch integration
sdks/java/.../DefaultTaskito.java
dispatchEnqueue runs registered interceptors before creating EnqueueContext, handling reject/redirect/convert outcomes ahead of middleware invocation.
Interception tests
sdks/java/src/test/.../InterceptionTest.java
Adds JUnit tests covering payload conversion, task redirection, and enqueue rejection.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Producer
  participant DefaultTaskito
  participant Interceptor
  participant Middleware
  participant Backend

  Producer->>DefaultTaskito: enqueue(taskName, payload)
  DefaultTaskito->>Interceptor: intercept(taskName, payload)
  alt Reject
    Interceptor-->>DefaultTaskito: Interception.Reject(reason)
    DefaultTaskito-->>Producer: throw InterceptionException
  else Redirect
    Interceptor-->>DefaultTaskito: Interception.Redirect(taskName, payload)
    DefaultTaskito->>DefaultTaskito: rewrite taskName/payload
  else Convert
    Interceptor-->>DefaultTaskito: Interception.Convert(payload)
    DefaultTaskito->>DefaultTaskito: rewrite payload
  end
  DefaultTaskito->>Middleware: onEnqueue(EnqueueContext)
  Middleware-->>DefaultTaskito: possibly mutated payload
  DefaultTaskito->>Backend: submit gated/encoded payload
Loading

Possibly related PRs

  • ByteVeda/taskito#341: Both PRs modify DefaultTaskito.dispatchEnqueue to add producer-side enqueue-time control before EnqueueContext/middleware execution.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.65% 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 and concisely summarizes the main change: adding enqueue interception in the Java SDK.
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/java-interception

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

@pratyush618 pratyush618 self-assigned this Jul 1, 2026

@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: 2

🤖 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 154-173: `enqueueMany()` / `enqueueAll()` are still bypassing the
interception pipeline used by `dispatchEnqueue()`. Update the batch enqueue flow
in `DefaultTaskito` so each item goes through the same `Interceptor` and
`Middleware` handling as single enqueues, or explicitly disallow/document
interception for batch APIs; ensure `Reject`, `Convert`, and `Redirect` are
applied consistently before serialization and submission.
- Around line 156-164: Reject null interceptor results explicitly in
DefaultTaskito’s interceptor loop: the intercept(...) call currently falls
through when it returns null, which hides interceptor bugs and lets enqueue
continue unexpectedly. Update the logic around the Interceptor.intercept,
Interception.Reject/Redirect/Convert handling to check for a null outcome
immediately after the call and fail fast with a clear exception before any
branch processing.
🪄 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: e4208e01-5056-4553-a870-282793b92ce5

📥 Commits

Reviewing files that changed from the base of the PR and between 5600c15 and a4d9ffc.

📒 Files selected for processing (7)
  • 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/InterceptionException.java
  • sdks/java/src/main/java/org/byteveda/taskito/interception/Interception.java
  • sdks/java/src/main/java/org/byteveda/taskito/interception/Interceptor.java
  • sdks/java/src/main/java/org/byteveda/taskito/interception/package-info.java
  • sdks/java/src/test/java/org/byteveda/taskito/InterceptionTest.java

Comment thread sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
Comment thread sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
@pratyush618 pratyush618 merged commit 45f1e46 into master Jul 1, 2026
18 checks passed
@pratyush618 pratyush618 deleted the feat/java-interception branch July 1, 2026 17:20
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