Skip to content

feat(java): add two-sided payload codecs#351

Merged
pratyush618 merged 3 commits into
masterfrom
feat/java-payload-codecs-core
Jul 1, 2026
Merged

feat(java): add two-sided payload codecs#351
pratyush618 merged 3 commits into
masterfrom
feat/java-payload-codecs-core

Conversation

@pratyush618

@pratyush618 pratyush618 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

What

Adds a payload codec layer — a two-sided byte-to-byte transform applied after serialization on the producer and reversed before deserialization on the worker. One implementation owns both directions, so the inverse can't drift (cf. Temporal Payload Codec, Sidekiq middleware).

  • PayloadCodec SPI — encode(byte[]) / decode(byte[]).
  • CodecSerializer — wraps any Serializer with an ordered codec chain: encode in order after serialization, decode in reverse before deserialization. Independent of the serializer, so a chain works over JSON or MessagePack alike, reusing the single serializer channel the worker already gets.
  • Built-in codecs: GzipCodec (compression), AesGcmCodec (authenticated encryption), HmacCodec (signing).
  • Wired via Taskito.builder().codec(...).

Test

PayloadCodecTest — round-trips each codec and a multi-codec chain (compress-then-encrypt), asserts order/reversal and that a tampered/corrupt payload fails to decode.

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

Summary by CodeRabbit

  • New Features

    • Added support for chaining payload transformations when creating a client, including compression, encryption, and integrity checks.
    • Added built-in options for gzip compression, AES-GCM encryption, and HMAC verification.
    • Jobs now use the configured transformation chain consistently for both sending and receiving payloads.
  • Tests

    • Added coverage for payload transformation round-trips, tamper detection, and end-to-end job handling with chained transformations.

PayloadCodec (encode/decode) applied after serialize and reversed before
deserialize, chained via Taskito.builder().codec(...). Gzip/AesGcm/Hmac
built-ins compose over any serializer through one CodecSerializer, reusing
the serializer channel so producer and worker stay in lockstep.
Per-codec round-trips, tamper rejection, reverse-order chain, worker e2e.
@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: 45 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: 861de271-c37e-455f-a2b4-02692c511261

📥 Commits

Reviewing files that changed from the base of the PR and between 5b5bbb5 and 0873eeb.

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

Walkthrough

Adds a PayloadCodec interface and three implementations (Gzip, AES-GCM, HMAC), a CodecSerializer that composes codecs around a delegate Serializer, wires codec configuration into Taskito.Builder via an effectiveSerializer, and adds tests for codecs and end-to-end worker round-trips.

Changes

Payload Codec Chain

Layer / File(s) Summary
PayloadCodec contract
.../serialization/PayloadCodec.java
Defines encode/decode byte transform interface with chaining/inversion semantics documented.
CodecSerializer composition
.../serialization/CodecSerializer.java
Wraps a delegate Serializer, applying codecs forward on serialize and in reverse order on deserialize.
GzipCodec implementation
.../serialization/GzipCodec.java
Implements PayloadCodec using gzip streams, wrapping IOException as SerializationException.
AesGcmCodec implementation
.../serialization/AesGcmCodec.java
Implements PayloadCodec using AES-GCM with random per-payload IV prefixed to ciphertext, wrapping failures as CryptoException.
HmacCodec implementation
.../serialization/HmacCodec.java
Implements PayloadCodec using HMAC-SHA256 tag prefixing and constant-time verification, wrapping failures as CryptoException.
Taskito.Builder codec wiring
Taskito.java
Adds codec(PayloadCodec...) and an effectiveSerializer() that wraps the base serializer with CodecSerializer when codecs are configured, used in both open() overloads.
Codec and end-to-end tests
PayloadCodecTest.java
Adds unit tests for each codec, chain reversibility, and a worker integration round-trip test.

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

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant CodecSerializer
  participant Serializer
  participant PayloadCodec

  Caller->>CodecSerializer: serialize(value)
  CodecSerializer->>Serializer: serialize(value)
  Serializer-->>CodecSerializer: bytes
  loop each codec forward
    CodecSerializer->>PayloadCodec: encode(bytes)
    PayloadCodec-->>CodecSerializer: encoded bytes
  end
  CodecSerializer-->>Caller: final bytes

  Caller->>CodecSerializer: deserialize(bytes, type)
  loop each codec reverse
    CodecSerializer->>PayloadCodec: decode(bytes)
    PayloadCodec-->>CodecSerializer: decoded bytes
  end
  CodecSerializer->>Serializer: deserialize(bytes, type)
  Serializer-->>CodecSerializer: value
  CodecSerializer-->>Caller: value
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding two-sided payload codecs to the Java SDK.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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-payload-codecs-core

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

