Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/copper_pilot_cli/copper_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
41 changes: 35 additions & 6 deletions tests/test_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: (
Expand All @@ -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
Expand Down Expand Up @@ -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"


Expand Down