refactor: centralize close-flow logic into shared createCloseEntityHandler factory
#25628
+356
−460
createCloseEntityHandler factory
#25628