fix(lambda): leave out the children of a durable context closed without ReplayChildren (#8248)

Floci listed every operation in the invocation event and in
GetDurableExecutionState. AWS leaves out the operations under a child
context closed without ReplayChildren=true, and everything below them.
Both now use one filtered view, and a context closed without
ContextOptions shows ReplayChildren: false. The checkpoint answer is
unchanged.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-13 22:37:23 -04:00
1 parent f0de926e02
commit 4313fc5fac
8 files changed
+190 -5

No files matched your search

+3
View File
@@ -238,6 +238,9 @@ other than the `{Status, Result, Error}` envelope fails its execution with
1, 2, 4 and 8 seconds, and then fails the execution with its error. AWS does the same over a few
minutes.
The operations under a child context closed without `ReplayChildren=true` are left out of the
invocation event and `GetDurableExecutionState`, as the API reference describes.
A callback (`createCallback`, `waitForCallback`) gets a callback id that the
`SendDurableExecutionCallback*` APIs complete. Its `TimeoutSeconds` and `HeartbeatTimeoutSeconds`
fail it with `Callback.Timeout` or `Callback.Heartbeat`, and each heartbeat restarts the heartbeat
@@ -270,9 +270,7 @@ final class DurableCheckpointApplier {
existing.setStatus(succeeded ? DurableOperationStatus.SUCCEEDED : DurableOperationStatus.FAILED);
existing.setResult(succeeded ? update.payload() : null);
existing.setError(succeeded ? null : update.error());
if (update.replayChildren() != null) {
existing.setReplayChildren(update.replayChildren());
}
existing.setReplayChildren(Boolean.TRUE.equals(update.replayChildren()));
existing.setEndTimestamp(now);
touch(existing);
event(existing, succeeded ? "ContextSucceeded" : "ContextFailed",
@@ -305,7 +305,7 @@ public class DurableExecutionService implements Resettable {
List<DurableOperation> operations;
synchronized (lockFor(arn)) {
DurableExecution execution = loadWithCurrentToken(arn, checkpointToken);
operations = new ArrayList<>(execution.getOperations().values());
operations = execution.replayedOperations();
}
List<Cursored<DurableOperation>> indexed = new ArrayList<>(operations.size());
for (int i = 0; i < operations.size(); i++) {
@@ -60,7 +60,7 @@ public final class DurableWire {
event.put("CheckpointToken", checkpointToken);
ObjectNode state = event.putObject("InitialExecutionState");
ArrayNode operations = state.putArray("Operations");
for (DurableOperation operation : execution.getOperations().values()) {
for (DurableOperation operation : execution.replayedOperations()) {
operations.add(operation(operation, true));
}
state.put("NextMarker", "");
@@ -6,8 +6,10 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
/**
* A durable execution with its checkpointed operations and history. One stored object per
@@ -66,6 +68,29 @@ public class DurableExecution {
return status.isClosed();
}
/** AWS leaves out the operations under a closed CONTEXT that did not ask to replay its children. */
public List<DurableOperation> replayedOperations() {
List<DurableOperation> replayed = new ArrayList<>(operations.size());
Set<String> leftOut = new HashSet<>();
for (DurableOperation operation : operations.values()) {
String parentId = operation.getParentId();
if (parentId != null) {
DurableOperation parent = operations.get(parentId);
boolean parentClosedWithoutReplay = parent != null
&& parent.getType() == DurableOperationType.CONTEXT
&& (parent.getStatus() == DurableOperationStatus.SUCCEEDED
|| parent.getStatus() == DurableOperationStatus.FAILED)
&& !Boolean.TRUE.equals(parent.getReplayChildren());
if (leftOut.contains(parentId) || parentClosedWithoutReplay) {
leftOut.add(operation.getId());
continue;
}
}
replayed.add(operation);
}
return replayed;
}
@JsonIgnore
public boolean hasUnseenChanges() {
return changeSequence > seenSequence;
@@ -15,6 +15,7 @@ import java.util.Map;
import java.util.function.Function;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
/** The batch rules of CheckpointDurableExecution, and that a rejected batch changes nothing. */
@@ -283,6 +284,23 @@ class DurableCheckpointApplierTest {
Map.of("ContextFailedDetails", Map.of("Error", empty))), closes);
}
@Test
void closingAContextStoresReplayChildrenAndDefaultsToFalse() {
DurableExecution execution = execution();
DurableCheckpointApplier.apply(execution, List.of(contextStart("c1"), contextStart("c2"),
contextStart("c3")), NOW, REACHABLE);
assertNull(execution.getOperations().get("c1").getReplayChildren());
DurableCheckpointApplier.apply(execution, List.of(
update("c1", null, DurableOperationType.CONTEXT, DurableOperationAction.SUCCEED, null),
contextClose("c2", DurableOperationAction.SUCCEED, true),
contextClose("c3", DurableOperationAction.FAIL, false)), NOW, REACHABLE);
assertEquals(false, execution.getOperations().get("c1").getReplayChildren());
assertEquals(true, execution.getOperations().get("c2").getReplayChildren());
assertEquals(false, execution.getOperations().get("c3").getReplayChildren());
}
@Test
void aRejectedBatchLeavesTheExecutionUntouched() {
DurableExecution execution = execution();
@@ -332,6 +350,12 @@ class DurableCheckpointApplierTest {
return update(id, null, DurableOperationType.CONTEXT, DurableOperationAction.START, null);
}
private static DurableOperationUpdate contextClose(String id, DurableOperationAction action,
Boolean replayChildren) {
return new DurableOperationUpdate(id, null, null, DurableOperationType.CONTEXT, null, action, null, null, null,
null, replayChildren, null, null, null, null, null);
}
private static DurableOperationUpdate waitStart(String id) {
return new DurableOperationUpdate(id, null, null, DurableOperationType.WAIT, null, DurableOperationAction.START,
null, null, null, 5, null, null, null, null, null, null);
@@ -231,6 +231,91 @@ class DurableExecutionServiceTest {
.getStatus());
}
@Test
void childrenOfAContextClosedWithoutReplayChildrenAreLeftOutOfTheStateAndTheNextInvocation() {
List<String> state = new ArrayList<>();
List<String> firstPage = new ArrayList<>();
List<String> secondPage = new ArrayList<>();
List<String> answer = new ArrayList<>();
List<JsonNode> closedWire = new ArrayList<>();
invoker.script(event -> {
String arn = event.get("DurableExecutionArn").asText();
List<DurableOperationUpdate> starts = new ArrayList<>();
for (int i = 1; i <= 8; i++) {
starts.add(contextUpdate("c" + i, null, DurableOperationAction.START, null));
}
starts.add(step("a1", "c1"));
starts.add(contextUpdate("n1", "c1", DurableOperationAction.START, null));
starts.add(step("g1", "n1"));
starts.add(step("a2", "c2"));
starts.add(step("a3", "c3"));
starts.add(step("a4", "c4"));
starts.add(step("a5", "c5"));
starts.add(step("a8", "c8"));
starts.add(contextUpdate("n2", "c6", DurableOperationAction.START, null));
starts.add(step("g2", "n2"));
starts.add(contextUpdate("n3", "c7", DurableOperationAction.START, null));
starts.add(step("g3", "n3"));
String token = checkpoint(event, token(event), starts).checkpointToken();
token = checkpoint(event, token, List.of(
contextUpdate("n1", "c1", DurableOperationAction.SUCCEED, true),
contextUpdate("n2", "c6", DurableOperationAction.SUCCEED, false),
contextUpdate("n3", "c7", DurableOperationAction.SUCCEED, false),
contextUpdate("c1", null, DurableOperationAction.SUCCEED, false),
contextUpdate("c2", null, DurableOperationAction.SUCCEED, true),
contextUpdate("c3", null, DurableOperationAction.SUCCEED, null),
contextUpdate("c4", null, DurableOperationAction.FAIL, false),
contextUpdate("c6", null, DurableOperationAction.SUCCEED, true),
contextUpdate("c8", null, DurableOperationAction.SUCCEED, false))).checkpointToken();
service.getState(arn, token, null, null).operations().forEach(o -> state.add(o.getId()));
DurableExecutionService.StatePage first = service.getState(arn, token, null, 5);
first.operations().forEach(o -> firstPage.add(o.getId()));
service.getState(arn, token, first.nextMarker(), 5).operations().forEach(o -> secondPage.add(o.getId()));
checkpoint(event, token, List.of(waitStart("w1", 1)));
return pending();
});
invoker.script(event -> {
event.get("InitialExecutionState").get("Operations").forEach(o -> answer.add(o.get("Id").asText()));
closedWire.add(operation(event, "c1").get("ContextDetails"));
closedWire.add(operation(event, "c5").get("ContextDetails"));
return succeeded("\"done\"");
});
DurableExecution execution = start("exec-1", "{}", false);
clock.advance(Duration.ofSeconds(2));
service.sweep();
List<String> expected = List.of(execution.getExecutionId(), "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8",
"a2", "a5", "n2", "n3");
assertEquals(expected, state);
List<String> replayed = new ArrayList<>(expected);
replayed.add("w1");
assertEquals(replayed, answer);
assertEquals(expected.subList(0, 5), firstPage);
assertEquals(expected.subList(5, 10), secondPage);
assertEquals(DurableExecutionStatus.SUCCEEDED, service.get(execution.getExecutionArn()).getStatus());
assertEquals("{\"ReplayChildren\":false}", closedWire.get(0).toString());
assertEquals("{}", closedWire.get(1).toString());
}
@Test
void theCheckpointAnswerKeepsTheChildOfAContextClosedInTheSameBatch() {
List<String> answered = new ArrayList<>();
invoker.script(event -> {
String token = checkpoint(event, token(event), List.of(
contextUpdate("c9", null, DurableOperationAction.START, null), step("a9", "c9"))).checkpointToken();
CheckpointResult result = checkpoint(event, token, List.of(
step("a9", "c9", DurableOperationAction.SUCCEED),
contextUpdate("c9", null, DurableOperationAction.SUCCEED, false)));
result.newExecutionState().forEach(o -> answered.add(o.getId()));
return succeeded("\"x\"");
});
start("exec-1", "{}", true);
assertEquals(List.of("c9", "a9"), answered);
}
@Test
void staleTokensAndTokensOfClosedExecutionsAreRejected() {
invoker.script(event -> {
@@ -1063,6 +1148,21 @@ class DurableExecutionServiceTest {
null, null, null, null, null, null, null, null);
}
private static DurableOperationUpdate step(String id, String parentId) {
return step(id, parentId, DurableOperationAction.START);
}
private static DurableOperationUpdate step(String id, String parentId, DurableOperationAction action) {
return new DurableOperationUpdate(id, parentId, null, DurableOperationType.STEP, "Step", action, null, null,
null, null, null, null, null, null, null, null);
}
private static DurableOperationUpdate contextUpdate(String id, String parentId, DurableOperationAction action,
Boolean replayChildren) {
return new DurableOperationUpdate(id, parentId, null, DurableOperationType.CONTEXT, "Context", action, null,
null, null, null, replayChildren, null, null, null, null, null);
}
private static DurableOperationUpdate stepRetry(String id, int delaySeconds, DurableErrorObject error) {
return new DurableOperationUpdate(id, null, null, DurableOperationType.STEP, "Step",
DurableOperationAction.RETRY, null, error, delaySeconds, null, null, null, null, null, null, null);
@@ -314,6 +314,41 @@ class LambdaDurableProtocolIntegrationTest {
.body("Events[4].ContextSucceededDetails.Result", equalTo(Map.of("Truncated", true)));
}
@Test
void aContextClosedWithoutReplayChildrenLeavesItsChildrenOutOfTheState() throws Exception {
CompletableFuture<Response> invoke = CompletableFuture.supplyAsync(() -> given()
.header("X-Amz-Durable-Execution-Name", "replay-children-1")
.body("{}")
.post(LAMBDA + "/functions/" + FUNCTION + ":$LATEST/invocations"));
Invocation invocation = invoker.awaitInvocation(Duration.ofSeconds(30));
JsonNode event = MAPPER.readTree(invocation.payload());
String arn = event.get("DurableExecutionArn").asText();
String token = checkpoint(arn, event.get("CheckpointToken").asText(), """
{"Id": "c1", "Type": "CONTEXT", "SubType": "RunInChildContext", "Action": "START"},
{"Id": "s1", "ParentId": "c1", "Type": "STEP", "SubType": "Step", "Action": "START"}
""");
token = checkpoint(arn, token, """
{"Id": "c1", "Type": "CONTEXT", "SubType": "RunInChildContext", "Action": "SUCCEED"}
""");
given()
.urlEncodingEnabled(false)
.when()
.get(DURABLE + "/durable-executions/" + arn + "/state?CheckpointToken=" + token)
.then()
.statusCode(200)
.body("Operations.Id", equalTo(List.of(event.get("InitialExecutionState").get("Operations").get(0)
.get("Id").asText(), "c1")))
.body("Operations[1].ContextDetails.ReplayChildren", equalTo(false));
checkpoint(arn, token, """
{"Id": "x", "Type": "EXECUTION", "Action": "SUCCEED", "Payload": "\\"done\\""}
""");
invocation.response().complete(handlerResponse("{\"Status\": \"SUCCEEDED\"}"));
assertEquals(200, invoke.get(30, TimeUnit.SECONDS).statusCode());
}
@Test
void anAsynchronousInvokeIsIdempotentByNameAndCanBeStopped() throws Exception {
Response accepted = given()