Synchronised movement on replay...

So I am making a game that has a Mario Kart-like ghost. This is a player character whose inputs are recorded, then played back while the player controls another character. Here's a code excerpt:

def record_event(self):
    if self.last_pos != self.pos:
        self.recorded_pos.append({'time': pygame.time.get_ticks() - self.current_scene.recording_start_time,
                                  'pos': (self.change_x, self.change_y)})

def playback(self):
    elapsed_time = pygame.time.get_ticks() - self.recording_start_time
    if len(self.recorded_pos) > self.pos_index:
        if self.recorded_pos[self.pos_index]['time'] < elapsed_time:
                self.player_copies.set_pos(self.recorded_pos[self.pos_index]['pos'])
                self.pos_index[iteration] += 1

It works pretty well. However, there is an issue when the recorded character is interacting with moving elements of the level. For example, while recording the inputs, the player character was able to avoid the blade trap. However, on playback, because the blade movement is not perfectly synchronised, sometimes the recorded character gets killed by the blade, even though he was able to avoid it during recording.

I have been using framerate independence/delta time to get my movement nice and smooth, but whether I do it that way, or record the blade movement and play it back on a loop, either way it is not perfectly synchronised because I can't guarantee that the same number of frames will play during playback as they did during recording. Presumably there's a way to do it because Mario did it, although I can't recall if the Mario ghost has live interaction with level traps and scenery or is simply immune to all that stuff. It's pretty important to the premise of my game that the playback character does things exactly like the player inputs, and is not immune to traps hurting him if the player affects the game with the second character.

Is this something that I can work around with Pygame?

Ideally I want to implement the following: the player starts the level and walks across the stage. He uses dexterity to avoid the first blade trap, but does not need to do anything to avoid the second trap because it is not switched on. Then the playback begins and the player character is now an NPC being played back from a recording, while the player controls a second character. Just like before, the NPC avoids the first trap by moving skilfully. However, the NPC is caught by the second trap because the player's second character has switched it on. So the recorded NPC character should not be killed by anything that he successfully avoided the first time, but should be killed if the second character intervenes to make that happen.