Skip to content
Merged
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
9 changes: 8 additions & 1 deletion src/toad/client/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,18 @@ class WireSource(BusQueueSource, ConversationSource):
me: str
style: WireMessageStyle
access: CoordinationAccess = field(kw_only=True)
core: CoreAccess = field(kw_only=True)
fixed_core: CoreAccess | None = field(default=None, kw_only=True)
fragments: type[EvidencedFragment] = field(kw_only=True)
tail_limit: int = 20
page_limit: int = 40

@property
def core(self) -> CoreAccess:
"""The live CoreAccess: explicit override when supplied (unit tests), else resolved
from the current Observation so opening a view during a disconnect never fails in
`__init__` and reconnecting automatically picks up the fresh CoreAccess."""
return self.fixed_core if self.fixed_core is not None else self.access.observation.observed().core

def observe(self, seen: ConversationObservation) -> SourceObservation:
"""The observed state owns how changed or unchanged history is drawn."""
revision = self.core.call(CommsConversationRevisionTool(
Expand Down
2 changes: 1 addition & 1 deletion src/toad/client/history_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def can_draw_on_screen(self) -> bool:

@property
def notification_root(self) -> str:
return str(self.app.source().root)
return self.coordination_root or str(self.app.source().root)

def subscribe_notifications(self, references) -> bool:
"""Route through the current `Observation` so a disconnected or closed observation
Expand Down
3 changes: 1 addition & 2 deletions src/toad/client/history_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
ObservationEnded,
ObserverUnattached,
RouteChangedError,
ConnectionError,
TimeoutError,
OSError,
http.client.HTTPException,
)

Expand Down
37 changes: 35 additions & 2 deletions src/toad/client/sidebar_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ def shows_model(self) -> bool:
def serves(self, path) -> bool:
return False

def retained_root(self):
"""Last observed bus root kept across a transient outage, or None."""
return None

def retained_model(self) -> SidebarModel | None:
"""Last shown SidebarModel kept across a transient outage, or None."""
return None

def observes(self, observed: Observing) -> bool:
return False

Expand Down Expand Up @@ -81,6 +89,17 @@ def shows_rows(self, view: SidebarStateMachine) -> bool:
@dataclass(frozen=True)
class FailedSidebarState(SidebarModelState):
observed: FailedObservation
retained_root_path: object = None
retained_sidebar: SidebarModel | None = None

def serves(self, path) -> bool:
return self.retained_root_path is not None and self.retained_root_path == path

def retained_root(self):
return self.retained_root_path

def retained_model(self) -> SidebarModel | None:
return self.retained_sidebar

def shows_child(self, view: SidebarStateMachine, child) -> bool:
return child is view.unavailable
Expand All @@ -103,6 +122,12 @@ def root(self):
def serves(self, path) -> bool:
return self.observed.root == path

def retained_root(self):
return self.observed.root

def retained_model(self) -> SidebarModel | None:
return self.observed.sidebar

def observes(self, observed: Observing) -> bool:
return self.observed is observed

Expand Down Expand Up @@ -204,9 +229,17 @@ def stop_showing(self) -> None:
self.unsubscribe()

def bind_failed_observation(self, observed: FailedObservation) -> None:
previous = self.model_state
retained_root = previous.retained_root()
retained_model = previous.retained_model()
self.unsubscribe()
self.model_state = FailedSidebarState(observed)
self.model_replaced()
self.model_state = FailedSidebarState(
observed,
retained_root_path=retained_root,
retained_sidebar=retained_model,
)
if retained_model is None:
self.model_replaced()
self.present()

def bind_observation(self, observed: Observing) -> None:
Expand Down
4 changes: 4 additions & 0 deletions src/toad/qt/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ def mount_composer(self, focus: bool = False) -> None:
else:
composer, reused = build(), False
except Exception as error:
# Keep the placeholder slot resumable instead of stranding a permanently blank box.
self._composer_reserved = reserved
if shiboken6.isValid(self) and shiboken6.isValid(self.messages):
self.messages.viewport().installEventFilter(self)
self.app.show_error(error, "Composer mount failed")
return
if reused:
Expand Down
19 changes: 14 additions & 5 deletions src/toad/qt/float_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from __future__ import annotations

from PySide6.QtCore import QEvent, QObject, QTimer, Qt
from PySide6.QtWidgets import QFrame, QLabel, QVBoxLayout, QWidget
from PySide6.QtWidgets import QFrame, QLabel, QSizePolicy, QVBoxLayout, QWidget
from pyqt_reactive.protocols.widget_adapters import PyQtWidgetMeta
from pyqt_reactive.theming import ColorScheme, StatusColorRole
from pyqt_reactive.widgets.status_line import NoticeLine
Expand Down Expand Up @@ -79,6 +79,9 @@ def __init__(self, scheme: ColorScheme, background_hex: str, text: str, role: St
layout.setContentsMargins(UiGap.tight, UiGap.tight, UiGap.tight, UiGap.tight)
line = NoticeLine(scheme)
line.setParent(self)
policy = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
policy.setHeightForWidth(True)
line.setSizePolicy(policy)
line.show_status(text, role)
layout.addWidget(line)
self.expiry = QTimer(self)
Expand All @@ -91,7 +94,7 @@ def dismiss(self) -> None:
self.hide()
self.deleteLater()
if (layer := self.parentWidget()) is not None:
layer.adjustSize()
layer.follow_content()

def mousePressEvent(self, event) -> None: # noqa: N802 - Qt virtual method name
self.dismiss()
Expand Down Expand Up @@ -175,7 +178,13 @@ def follow_content(self, *_destroyed: object) -> None:
def place(self) -> None:
window = self.parentWidget()
margins = window.contentsMargins()
width = window.width() - margins.left() - margins.right()
self.setFixedWidth(max(1, width))
self.adjustSize()
width = max(1, window.width() - margins.left() - margins.right())
self.setFixedWidth(width)
layout = self.layout()
layout.activate()
height = layout.totalHeightForWidth(width)
if height <= 0:
height = self.sizeHint().height()
self.resize(width, max(1, height))
self.move(margins.left(), margins.top())
layout.activate()
8 changes: 5 additions & 3 deletions src/toad/qt/goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ class QtGoalBar(QtCoreObserver, GoalBarOwner, GoalCollapse, QWidget, metaclass=P

document_share = 0.2

def __init__(self, app: ClientApplication, renderer: QtLineRenderer, peer: ThreadIncarnation) -> None:
def __init__(self, app: ClientApplication, renderer: QtLineRenderer, peer: ThreadIncarnation,
*, root: str | None = None) -> None:
super().__init__()
self.app, self.peer = app, peer
self.goal_source = CommsGoalSource(app, peer, str(app.source().root))
self.root = root if root is not None else str(app.source().root)
self.goal_source = CommsGoalSource(app, peer, self.root)
self.session = QtGoalSession(self)
self.goal_observation = GoalObservation(self)
self._goal_display: GoalDisplay = NoGoal()
Expand Down Expand Up @@ -233,7 +235,7 @@ def mount(self) -> None:
self.is_attached = True
self.observe_core_callback(
self.coordination.events, ThreadRowsChanged, self.rows_changed,
factory=partial(ThreadCallbackSubscription, scope=(str(self.app.source().root), self.peer.name)))
factory=partial(ThreadCallbackSubscription, scope=(self.root, self.peer.name)))
self.goal_observation.invalidate()

def rows_changed(self, event: ThreadRowsChanged) -> None:
Expand Down
4 changes: 3 additions & 1 deletion src/toad/qt/thread_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ def _setup_prompt_stack(self, app: QtToadApp, layout: QVBoxLayout, incarnation)
The composer is built once the transcript has painted (`reserve_composer`); its
slot is reserved here so it lands in order, with the question under it."""
self.thread_activity = QtSessionDetails(self, app.renderer)
self.goal_bar = None if incarnation is None else QtGoalBar(app, app.renderer, incarnation)
self.goal_bar = None if incarnation is None else QtGoalBar(
app, app.renderer, incarnation, root=self.coordination_root
)
self.activity = tuple(row for row in (self.thread_activity, self.goal_bar) if row is not None)
self._composer_slot = QVBoxLayout()
self._composer_slot.setContentsMargins(0, 0, 0, 0)
Expand Down
18 changes: 11 additions & 7 deletions src/toad/qt/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ def present(self, **changes: object) -> None:
thread here on each observation was 17% of the phone's UI thread during a burst of
arrivals (2026-11-18)."""
super().present(**changes)
model = self.model_state.shown if self.model_state.shows_model() else None
model = self.model_state.shown if self.model_state.shows_model() else self.model_state.retained_model()
if model is None and self.groups:
self.groups = {}
self.redraw(lambda top: None)
Expand Down Expand Up @@ -1487,12 +1487,14 @@ def __init__(self, app: QtToadApp, entry: QtHistorySessionEntry) -> None:
label = entry.unobserved_tab().label()
self._setup_conversation(app)
self.message_history = QtWireHistory(self.messages, self, app)
source = app.source()
# WireSource IS a BusQueueSource (client/history.py): the submissions read its
# pending/queued/held state as `CommsChatView` does.
# pending/queued/held state as `CommsChatView` does. Resolve live CoreAccess via
# `app.coordination_access` instead of `app.source().core` so opening or restoring
# a tab during a disconnect never crashes `__init__` and reconnects seamlessly.
wire = WireSource(
source.root, self.conversation, source.project, entry.viewer, self.configuration_state.fields.ui.message_style(),
access=app.coordination_access, core=source.core, fragments=QtWireFragment)
Path(entry.key.root), self.conversation, entry.project, entry.viewer,
self.configuration_state.fields.ui.message_style(),
access=app.coordination_access, fragments=QtWireFragment)
self.queue_source = wire
self.message_history.initialize_source(wire)
self.message_history.observe_source()
Expand Down Expand Up @@ -1565,7 +1567,9 @@ def read_thread_config(self) -> None:
async def thread_label_read(self) -> None:
# The label reads Core's thread references: off the GUI loop, as compose access is.
# Read on the loop it held a tab's opening for 104 ms on the desktop (frame probe).
references = await self.app.preparation.run_thread(self.app.source().references)
# Resolve `app.source()` inside `run_thread` so a disconnected FailedObservation
# raises inside the worker where `_refresh_thread_config` catches transient errors.
references = await self.app.preparation.run_thread(lambda: self.app.source().references())
label = self.conversation.label(references)
self._composer_label = label
self.on_composer("label", lambda composer: composer.labelled(label))
Expand All @@ -1590,7 +1594,7 @@ def compose_channel_activity(self) -> Iterator[ChannelActivitySidebar]:
def compose_peer_activity(self, peer: ThreadIncarnation) -> Iterator[QtGoalBar | PeerActivity]:
# The peer's goal sits over its activity and the composer, as the TUI's goal bar
# sits over its prompt.
self.goal_bar = QtGoalBar(self.app, self.app.renderer, peer)
self.goal_bar = QtGoalBar(self.app, self.app.renderer, peer, root=self.coordination_root)
yield self.goal_bar
self.thread_activity = PeerActivity(self.app, self.app.renderer, peer, self.sync_working)
yield self.thread_activity
Expand Down
2 changes: 1 addition & 1 deletion src/toad/widgets/comms_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def initialize_view(self) -> None:
)
source = WireSource(
observed.root, self.conversation, self.project_path, self._me,
self.settings.ui.message_style(), access=self.app.coordination_access, core=observed.core,
self.settings.ui.message_style(), access=self.app.coordination_access,
fragments=WireFragment,
)
self.queue_source = source
Expand Down
Loading
Loading