EKF3 altitude bug with visual odometry

I’m running a 4.2.3 firmware version on multiple drones to test different visual odometry technologies feeding the EKF3 for position and speed in xy while keeping the traditional barometer or down-facing lidar as main altitude source beside IMUs.
Mostly everything is working good but it happened few times that when the drone took off after it was landed or was flying very low (below 50cm from ground) the EKF3 completely got crazy estimating an exponentially decreasing altitude: that causes the drone to fly very fast and indefinitely towards the sky if in althold or loiter mode (the first time that happened I was unprepared and I needed to crash the drone not to loose it completely :pensive:).

Looking into the logs I find out that the EK3 altitude curve was very similar (even if specular) to the log of odometry VISP PZ which apparently also got crazy. But how is it possible that the EKF3 altitude failed in the same way even if all the sensors selected for its estimation (barometer, lidar and IMU) were fine and healthy?

Here is the more interesting log I have in my hand showing the ALT exponentially decreasing curve at the end of the flight when I reduced the quote below 30 cm in loiter mode (as you can see this time I immediately stopped it with my hand and killed it): altitude_bug_with_visual_odometry.bin

I am also facing the same issue, can anyone from the developer team provide help?

@N0L12 thanks for reporting this!
what we need is an EKF replay log to find the issue.
can you possibly reproduce with LOG_REPLAY=1 and LOG_DISARMED=1?
with a replay log we can usually find the issue, and even better we can confirm the fix actually works by replaying the flight through the EKF

@tridge well received. I will keep those 2 parameters enabled hoping the bug to happen again soon…