feat(java): add two-sided payload codecs#351
Conversation
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.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 45 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a ChangesPayload Codec Chain
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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@CodeRabbit review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
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 valueConsider 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
CryptoExceptionfromcipher.init()insideencode/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
📒 Files selected for processing (7)
sdks/java/src/main/java/org/byteveda/taskito/Taskito.javasdks/java/src/main/java/org/byteveda/taskito/serialization/AesGcmCodec.javasdks/java/src/main/java/org/byteveda/taskito/serialization/CodecSerializer.javasdks/java/src/main/java/org/byteveda/taskito/serialization/GzipCodec.javasdks/java/src/main/java/org/byteveda/taskito/serialization/HmacCodec.javasdks/java/src/main/java/org/byteveda/taskito/serialization/PayloadCodec.javasdks/java/src/test/java/org/byteveda/taskito/PayloadCodecTest.java
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).
PayloadCodecSPI —encode(byte[])/decode(byte[]).CodecSerializer— wraps anySerializerwith an ordered codec chain:encodein order after serialization,decodein 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.GzipCodec(compression),AesGcmCodec(authenticated encryption),HmacCodec(signing).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 buildgreen (JDK 17 build leg + 21/25 test legs).Summary by CodeRabbit
New Features
Tests