Add a static cache of what paths can be modalized. Use preprocess rather than hook_menu_local_tasks_alter().