Drive train making weird initial turn at beginning

I am coaching kids on the auton. Kids do almost all their coding stuff and I provide occasional help on some compiling issues or some debugging ideas.

Now we are facing a weird problem, the drive train will make an unexpected turn first when being asked to drive straight, and this only happens after a PID controlled turn.

The logic can be simplified as following:

// First do a PID controlled turn:
while (notDone) {
  pidOutput = calculatePID(...);
  // motor group is of type pros::MotorGroup
  rightMotorGroup.move_voltage(pidOutput);
  leftMotorGroup.move_voltage(-pidOutout);
  pros::delay(x milliseconds);
}
// turning done
rightMotorGroup.move_voltage(0);
leftMotorGroup.move_voltage(0);
// brake mode is set to: pros::v5::MotorBrake::hold using
// pros::MotorGroup.set_brake_mode_all(...)
rightMotorGroup.brake();
leftMotorGroup.brake();

// If the code stops here (i.e. commenting out the code after this line), 
// the turn finishes and points to the expected direction

// If you execute the same code below without doing a turn first,
// the drive base moves straight as expected. But when placed after the
// above PID turn, the robot will consistently swing to left for a very noticeable
// degree, and then drive straight.

rightMotorGroup.move_velocity(v);
leftMotorGroup.move_velocity(v);

The code looks perfect fine to kids and me. Kids also asked their club’s coding coach and they have no clue either.

Kids also tried to add a brief sleep after the PID turn, to see if it is because of the motors need to “settle down”. They also tried to change the value of v. The behavior remains the same.

Does anyone have any ideas?

Thank you very much!