@pratyush618

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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

🧹 Nitpick comments (1)
sdks/java/src/main/java/org/byteveda/taskito/serialization/AesGcmCodec.java (1)

23-25: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider validating key length upfront.

The javadoc states the key must be 16/24/32 bytes, but the constructor doesn't enforce it — an invalid key only surfaces later as a generic CryptoException from cipher.init() inside encode/decode, which obscures the real cause.

♻️ Proposed fix
 public AesGcmCodec(byte[] key) {
+    if (key.length != 16 && key.length != 24 && key.length != 32) {
+        throw new IllegalArgumentException("AES key must be 16, 24, or 32 bytes");
+    }
     this.key = new SecretKeySpec(key, "AES");
 }
🤖 Prompt for 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.

In `@sdks/java/src/main/java/org/byteveda/taskito/serialization/AesGcmCodec.java`
around lines 23 - 25, The AesGcmCodec constructor currently accepts any byte[]
key without enforcing the documented 16/24/32-byte requirement, so invalid input
only fails later in encode/decode. Add upfront validation in AesGcmCodec(byte[]
key) to check the key length before creating the SecretKeySpec, and fail fast
with a clear exception message that mentions the expected AES key sizes.
🤖 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/serialization/GzipCodec.java`:
- Around line 24-31: The GZIP decode path in GzipCodec.decode is currently
unbounded because it calls readAllBytes(), which can allow a small payload to
expand into excessive memory usage. Update GzipCodec to enforce a maximum
decompressed size by reading through GZIPInputStream into a fixed-capacity
buffer and throwing a SerializationException once the limit is exceeded, or add
clear documentation/ordering constraints if decompression must only happen after
integrity verification. Keep the fix localized to GzipCodec.decode and preserve
the existing error handling pattern.

---

Nitpick comments:
In `@sdks/java/src/main/java/org/byteveda/taskito/serialization/AesGcmCodec.java`:
- Around line 23-25: The AesGcmCodec constructor currently accepts any byte[]
key without enforcing the documented 16/24/32-byte requirement, so invalid input
only fails later in encode/decode. Add upfront validation in AesGcmCodec(byte[]
key) to check the key length before creating the SecretKeySpec, and fail fast
with a clear exception message that mentions the expected AES key sizes.
🪄 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: 0bd64a63-9a36-47df-b03a-289bdfd1b435

📥 Commits

Reviewing files that changed from the base of the PR and between 45f1e46 and 5b5bbb5.

📒 Files selected for processing (7)
  • sdks/java/src/main/java/org/byteveda/taskito/Taskito.java
  • sdks/java/src/main/java/org/byteveda/taskito/serialization/AesGcmCodec.java
  • sdks/java/src/main/java/org/byteveda/taskito/serialization/CodecSerializer.java
  • sdks/java/src/main/java/org/byteveda/taskito/serialization/GzipCodec.java
  • sdks/java/src/main/java/org/byteveda/taskito/serialization/HmacCodec.java
  • sdks/java/src/main/java/org/byteveda/taskito/serialization/PayloadCodec.java
  • sdks/java/src/test/java/org/byteveda/taskito/PayloadCodecTest.java

@pratyush618 pratyush618 merged commit 1e489c4 into master Jul 1, 2026
18 checks passed
@pratyush618 pratyush618 deleted the feat/java-payload-codecs-core branch July 1, 2026 18:05
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