Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

Preserve aborted executions on stop retries (#2094)

Jay Janssen27b5e82da9c0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 30b8cdbc..31c130d3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,8 @@ Versioning follows [Semantic Versioning](https://semver.org/).
### Fixed
+- **Step Functions — retry `StopExecution` after an abort** — an already-aborted execution now returns its original stop date instead of `ValidationException`. A retry preserves the first error/cause and emits no duplicate abort event.
+
- **Gateway**: reject malformed request-body and aws-chunked framing; preserve account-isolated SQS diagnostic aliases and tombstone-aware peeking.
- **SES**: validate source/recipient addresses, content-field presence and configuration sets while accepting present empty content and ASCII/Punycode addresses.
- **Container reaping — one unreadable container no longer stops the sweep** — the boot sweep and the periodic reaper now list containers without inspecting each one, so a container whose inspect fails is skipped instead of leaving every leftover running. Reported by @iot-rocket.
diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.py
index 3a6f6520..025acc59 100644
--- a/ministack/services/stepfunctions.py
+++ b/ministack/services/stepfunctions.py
@@ -699,6 +699,11 @@ def _stop_execution(data):
return error_response_json(
"ExecutionDoesNotExist",
f"Execution {exec_arn} not found", 400)
+ # A client may retry after the abort was applied but its response was lost.
+ # Return the original result without rewriting the cause or emitting a
+ # second ExecutionAborted event.
+ if execution["status"] == "ABORTED":
+ return json_response({"stopDate": execution["stopDate"]})
if execution["status"] != "RUNNING":
return error_response_json(
"ValidationException", "Execution is not running", 400)
diff --git a/tests/test_stepfunctions.py b/tests/test_stepfunctions.py
index 671f234d..f9c13979 100644
--- a/tests/test_stepfunctions.py
+++ b/tests/test_stepfunctions.py
@@ -4616,6 +4616,35 @@ def test_sfn_stop_execution(sfn):
desc = sfn.describe_execution(executionArn=exec_arn)
assert desc["status"] == "ABORTED"
+def test_sfn_stop_execution_retry_preserves_abort(sfn):
+ """A retry after a lost StopExecution response must not rewrite the abort."""
+ name = f"stop-retry-{_uuid_mod.uuid4().hex[:12]}"
+ machine = sfn.create_state_machine(
+ name=name,
+ definition=json.dumps({"StartAt": "Wait", "States": {
+ "Wait": {"Type": "Wait", "Seconds": 3600, "End": True},
+ }}),
+ roleArn=_LAMBDA_ROLE,
+ )["stateMachineArn"]
+ try:
+ execution = sfn.start_execution(stateMachineArn=machine)["executionArn"]
+ first = sfn.stop_execution(executionArn=execution, error="FirstError", cause="first cause")
+ before = sfn.describe_execution(executionArn=execution)
+ before.pop("ResponseMetadata")
+ history = sfn.get_execution_history(executionArn=execution)["events"]
+ retry = sfn.stop_execution(executionArn=execution, error="RetryError", cause="retry cause")
+ assert retry["stopDate"] == first["stopDate"]
+ after = sfn.describe_execution(executionArn=execution)
+ after.pop("ResponseMetadata")
+ assert after == before
+ assert sfn.get_execution_history(executionArn=execution)["events"] == history
+ assert before["status"] == "ABORTED"
+ assert before["error"] == "FirstError"
+ assert before["cause"] == "first cause"
+ finally:
+ sfn.delete_state_machine(stateMachineArn=machine)
+
+
def test_sfn_list_executions_filter(sfn):
"""ListExecutions with statusFilter returns only matching executions."""
definition = json.dumps(