fix(stepfunctions): let Express executions reuse names and type the nested StartExecution refusal (#3059)

StartExecution enforced execution-name uniqueness on Express state machines, but AWS
does not: an Express name is immediately reusable and every start is its own concurrent
execution. Uniqueness, and the 90-day reuse window, applies to Standard workflows only.

- StepFunctionsService.startExecution now gives an Express execution a per-start ARN
  (express:<stateMachine>:<name>:<uuid>) and skips the execution-store collision check, so
  a reused name starts a new, independent execution instead of failing with
  ExecutionAlreadyExists. This also closes a data-loss hazard: same-name Express starts
  would otherwise share one store key, letting a completing execution overwrite another.
  Standard behavior (idempotent same-input replay while RUNNING, ExecutionAlreadyExists
  otherwise) is unchanged.
- AslExecutor.invokeNestedStateMachine now wraps the child StartExecution call so a refusal
  becomes a typed, catchable error (StepFunctions.ExecutionAlreadyExistsException) instead of
  States.Runtime, which no Catch or Retry can match. This mirrors the aws-sdk:sfn:startExecution
  path, which keeps its Sfn. prefix and is unchanged.

Tests cover Express name reuse and a same-name no-clobber regression at the service level;
nested-refusal typed-error, catch, retry and Sfn-vs-StepFunctions prefix cases for bare,
.sync and .sync:2; a wire-level StartExecution integration test; and a .sync/.sync:2 success
guard. The Express idempotency test that pinned the old divergence is removed.

AWS Compatibility: Express StartExecution is non-idempotent and enforces no name uniqueness,
and the express:<stateMachine>:<name>:<id> ARN shape matches the Step Functions resource-ARN
definition; the optimized states:startExecution integration reports StepFunctions.<Code>Exception
for a Standard-child collision. Left as documented deviations, not changed here: the 90-day
Standard name-reuse window is not modeled, and finished Express executions are retained rather
than evicted.
This commit is contained in:
Guilherme Scaranse authored and GitHub committed 2026-09-05 07:37:26 -04:00
1 parent 2d26f93e7d
commit 8a2161ab5e
7 files changed
+466 -17

No files matched your search

@@ -1161,6 +1161,16 @@ public class AslExecutor {
: service + "." + errorCode + "Exception";
}
/**
* The optimized {@code states:startExecution} integration names a refused StartExecution with the
* {@code StepFunctions.} prefix on AWS, e.g. {@code StepFunctions.ExecutionAlreadyExistsException},
* where {@code aws-sdk:sfn:startExecution} uses the {@code Sfn.} prefix. Only the prefix differs;
* the {@code Exception}-suffix rule is the one {@link #sdkExceptionName} already applies.
*/
private static String optimizedSfnErrorName(String errorCode) {
return sdkExceptionName("StepFunctions", errorCode);
}
private static String sdkTimestamp(double epochSeconds) {
return SDK_TIMESTAMP.format(Instant.ofEpochMilli(Math.round(epochSeconds * 1000)));
}
@@ -1372,8 +1382,15 @@ public class AslExecutor {
childName = null;
}
io.github.hectorvent.floci.services.stepfunctions.model.Execution exec =
sfnService.get().startExecution(smArn, childName, childInput, region);
io.github.hectorvent.floci.services.stepfunctions.model.Execution exec;
try {
exec = sfnService.get().startExecution(smArn, childName, childInput, region);
} catch (AwsException e) {
// A StartExecution refusal (e.g. a reused STANDARD name) is a typed task failure a Catch or
// Retry can name, not a States.Runtime that nothing can catch. Same bridge as
// invokeAwsSdkSfnStartExecution, under the prefix this optimized integration reports on AWS.
throw new FailStateException(optimizedSfnErrorName(e.getErrorCode()), e.getMessage());
}
String execArn = exec.getExecutionArn();
if ("".equals(mode)) {
@@ -528,17 +528,26 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
var sm = describeStateMachine(selection.stateMachineArn());
var mockedTestCase = resolveMockedTestCase(sm, selection);
var execName = (name != null && !name.isBlank()) ? name : UUID.randomUUID().toString();
var arn = regionResolver.buildArn("states", region, "execution:" + sm.getName() + ":" + execName);
boolean express = "EXPRESS".equals(sm.getType());
// An EXPRESS name is not unique on AWS: every start is its own execution that runs alongside
// the others, so the ARN (which is also the execution-store key) carries a per-start id after
// the name, under the express: namespace startSyncExecution already uses. A STANDARD execution
// keeps the name-derived ARN whose uniqueness AWS enforces.
var arn = express
? regionResolver.buildArn("states", region,
"express:" + sm.getName() + ":" + execName + ":" + UUID.randomUUID())
: regionResolver.buildArn("states", region, "execution:" + sm.getName() + ":" + execName);
Execution exec;
ExecutionHistory history;
synchronized (executionStartLock) {
Optional<Execution> existing = executionStore.get(arn);
Optional<Execution> existing = express ? Optional.empty() : executionStore.get(arn);
if (existing.isPresent()) {
Execution prior = existing.get();
// AWS idempotency (STANDARD only): the same name + same input while the original is still
// RUNNING returns the original execution as a success; a different input, or a closed
// execution with that name, is a conflict. EXPRESS workflows get no idempotency guarantee.
// execution with that name, is a conflict. An EXPRESS start never reaches this branch:
// its names are reusable and each start got its own ARN above.
if ("STANDARD".equals(sm.getType())
&& "RUNNING".equals(prior.getStatus())
&& Objects.equals(prior.getInput(), input)) {