Wired failure on step.apply(doc) on same set of steps

I found out the reason. Seem there is a mergeSteps function being run when saving to the mongo. And the merged steps are invalid when replay. After removing that, the problem is solved.

btw, if we really want to merge the steps before saving into mongo in order to reduce the number of step. Any suggestion on how to do that?

input
{
    "payload": [
        {
            "stepType": "replace",
            "from": 69,
            "to": 70
        },
        {
            "stepType": "replace",
            "from": 69,
            "to": 70
        },
        {
            "stepType": "replace",
            "from": 68,
            "to": 71,
            "slice": {
                "content": [
                    {
                        "type": "text",
                        "text": " "
                    }
                ]
            }
        },
        {
            "stepType": "replace",
            "from": 69,
            "to": 71,
            "structure": true
        },
        {
            "stepType": "replace",
            "from": 69,
            "to": 71,
            "structure": true
        }
    ]
}

merged
{
    "payload": [
        {
            "stepType": "replace",
            "from": 69,
            "to": 71
        },
        {
            "stepType": "replace",
            "from": 68,
            "to": 71,
            "slice": {
                "content": [
                    {
                        "type": "text",
                        "text": " "
                    }
                ]
            }
        },
        {
            "stepType": "replace",
            "from": 69,
            "to": 73,
            "structure": true
        }
    ]
}

Is that because of the structure?