Skip to content

bug: Callback pattern doesn't work correctly #12642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
alisherzhaken opened this issue May 19, 2025 · 2 comments
Open
1 task done

bug: Callback pattern doesn't work correctly #12642

alisherzhaken opened this issue May 19, 2025 · 2 comments
Assignees
Labels
aws:stepfunctions AWS Step Functions status: backlog Triaged but not yet being worked on type: bug Bug report

Comments

@alisherzhaken
Copy link

alisherzhaken commented May 19, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I implemented two state machines where one state machine (parent) invokes another state machine (child), and I have utilised a callback pattern where Child State Machine will perform sendTaskHeartbeat every 30 seconds. Parent State Machine has a heartbeat timeout of 40 seconds.

The problem lies in sendTaskHeartbeat. It seems like the callback doesn't make it to the parent state machine, which causes the Parent Task to time out after 40 seconds, and the sendTaskHeartbeat step in Child State Machine fails with Sfn.InvalidTokenException.

Here are the definitions.

# Parent state machine

{
  "StartAt": "StartChild",
  "States": {
    "StartChild": {
      "Type": "Task",
      "Resource": "arn:aws:states:::states:startExecution.sync:2",
      "HeartbeatSeconds": 40,
      "Arguments": {
        "Input": {
          "TaskToken": "{% $states.context.Task.Token %}",
          "count": 0
        },
        "StateMachineArn": "arn:aws:states:us-east-1:000000000000:stateMachine:ChildStateMachine"
      },
      "End": true
    }
  },
  "QueryLanguage": "JSONata"
}

and

# Child State Machine

{
  "StartAt": "Heartbeat",
  "States": {
    "Heartbeat": {
      "Type": "Task",
      "Resource": "arn:aws:states:::aws-sdk:sfn:sendTaskHeartbeat",
      "Arguments": {
        "TaskToken": "{% $states.context.Execution.Input.TaskToken %}"
      },
      "Output": "{% $states.input %}",
      "Next": "IncrementPoint"
    },
    "IncrementPoint": {
      "Type": "Pass",
      "Output": {
        "count": "{% $states.input.count + 1 %}"
      },
      "Next": "Delay"
    },
    "Delay": {
      "Type": "Wait",
      "Seconds": 10,
      "Next": "CheckEnd"
    },
    "CheckEnd": {
      "Type": "Choice",
      "Choices": [
        {
          "Condition": "{% $states.input.count = 3 or $states.input.count = 6 or $states.input.count = 9%}",
          "Next": "Heartbeat"
        },
        {
          "Condition": "{% $states.input.count < 10 %}",
          "Next": "IncrementPoint"
        }
      ],
      "Default": "Finish"
    },
    "Finish": {
      "Type": "Task",
      "Resource": "arn:aws:states:::aws-sdk:sfn:sendTaskSuccess",
      "Arguments": {
        "TaskToken": "{% $states.context.Execution.Input.TaskToken %}",
        "Output": "{% $states.input %}"
      },
      "End": true
    }
  },
  "QueryLanguage": "JSONata"
}

Expected Behavior

It is expected to see sendTaskHeartbeat to be successful such that the execution of both Parent and Child State Machine would continue and end up successful instead of timing out.

How are you starting LocalStack?

Using localstack start

Steps To Reproduce

How are you starting localstack (e.g., bin/localstack command, arguments, or docker-compose.yml)

localstack start

Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)

awslocal 
awslocal iam create-role --role-name AllPurpose --assume-role-policy-document '{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "states.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}'

awslocal iam create-policy --policy-name AllPurpose \
--policy-document '{
     "Version": "2012-10-17",
     "Statement": [
          {
             "Action": "*",
             "Resource": "*",
             "Effect": "Allow"
          }
      ]
   }'

awslocal iam attach-role-policy --role-name AllPurpose --policy-arn arn:aws:iam::000000000000:policy/AllPurpose

awslocal stepfunctions create-state-machine --definition file://parent-state-machine.json --role-arn arn:aws:iam::000000000000:role/AllPurpose --name ParentStateMachine

awslocal stepfunctions create-state-machine --definition file://child-state-machine.json --role-arn arn:aws:iam::000000000000:role/AllPurpose --name ChildStateMachine

awslocal stepfunctions start-execution --state-machine-arn arn:aws:states:us-east-1:000000000000:stateMachine:ParentStateMachine

Environment

- OS: Ubuntu 25.04
- LocalStack:
  LocalStack version: 4.4.0
  LocalStack Docker image sha:
  LocalStack build date: 2025-05-08
  LocalStack build git hash: 21f6e5fb2

Anything else?

No response

@alisherzhaken alisherzhaken added type: bug Bug report status: triage needed Requires evaluation by maintainers labels May 19, 2025
@localstack-bot
Copy link
Collaborator

Welcome to LocalStack! Thanks for reporting your first issue and our team will be working towards fixing the issue for you or reach out for more background information. We recommend joining our Slack Community for real-time help and drop a message to LocalStack Support if you are a licensed user! If you are willing to contribute towards fixing this issue, please have a look at our contributing guidelines.

@MEPalma MEPalma self-assigned this May 19, 2025
@ryan-berke ryan-berke added aws:stepfunctions AWS Step Functions status: backlog Triaged but not yet being worked on and removed status: triage needed Requires evaluation by maintainers labels May 19, 2025
@alisherzhaken
Copy link
Author

Hi folks, is it possible to prioritise this, or provide an alternative solution?
I understand that I can set HeartbeatSeconds to some large value , but I'd like to avoid that because when Child SM gets stuck, I wouldn't notice that in Parent SM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:stepfunctions AWS Step Functions status: backlog Triaged but not yet being worked on type: bug Bug report
Projects
None yet
Development

No branches or pull requests

4 participants