From 67c205a7bf0240b3407b03896b79f6291d2f8f85 Mon Sep 17 00:00:00 2001 From: khushpal-cipher Date: Tue, 1 Dec 2026 15:43:00 +0530 Subject: [PATCH 1/2] Run the Ctrl+R thread picker in a worker --- src/copper_pilot_cli/copper_app.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/copper_pilot_cli/copper_app.py b/src/copper_pilot_cli/copper_app.py index 33c5af2..5de8b7e 100644 --- a/src/copper_pilot_cli/copper_app.py +++ b/src/copper_pilot_cli/copper_app.py @@ -1528,7 +1528,7 @@ async def _command(self, value: str) -> None: elif command == "/resume" and await self._unfinished_turn() is not None: await self._resume_turn() elif command in {"/resume", "/threads"}: - await self.action_resume_thread() + await self._resume_thread() elif command == "/approval": if argument.strip().lower() == "shell": await self._choose_shell_approval() @@ -2062,7 +2062,15 @@ async def action_cycle_approval(self) -> None: mode = order[(order.index(self.broker.mode) + 1) % len(order)] await self._activate_approval(mode) - async def action_resume_thread(self) -> None: + def action_resume_thread(self) -> None: + # Bound actions run inside the app's message pump. Waiting for the + # picker there stops the pump from delivering the keys that would + # close it, so the picker freezes. Run the flow in a worker instead. + if isinstance(self.screen, ModalScreen): + return + self.run_worker(self._resume_thread(), exclusive=True, group="resume-thread") + + async def _resume_thread(self) -> None: choice = await self._wait_for_modal( ThreadSelectorScreen( current_thread=self.thread_id, From 2904ec56eba5d7965f7dce4cd33a806eb9050a0a Mon Sep 17 00:00:00 2001 From: khushpal-cipher Date: Tue, 1 Dec 2026 15:43:22 +0530 Subject: [PATCH 2/2] Test the Ctrl+R binding and picker dismissal --- tests/test_tui.py | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/tests/test_tui.py b/tests/test_tui.py index d42bc44..0c032eb 100644 --- a/tests/test_tui.py +++ b/tests/test_tui.py @@ -351,7 +351,7 @@ async def threads(**_kwargs): monkeypatch.setattr(copper_widgets_module, "list_threads", threads) app = CopperPilotApp(FakeRuntime(), LocalToolBroker(tmp_path), tmp_path, "thread") async with app.run_test(size=(100, 40)) as pilot: - resume = asyncio.create_task(app.action_resume_thread()) + await pilot.press("ctrl+r") await _wait_until( pilot, lambda: ( @@ -367,8 +367,38 @@ async def threads(**_kwargs): await pilot.press("tab") assert app.screen.query_one("#thread-filter", Input).has_focus await pilot.press("shift+tab", "enter") - await resume - assert app.thread_id == "resumed-thread" + await _wait_until(pilot, lambda: app.thread_id == "resumed-thread") + assert not isinstance(app.screen, ThreadSelectorScreen) + + +@pytest.mark.asyncio +async def test_ctrl_r_picker_can_be_dismissed_and_reopened(tmp_path, monkeypatch) -> None: + async def threads(**_kwargs): + return [ + { + "thread_id": "other", + "message_count": 1, + "updated_at": "2026-10-14", + "initial_prompt": "Other", + } + ] + + monkeypatch.setattr(copper_widgets_module, "list_threads", threads) + app = CopperPilotApp(FakeRuntime(), LocalToolBroker(tmp_path), tmp_path, "thread") + async with app.run_test(size=(100, 40)) as pilot: + await pilot.press("ctrl+r") + await _wait_until(pilot, lambda: isinstance(app.screen, ThreadSelectorScreen)) + # A second press while the picker is open does not stack another one. + await pilot.press("ctrl+r") + await pilot.pause() + assert isinstance(app.screen, ThreadSelectorScreen) + await pilot.press("escape") + await _wait_until(pilot, lambda: not isinstance(app.screen, ThreadSelectorScreen)) + assert app.thread_id == "thread" + await pilot.press("ctrl+r") + await _wait_until(pilot, lambda: isinstance(app.screen, ThreadSelectorScreen)) + await pilot.press("escape") + await _wait_until(pilot, lambda: not isinstance(app.screen, ThreadSelectorScreen)) @pytest.mark.asyncio @@ -905,9 +935,8 @@ async def select_thread(_screen): app._wait_for_modal = select_thread async with app.run_test(size=(100, 30)) as pilot: - await app.action_resume_thread() - await pilot.pause() - assert app.thread_id == "resumed-thread" + app.action_resume_thread() + await _wait_until(pilot, lambda: app.thread_id == "resumed-thread") assert runtime.agent.conversation_id == "resumed-thread"