From f0de926e021c38a5111a36aac5e4baec34335a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TATSUNO=20=E2=80=9CTaz=E2=80=9D=20Yasuhiro?= Date: Sat, 14 Nov 2026 11:33:13 +0900 Subject: [PATCH] fix(lambda): accept a durable update without ParentId and reword its consistency errors (#8249) * fix(lambda): accept a durable update without ParentId and word its consistency errors like AWS --- .../durable/DurableCheckpointApplier.java | 21 +++-- .../durable/DurableCheckpointApplierTest.java | 86 ++++++++++++++++++- 2 files changed, 97 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/floci/aws/services/lambda/durable/DurableCheckpointApplier.java b/src/main/java/io/floci/aws/services/lambda/durable/DurableCheckpointApplier.java index d5c033ad22..9b0a1deb7d 100644 --- a/src/main/java/io/floci/aws/services/lambda/durable/DurableCheckpointApplier.java +++ b/src/main/java/io/floci/aws/services/lambda/durable/DurableCheckpointApplier.java @@ -200,15 +200,15 @@ final class DurableCheckpointApplier { throw invalid("Invalid operation id."); } DurableOperation existing = operations.get(update.id()); - if (existing != null) { - requireConsistent(existing, update); - } if (update.parentId() != null) { DurableOperation parent = operations.get(update.parentId()); if (parent == null || parent.getType() != DurableOperationType.CONTEXT) { throw invalid("Invalid parent operation id."); } } + if (existing != null) { + requireConsistent(existing, update); + } requireErrorSize(update); if (update.type() == DurableOperationType.CHAINED_INVOKE) { if (utf8Length(update.payload()) > MAX_CHAINED_INVOKE_PAYLOAD_BYTES) { @@ -495,19 +495,24 @@ final class DurableCheckpointApplier { private static void requireConsistent(DurableOperation existing, DurableOperationUpdate update) { if (existing.getType() != update.type()) { - throw invalid("Inconsistent operation type."); + throw inconsistent("Type"); } if (update.subType() != null && !Objects.equals(existing.getSubType(), update.subType())) { - throw invalid("Inconsistent operation subtype."); + throw inconsistent("SubType"); } if (update.name() != null && !Objects.equals(existing.getName(), update.name())) { - throw invalid("Inconsistent operation name."); + throw inconsistent("Name"); } - if (!Objects.equals(existing.getParentId(), update.parentId())) { - throw invalid("Inconsistent parent operation id."); + if (update.parentId() != null && !Objects.equals(existing.getParentId(), update.parentId())) { + throw inconsistent("ParentId"); } } + private static AwsException inconsistent(String field) { + return invalid(field + " value in OperationUpdate is inconsistent with existing operation. " + + "Check for non-determinism."); + } + private static Map resultOrError(DurableOperation operation, boolean failed) { Map details = new LinkedHashMap<>(); if (failed) { diff --git a/src/test/java/io/floci/aws/services/lambda/durable/DurableCheckpointApplierTest.java b/src/test/java/io/floci/aws/services/lambda/durable/DurableCheckpointApplierTest.java index 5a46640c8b..a82c36dcc5 100644 --- a/src/test/java/io/floci/aws/services/lambda/durable/DurableCheckpointApplierTest.java +++ b/src/test/java/io/floci/aws/services/lambda/durable/DurableCheckpointApplierTest.java @@ -24,6 +24,15 @@ class DurableCheckpointApplierTest { private static final Function REACHABLE = functionName -> null; private static final String EXECUTION_ARN = "arn:aws:lambda:us-east-1:000000000000:function:fn:1/durable-execution/exec/exec-id"; + private static final String INVALID_PARENT_MESSAGE = "Invalid parent operation id."; + private static final String TYPE_MESSAGE = + "Type value in OperationUpdate is inconsistent with existing operation. Check for non-determinism."; + private static final String SUB_TYPE_MESSAGE = + "SubType value in OperationUpdate is inconsistent with existing operation. Check for non-determinism."; + private static final String NAME_MESSAGE = + "Name value in OperationUpdate is inconsistent with existing operation. Check for non-determinism."; + private static final String PARENT_ID_MESSAGE = + "ParentId value in OperationUpdate is inconsistent with existing operation. Check for non-determinism."; @Test void executionUpdateMustBeTheOnlyOneAndTheLast() { @@ -67,11 +76,78 @@ class DurableCheckpointApplierTest { assertRejected(List.of(stepStart("s1", "missing")), "Invalid parent operation id."); DurableExecution execution = execution(); DurableCheckpointApplier.apply(execution, List.of(stepStart("s1", null)), NOW, REACHABLE); - assertEquals("Inconsistent operation type.", reject(execution, List.of(waitStart("s1")))); - assertEquals("Inconsistent parent operation id.", reject(execution, List.of(stepStart("ctx", null), + assertEquals(TYPE_MESSAGE, reject(execution, List.of(waitStart("s1")))); + assertEquals(PARENT_ID_MESSAGE, reject(execution, List.of(contextStart("ctx"), update("s1", "ctx", DurableOperationType.STEP, DurableOperationAction.SUCCEED, "1")))); } + @Test + void anExistingOperationClosedWithoutParentIdKeepsItsParent() { + DurableExecution execution = execution(); + DurableCheckpointApplier.apply(execution, List.of(contextStart("ctx"), stepStart("s1", "ctx"), + typed("c1", "ctx", null, DurableOperationType.CONTEXT, "Parallel", DurableOperationAction.START)), + NOW, REACHABLE); + DurableCheckpointApplier.apply(execution, List.of( + update("s1", null, DurableOperationType.STEP, DurableOperationAction.SUCCEED, "1"), + update("c1", null, DurableOperationType.CONTEXT, DurableOperationAction.SUCCEED, "2")), NOW, REACHABLE); + assertEquals(DurableOperationStatus.SUCCEEDED, execution.getOperations().get("s1").getStatus()); + assertEquals("ctx", execution.getOperations().get("s1").getParentId()); + assertEquals(DurableOperationStatus.SUCCEEDED, execution.getOperations().get("c1").getStatus()); + assertEquals("ctx", execution.getOperations().get("c1").getParentId()); + } + + @Test + void eachInconsistentFieldHasItsOwnMessage() { + DurableExecution execution = execution(); + DurableCheckpointApplier.apply(execution, List.of(typed("s1", null, "n", DurableOperationType.STEP, "Step", + DurableOperationAction.START)), NOW, REACHABLE); + assertEquals(TYPE_MESSAGE, reject(execution, List.of(typed("s1", null, "n", DurableOperationType.WAIT, "Step", + DurableOperationAction.SUCCEED)))); + assertEquals(SUB_TYPE_MESSAGE, reject(execution, List.of(typed("s1", null, "n", DurableOperationType.STEP, + "Other", DurableOperationAction.SUCCEED)))); + assertEquals(NAME_MESSAGE, reject(execution, List.of(typed("s1", null, "other", DurableOperationType.STEP, + "Step", DurableOperationAction.SUCCEED)))); + } + + @Test + void inconsistentFieldsAreReportedInTypeSubTypeNameParentIdOrder() { + DurableExecution execution = execution(); + DurableCheckpointApplier.apply(execution, List.of(contextStart("ctx"), contextStart("ctx2"), + typed("s1", "ctx", "n", DurableOperationType.STEP, "Step", DurableOperationAction.START)), + NOW, REACHABLE); + assertEquals(NAME_MESSAGE, reject(execution, List.of(typed("s1", "ctx2", "other", + DurableOperationType.STEP, "Step", DurableOperationAction.SUCCEED)))); + assertEquals(TYPE_MESSAGE, reject(execution, List.of(typed("s1", "ctx2", "n", DurableOperationType.WAIT, + "Step", DurableOperationAction.SUCCEED)))); + assertEquals(SUB_TYPE_MESSAGE, reject(execution, List.of(typed("s1", "ctx2", "n", DurableOperationType.STEP, + "Other", DurableOperationAction.SUCCEED)))); + assertEquals(SUB_TYPE_MESSAGE, reject(execution, List.of(typed("s1", "ctx", "other", + DurableOperationType.STEP, "Other", DurableOperationAction.SUCCEED)))); + assertEquals(TYPE_MESSAGE, reject(execution, List.of(typed("s1", null, "n", DurableOperationType.WAIT, null, + DurableOperationAction.SUCCEED)))); + assertEquals(PARENT_ID_MESSAGE, reject(execution, List.of(update("s1", "ctx2", DurableOperationType.STEP, + DurableOperationAction.SUCCEED, "1")))); + } + + @Test + void aTopLevelOperationClosedWithAContextParentIsInconsistent() { + DurableExecution execution = execution(); + DurableCheckpointApplier.apply(execution, List.of(contextStart("ctx"), stepStart("s1", null)), NOW, REACHABLE); + assertEquals(PARENT_ID_MESSAGE, reject(execution, List.of(update("s1", "ctx", DurableOperationType.STEP, + DurableOperationAction.SUCCEED, "1")))); + } + + @Test + void theParentIsCheckedBeforeTheOtherFieldsOfAnExistingOperation() { + DurableExecution execution = execution(); + DurableCheckpointApplier.apply(execution, List.of(contextStart("ctx"), stepStart("s1", "ctx"), + stepStart("s2", "ctx")), NOW, REACHABLE); + assertEquals(INVALID_PARENT_MESSAGE, reject(execution, List.of(update("s1", "missing", + DurableOperationType.WAIT, DurableOperationAction.SUCCEED, null)))); + assertEquals(INVALID_PARENT_MESSAGE, reject(execution, List.of(update("s1", "s2", + DurableOperationType.WAIT, DurableOperationAction.SUCCEED, null)))); + } + @Test void stepTransitionsAreGuarded() { DurableExecution execution = execution(); @@ -284,4 +360,10 @@ class DurableCheckpointApplierTest { return new DurableOperationUpdate(id, parentId, null, type, null, action, payload, null, null, null, null, null, null, null, null, null); } + + private static DurableOperationUpdate typed(String id, String parentId, String name, DurableOperationType type, + String subType, DurableOperationAction action) { + return new DurableOperationUpdate(id, parentId, name, type, subType, action, null, null, null, null, null, + null, null, null, null, null); + } }