alerting(eval): EvalResult.Batch carries nextEvalState for cursor threading

This commit is contained in:
hsiegeln
2026-04-22 15:42:20 +02:00
parent 031fe725b5
commit 6fa8e3aa30
4 changed files with 11 additions and 6 deletions

View File

@@ -64,13 +64,13 @@ public class AgentLifecycleEvaluator implements ConditionEvaluator<AgentLifecycl
List<AgentEventRecord> matches = eventRepo.findInWindow(
envSlug, appSlug, agentId, typeNames, from, to, MAX_EVENTS_PER_TICK);
if (matches.isEmpty()) return new EvalResult.Batch(List.of());
if (matches.isEmpty()) return new EvalResult.Batch(List.of(), Map.of());
List<EvalResult.Firing> firings = new ArrayList<>(matches.size());
for (AgentEventRecord ev : matches) {
firings.add(toFiring(ev));
}
return new EvalResult.Batch(firings);
return new EvalResult.Batch(firings, Map.of());
}
private static EvalResult.Firing toFiring(AgentEventRecord ev) {

View File

@@ -17,9 +17,14 @@ public sealed interface EvalResult {
record Error(Throwable cause) implements EvalResult {}
record Batch(List<Firing> firings) implements EvalResult {
record Batch(List<Firing> firings, Map<String, Object> nextEvalState) implements EvalResult {
public Batch {
firings = firings == null ? List.of() : List.copyOf(firings);
nextEvalState = nextEvalState == null ? Map.of() : Map.copyOf(nextEvalState);
}
/** Convenience: a Batch with no cursor update (first-run empty, or no matches). */
public static Batch empty() {
return new Batch(List.of(), Map.of());
}
}
}

View File

@@ -116,7 +116,7 @@ public class ExchangeMatchEvaluator implements ConditionEvaluator<ExchangeMatchC
SearchResult<ExecutionSummary> result = searchIndex.search(req);
List<ExecutionSummary> matches = result.data();
if (matches.isEmpty()) return new EvalResult.Batch(List.of());
if (matches.isEmpty()) return new EvalResult.Batch(List.of(), Map.of());
// Find the latest startTime across all matches — becomes the next cursor
Instant latestTs = matches.stream()
@@ -144,6 +144,6 @@ public class ExchangeMatchEvaluator implements ConditionEvaluator<ExchangeMatchC
firings.add(new EvalResult.Firing(1.0, null, ctx2));
}
return new EvalResult.Batch(firings);
return new EvalResult.Batch(firings, Map.of());
}
}