-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[OPIK-8192] [BE] fix: drop undecodable scoring stream messages instead of wedging the stream #8089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thiagohora
merged 19 commits into
main
from
thiagohora/OPIK-8192-drop-undecodable-scoring-messages
Sep 3, 2026
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e4aecb9
[OPIK-8192] [BE] fix: drop undecodable scoring stream messages instea…
thiagohora 32acf25
fix: address review cycle 1 — retry before dropping, and close the fi…
thiagohora 3675300
fix: address review cycle 2 — split the two no-payload causes, stop l…
thiagohora 30c30a2
fix: address review cycle 3 — repair BaseRedisSubscriberTest and a 1.…
thiagohora 4c2afe1
fix: keep the decoder counter to decode failures, enforce the sentine…
thiagohora 0ddb90c
fix: route doFinally through recordQueueDelay, document the shared re…
thiagohora 8e827ec
docs: the retry caveats that two earlier commit messages claimed but …
thiagohora 4072aee
docs: clearer contrast in the retry-budget caveat
thiagohora bdd1895
Merge branch 'main' into thiagohora/OPIK-8192-drop-undecodable-scorin…
thiagohora 8a724b2
Merge branch 'main' into thiagohora/OPIK-8192-drop-undecodable-scorin…
thiagohora 396a9f8
Merge branch 'main' into thiagohora/OPIK-8192-drop-undecodable-scorin…
thiagohora 5cbfc75
fix: name the size honestly, correct the drain rationale, document th…
thiagohora ff5c966
fix: bound the LZ4 declared-length allocation, fix the value-path jav…
thiagohora 4f4a679
fix: correct the LZ4 bytecode javadoc, un-orphan a contract, drop a n…
thiagohora d7dc961
refactor: absorb OutOfMemoryError instead of pre-checking the LZ4 dec…
thiagohora 7cef0b8
docs: both failure modes measured, and whether absorbing an OOM recovers
thiagohora d8ffd35
test: drive a real StreamConstraintsException through a real stream e…
thiagohora ad70f77
test: pin the CompositeCodec argument order, and mark what is not pinned
thiagohora 316db5a
fix: deflake the integration test, assert XACK, stop allocating gigab…
thiagohora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...k-backend/src/main/java/com/comet/opik/infrastructure/redis/UndecodableStreamMessage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.comet.opik.infrastructure.redis; | ||
|
|
||
| /** | ||
| * Stand-in for a stream entry whose payload the codec could not decode. | ||
| * <p> | ||
| * Without this, a decode failure is thrown inside Redisson's {@code CommandDecoder} — below | ||
| * {@code BaseRedisSubscriber}, before any {@code StreamMessageId} is in hand. With no id there is | ||
| * nothing to ack, retry or remove, so the entry is redelivered forever and, at | ||
| * {@code consumerBatchSize > 1}, strands every healthy entry claimed alongside it. That is the | ||
| * permanent wedge behind OPIK-8164: one oversized trace took two production scoring streams to | ||
| * {@code pending == XLEN} and 19.66 GiB. | ||
| * <p> | ||
| * Returning this instead of throwing keeps the failure inside the normal message flow, where the id | ||
| * is known, so {@code BaseRedisSubscriber} can drop the entry, count it and log it. A payload we | ||
| * cannot decode will never become decodable, so dropping is the only outcome that terminates. | ||
| * | ||
| * @param payloadBytes readable bytes the decoder was handed, for sizing the offending entry | ||
| * @param cause the decode failure, kept for the log rather than rethrown | ||
| */ | ||
| public record UndecodableStreamMessage(int payloadBytes, Throwable cause) { | ||
|
thiagohora marked this conversation as resolved.
Outdated
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...ckend/src/test/java/com/comet/opik/infrastructure/redis/FaultTolerantStreamCodecTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package com.comet.opik.infrastructure.redis; | ||
|
|
||
| import com.fasterxml.jackson.core.StreamReadConstraints; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import io.netty.buffer.ByteBuf; | ||
| import io.netty.buffer.Unpooled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.redisson.client.codec.Codec; | ||
| import org.redisson.codec.JsonJacksonCodec; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** | ||
| * The decode side of {@link RedisStreamCodec#JAVA} must never throw: a throw lands inside Redisson's | ||
| * {@code CommandDecoder}, below {@code BaseRedisSubscriber} and before any {@code StreamMessageId} exists, | ||
| * so the entry can never be acked or removed and the stream wedges permanently (OPIK-8164). | ||
| * <p> | ||
| * Container-free on purpose -- this is decoder behaviour, and the wedge it prevents needs no Redis to | ||
| * demonstrate. | ||
| */ | ||
| @DisplayName("Fault-tolerant stream codec") | ||
| class FaultTolerantStreamCodecTest { | ||
|
|
||
| private static final int SMALL_STRING_LIMIT = 64; | ||
|
|
||
| /** A mapper whose string limit is small enough to breach without allocating megabytes. */ | ||
| private static Codec codecWithSmallStringLimit() { | ||
| var mapper = new ObjectMapper(); | ||
| mapper.getFactory().setStreamReadConstraints( | ||
| StreamReadConstraints.builder().maxStringLength(SMALL_STRING_LIMIT).build()); | ||
| return RedisStreamCodec.faultTolerant(new JsonJacksonCodec(mapper)); | ||
| } | ||
|
|
||
| private static ByteBuf json(String payload) { | ||
| return Unpooled.wrappedBuffer(payload.getBytes(StandardCharsets.UTF_8)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("a payload over the string limit decodes to a sentinel instead of throwing") | ||
| void oversizedPayloadYieldsSentinel() throws IOException { | ||
| var oversized = "\"%s\"".formatted("a".repeat(SMALL_STRING_LIMIT + 1)); | ||
| var buf = json(oversized); | ||
| var payloadBytes = buf.readableBytes(); | ||
|
|
||
| var decoded = codecWithSmallStringLimit().getMapValueDecoder().decode(buf, null); | ||
|
|
||
| assertThat(decoded).isInstanceOf(UndecodableStreamMessage.class); | ||
| var undecodable = (UndecodableStreamMessage) decoded; | ||
| assertThat(undecodable.payloadBytes()).isEqualTo(payloadBytes); | ||
| assertThat(undecodable.cause()).isNotNull(); | ||
| // The size is reported from the buffer, so it survives the failed decode consuming it. | ||
| assertThat(buf.isReadable()).isFalse(); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("a well-formed payload still decodes normally") | ||
| void wellFormedPayloadStillDecodes() throws IOException { | ||
| var decoded = codecWithSmallStringLimit().getMapValueDecoder().decode(json("\"within limits\""), null); | ||
|
|
||
| assertThat(decoded).isEqualTo("within limits"); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("malformed JSON decodes to a sentinel rather than throwing") | ||
| void malformedJsonYieldsSentinel() throws IOException { | ||
| var decoded = codecWithSmallStringLimit().getMapValueDecoder().decode(json("{not json"), null); | ||
|
|
||
| assertThat(decoded).isInstanceOf(UndecodableStreamMessage.class); | ||
| } | ||
|
|
||
| /** | ||
| * The wire format must not move. Encoders are handed through untouched, so a pod on either build | ||
| * writes bytes the other can read and a rolling upgrade is safe in both directions. | ||
| */ | ||
| @Test | ||
| @DisplayName("encoders are the delegate's own, so the wire format is unchanged") | ||
| void encodersAreUntouched() { | ||
| var delegate = new JsonJacksonCodec(new ObjectMapper()); | ||
| var tolerant = RedisStreamCodec.faultTolerant(delegate); | ||
|
|
||
| assertThat(tolerant.getMapValueEncoder()).isSameAs(delegate.getMapValueEncoder()); | ||
| assertThat(tolerant.getMapKeyEncoder()).isSameAs(delegate.getMapKeyEncoder()); | ||
| assertThat(tolerant.getValueEncoder()).isSameAs(delegate.getValueEncoder()); | ||
| assertThat(tolerant.getMapKeyDecoder()).isSameAs(delegate.getMapKeyDecoder()); | ||
| assertThat(tolerant.getClassLoader()).isSameAs(delegate.getClassLoader()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("the shipped JAVA codec is fault tolerant") | ||
| void shippedJavaCodecIsFaultTolerant() throws IOException { | ||
| // Guards the wiring, not the wrapper: the enum must hand the stream a decoder that cannot throw. | ||
| var decoded = RedisStreamCodec.JAVA.getCodec().getMapValueDecoder().decode(json("{not json"), null); | ||
|
|
||
| assertThat(decoded).isInstanceOf(UndecodableStreamMessage.class); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.