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
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-13 22:33:13 -04:00
1 parent 55a7d95146
commit f0de926e02
2 files changed
+97 -10

No files matched your search

@@ -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<String, Object> resultOrError(DurableOperation operation, boolean failed) {
Map<String, Object> details = new LinkedHashMap<>();
if (failed) {
@@ -24,6 +24,15 @@ class DurableCheckpointApplierTest {
private static final Function<String, AwsException> 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);
}
}