Skip to content

Commit a0c8784

Browse files
committed
fix: default tracker version to 1 and remove version clamp from token decode
1 parent 7c4dbde commit a0c8784

3 files changed

Lines changed: 4 additions & 17 deletions

File tree

lib/sdk/server-ai/src/main/java/com/launchdarkly/sdk/server/ai/LDAIClientImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ private Supplier<LDAIConfigTracker> trackerFactory(
289289
LDContext context) {
290290
String modelName = model != null && model.getName() != null ? model.getName() : "";
291291
String providerName = provider != null && provider.getName() != null ? provider.getName() : "";
292-
int ver = version != null ? version : 0;
292+
int ver = version != null ? version : 1;
293293
return () -> new LDAIConfigTrackerImpl(
294294
client,
295295
UUID.randomUUID().toString(),

lib/sdk/server-ai/src/main/java/com/launchdarkly/sdk/server/ai/internal/ResumptionTokens.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ private static Decoded parseJson(String json) {
160160
throw new IllegalArgumentException("Resumption token missing required field 'version'");
161161
}
162162

163-
// Clamp version: a missing version field defaults to 0 in older tokens, but configs default to 1.
164-
int clampedVersion = Math.max(1, version);
165-
166-
return new Decoded(runId, configKey, variationKey, clampedVersion, graphKey);
163+
return new Decoded(runId, configKey, variationKey, version, graphKey);
167164
}
168165

169166
private static int skipWhitespace(String s, int pos) {

lib/sdk/server-ai/src/test/java/com/launchdarkly/sdk/server/ai/internal/ResumptionTokensTest.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,10 @@ public void roundTripWithUnicodeInKeys() {
7878
assertThat(d.getRunId(), is(runId));
7979
}
8080

81-
// ---- version clamping -----------------------------------------------------
81+
// ---- version round-trip ---------------------------------------------------
8282

8383
@Test
84-
public void versionBelowOneIsClampedToOne() {
85-
// Construct a token with version 0 directly to simulate an old token.
86-
String json = "{\"runId\":\"r\",\"configKey\":\"c\",\"version\":0}";
87-
String token = java.util.Base64.getUrlEncoder().withoutPadding()
88-
.encodeToString(json.getBytes(java.nio.charset.StandardCharsets.UTF_8));
89-
ResumptionTokens.Decoded d = ResumptionTokens.decode(token);
90-
assertThat(d.getVersion(), is(1));
91-
}
92-
93-
@Test
94-
public void versionOneIsNotClamped() {
84+
public void versionIsPreservedOnRoundTrip() {
9585
String token = ResumptionTokens.encode("r", "c", null, 1, null);
9686
assertThat(ResumptionTokens.decode(token).getVersion(), is(1));
9787
}

0 commit comments

Comments
 (0)