Salvaged from #40429; re-verified on main, tightened, tested. Co-authored-by: jimjsong <jimjsong@users.noreply.github.com>