Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(stepfunctions): do not retry or catch a task timeout with States.TaskFailed (#1993)
mishukdutta-czd03b4d9d2865
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex dbaa58a2..08a72f2a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,9 @@ Versioning follows [Semantic Versioning](https://semver.org/).## [Unreleased]+### Fixed++- **Step Functions — `States.TaskFailed` no longer matches `States.Timeout`** — a `Retry` or `Catch` on `States.TaskFailed` also matched a timeout, so a state machine retried or caught a timeout where AWS does not. `States.TaskFailed` now matches every error except `States.Timeout`, as the Step Functions error handling guide describes.### Added- **OpenSearch Serverless — collections, security and access policies, and a proxied data plane** — `CreateCollection`, `BatchGetCollection`, `ListCollections`, `UpdateCollection`, `DeleteCollection`, `Create`/`Get`/`Update`/`Delete`/`ListSecurityPolicy` (`encryption`, `network`), `Create`/`Get`/`Update`/`Delete`/`ListAccessPolicy` (`data`), `GetPoliciesStats` and `TagResource` / `UntagResource` / `ListTagsForResource`, enough for Terraform's `aws_opensearchserverless_collection`, `_security_policy` and `_access_policy` to apply, plan clean and destroy. A collection needs a matching encryption policy (exact name or `prefix*`, most specific wins) unless `encryptionConfig` is given, and answers `kmsKeyArn: auto` for an AWS-owned key; policy documents are validated, a resource pattern may sit in only one encryption policy, a data policy refuses empty or wildcard principals, and an update must name the current `policyVersion` (`base64("<lastModifiedDate>_<n>")`). Its `collectionEndpoint`, `http://<id>.<region>.aoss.<host>:<port>`, is served through the gateway and requests must be SigV4-signed for `aoss` and carry `x-amz-content-sha256` (403 otherwise); with `OPENSEARCH_DATAPLANE=1` it is backed by its own `opensearchproject/opensearch` container, persisted on a named Docker volume across a restart under `PERSIST_STATE` and removed on `DeleteCollection`, otherwise it answers 503. APIs AOSS does not support answer 404, as `_refresh`, `_cluster/*` and scroll do on AWS, and `TIMESERIES` collections refuse custom document ids and updates. Data access and network policies are stored, not enforced. Checked against the botocore model and the OpenSearch Serverless developer guide and API reference.diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.pyindex 2b20adad..3250998f 100644--- a/ministack/services/stepfunctions.py+++ b/ministack/services/stepfunctions.py@@ -3021,21 +3021,30 @@ def _resolve_ctx_path(path, ctx):# Retry / Catch helpers# ===================================================================+def _error_matches(error_equals, error):+ """Return True when a retrier's or catcher's ErrorEquals list matches this error name.++ States.TaskFailed matches every error name except States.Timeout, as the+ AWS Step Functions error handling guide describes.+ """+ if "States.ALL" in error_equals or error in error_equals:+ return True+ return "States.TaskFailed" in error_equals and error != "States.Timeout"++def _find_matching_retrier(retriers, error, retry_counts):for idx, retrier in enumerate(retriers):- equals = retrier.get("ErrorEquals", [])max_attempts = retrier.get("MaxAttempts", 3)if retry_counts.get(idx, 0) >= max_attempts:continue- if "States.ALL" in equals or "States.TaskFailed" in equals or error in equals:+ if _error_matches(retrier.get("ErrorEquals", []), error):return retrier, idxreturn None, -1def _find_matching_catcher(catchers, error):for catcher in catchers:- equals = catcher.get("ErrorEquals", [])- if "States.ALL" in equals or "States.TaskFailed" in equals or error in equals:+ if _error_matches(catcher.get("ErrorEquals", []), error):return catcherreturn Nonediff --git a/tests/test_stepfunctions.py b/tests/test_stepfunctions.pyindex d1a7023f..76c3d4b5 100644--- a/tests/test_stepfunctions.py+++ b/tests/test_stepfunctions.py@@ -3425,6 +3425,41 @@ def test_sfn_integration_sqs_send_message_wait_for_task_token(sfn, sqs):desc = _wait_sfn(sfn, ex["executionArn"])assert desc["status"] == "SUCCEEDED"++def test_sfn_task_failed_does_not_match_states_timeout(sfn, sqs):+ """States.TaskFailed matches every error except States.Timeout, in Retry and in Catch."""+ queue_url = sqs.create_queue(QueueName="sfn-taskfailed-timeout")["QueueUrl"]+ definition = json.dumps({+ "StartAt": "Wait",+ "States": {+ "Wait": {+ "Type": "Task",+ "Resource": "arn:aws:states:::sqs:sendMessage.waitForTaskToken",+ "Parameters": {"QueueUrl": queue_url, "MessageBody": {"token.$": "$$.Task.Token"}},+ "TimeoutSeconds": 1,+ "Retry": [{"ErrorEquals": ["States.TaskFailed"], "IntervalSeconds": 1, "MaxAttempts": 1}],+ "Catch": [+ {"ErrorEquals": ["States.TaskFailed"], "Next": "CaughtAsTaskFailed"},+ {"ErrorEquals": ["States.Timeout"], "Next": "CaughtAsTimeout"},+ ],+ "End": True,+ },+ "CaughtAsTaskFailed": {"Type": "Pass", "Result": "task-failed", "End": True},+ "CaughtAsTimeout": {"Type": "Pass", "Result": "timeout", "End": True},+ },+ })+ sm = sfn.create_state_machine(+ name="sfn-taskfailed-timeout", definition=definition, roleArn="arn:aws:iam::000000000000:role/R",+ )+ ex = sfn.start_execution(stateMachineArn=sm["stateMachineArn"], input="{}")++ desc = _wait_sfn(sfn, ex["executionArn"])+ assert desc["status"] == "SUCCEEDED"+ assert json.loads(desc["output"]) == "timeout"+ events = sfn.get_execution_history(executionArn=ex["executionArn"])["events"]+ assert [e["type"] for e in events].count("TaskScheduled") == 1++def test_sfn_integration_lambda_invoke_wait_for_task_token(sfn, lam):"""lambda:invoke.waitForTaskToken must deliver the *unwrapped* Payload tothe handler, exactly like the synchronous lambda:invoke path.