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

@@ -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()