It is a nice challenge how to rewrite such a system. One way would be to build a parallel system, identify all inputs and duplicate them to the parallel solution and then compare the outputs; in case of discrepancies fix the erroneous system. Once the systems produce same results (or once the new system produces better results than the old one) you just switch the systems.
The rewrite doesn't have to be complete; it can (should) be done in pieces of course.
The big issues is duplicating the system while it is still morphing in production for all the edge cases, it often feels like trying to paint a moving bus.
The rewrite doesn't have to be complete; it can (should) be done in pieces of course.