fix: wrap session resume in @work to resolve NoActiveWorker crash
push_screen_wait requires a worker context, but on_mount is a plain lifecycle callback. Extract session resume logic into a @work-decorated method so the modal can be awaited without triggering NoActiveWorker.
This commit is contained in:
@@ -11,6 +11,7 @@ from rich.text import Text
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.binding import Binding
|
||||
from textual.widgets import Header, RichLog
|
||||
from textual import work
|
||||
|
||||
from app.agent.context import SessionContext
|
||||
from app.agent.loop import AgentLoop
|
||||
@@ -106,7 +107,12 @@ class SneakyCodeApp(App):
|
||||
|
||||
self._permissions.set_prompt_callback(permission_prompt)
|
||||
|
||||
# Offer session resume if configured
|
||||
# Offer session resume if configured (must run in a worker for push_screen_wait)
|
||||
self._offer_session_resume()
|
||||
|
||||
@work
|
||||
async def _offer_session_resume(self) -> None:
|
||||
"""Offer to resume a previous session, running in a worker for modal support."""
|
||||
if self._session_mgr and self._config.session.offer_resume:
|
||||
saved = self._session_mgr.load_latest()
|
||||
if saved:
|
||||
@@ -118,7 +124,6 @@ class SneakyCodeApp(App):
|
||||
log.write(Text("Session restored", style="bold green"))
|
||||
else:
|
||||
log.write(Text("Starting fresh session", style="cyan"))
|
||||
|
||||
self.query_one(HistoryInput).focus()
|
||||
|
||||
async def on_input_submitted(self, event: Input.Submitted) -> None:
|
||||
|
||||
Reference in New Issue
Block a user