From 9b4bd011489a487e2c275f0647e6507c11b3331b Mon Sep 17 00:00:00 2001 From: Jackie Li Date: Mon, 27 Oct 2025 13:04:05 +0000 Subject: [PATCH] Fix --wait-for-child-to-exit not working with overlay windows The issue was a closure problem where the on_child_death callback referenced a responder variable that was created after do_launch() was called. This caused the callback to fail when the child process exited because responder didn't exist in the callback's closure. The fix creates the responder before defining the callback and adds a null check in the callback to ensure it exists before using it. This allows commands like: kitten @ launch --type=overlay --wait-for-child-to-exit bash -c "echo test" to properly wait for the child process to exit and return the exit code. --- kitty/rc/launch.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kitty/rc/launch.py b/kitty/rc/launch.py index 51008358f..b0aa50479 100644 --- a/kitty/rc/launch.py +++ b/kitty/rc/launch.py @@ -132,6 +132,11 @@ instead of the active tab if tabs and tabs[0]: target_tab = tabs[0] + # Create responder before defining callback to avoid closure issue + responder = None + if payload_get('wait_for_child_to_exit') and not payload_get('no_response'): + responder = self.create_async_responder(payload_get, window) + def on_child_death(exit_status: int, exc: Exception | None) -> None: code = os.waitstatus_to_exitcode(exit_status) ans = str(code) @@ -141,7 +146,8 @@ instead of the active tab ans = Signals(-code).name except ValueError: pass - responder.send_data(ans) + if responder is not None: + responder.send_data(ans) w = do_launch( boss, opts, payload_get('args') or [], target_tab=target_tab, rc_from_window=window, base_env=base_env, @@ -152,7 +158,6 @@ instead of the active tab if not payload_get('wait_for_child_to_exit'): return str(0 if w is None else w.id) - responder = self.create_async_responder(payload_get, window) return AsyncResponse() def cancel_async_request(self, boss: 'Boss', window: Window | None, payload_get: PayloadGetType) -> None: