Skip to content

Commit 80ef017

Browse files
committed
fix: pass instance logger to createGraphTracker for resumed runs
1 parent a0a3a54 commit 80ef017

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ public final class AIGraphTracker {
9292
*/
9393
public static AIGraphTracker fromResumptionToken(
9494
String token, LDClientInterface client, LDContext context) {
95+
return fromResumptionToken(token, client, context, defaultLogger());
96+
}
97+
98+
/**
99+
* Reconstructs a graph tracker from a resumption token, preserving the original run identity,
100+
* and logging through the supplied logger.
101+
*
102+
* @param token the resumption token produced by {@link #getResumptionToken()}
103+
* @param client the LaunchDarkly client; must not be {@code null}
104+
* @param context the evaluation context; must not be {@code null}
105+
* @param logger the logger to use for at-most-once warnings; must not be {@code null}
106+
* @return a new tracker with the decoded run identity
107+
* @throws IllegalArgumentException if the token is malformed
108+
*/
109+
public static AIGraphTracker fromResumptionToken(
110+
String token, LDClientInterface client, LDContext context, LDLogger logger) {
95111
ResumptionTokens.DecodedGraph d = ResumptionTokens.decodeGraph(token);
96112
int version = Math.max(1, d.getVersion());
97113
return new AIGraphTracker(
@@ -101,7 +117,7 @@ public static AIGraphTracker fromResumptionToken(
101117
d.getVariationKey(),
102118
version,
103119
context,
104-
defaultLogger());
120+
logger);
105121
}
106122

107123
/**

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
@@ -444,7 +444,7 @@ private static Set<String> collectReachableKeys(AgentGraphFlagValue flagValue) {
444444

445445
@Override
446446
public AIGraphTracker createGraphTracker(String resumptionToken, LDContext context) {
447-
return AIGraphTracker.fromResumptionToken(resumptionToken, client, context);
447+
return AIGraphTracker.fromResumptionToken(resumptionToken, client, context, logger);
448448
}
449449

450450
@Override

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,24 @@ public void fromResumptionTokenPreservesRunId() {
382382
assertThat(captor.getValue().get("graphKey").stringValue(), is(GRAPH_KEY));
383383
}
384384

385+
@Test
386+
public void fromResumptionTokenWithLoggerRoutesWarningsThroughIt() {
387+
LogCapture captureForResumed = Logs.capture();
388+
LDLogger resumedLogger = LDLogger.withAdapter(captureForResumed, "test");
389+
String token = tracker.getResumptionToken();
390+
AIGraphTracker reconstructed = AIGraphTracker.fromResumptionToken(token, client, CONTEXT, resumedLogger);
391+
392+
reconstructed.trackInvocationSuccess();
393+
reconstructed.trackInvocationSuccess(); // duplicate — should warn on resumedLogger, not the base logCapture
394+
395+
List<String> resumedWarnings = captureForResumed.getMessages().stream()
396+
.filter(m -> m.getLevel() == LDLogLevel.WARN)
397+
.map(LogCapture.Message::getText)
398+
.collect(Collectors.toList());
399+
assertThat(resumedWarnings.stream().anyMatch(w -> w.contains("invocation already recorded")), is(true));
400+
assertThat(logCapture.getMessages(), is(org.hamcrest.Matchers.empty()));
401+
}
402+
385403
@Test
386404
public void fromResumptionTokenClampsVersionLessThanOne() {
387405
AIGraphTracker t = new AIGraphTracker(client, RUN_ID, GRAPH_KEY, null, 0, CONTEXT, logger);

0 commit comments

Comments
 (0)