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
1 change: 1 addition & 0 deletions src/toad/client/committed_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def arriving(self, prepared: PreparedTranscriptPage, followed_end: bool):
)

def rows_published(self, owner) -> None:
super().rows_published(owner)
if self.live_blocks and not NEWER_END.visible_more(owner):
blocks, self.live_blocks = self.live_blocks, ()
self.retirement = owner.view.retire_blocks(blocks)
13 changes: 1 addition & 12 deletions src/toad/client/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from toad.client.connection import CoordinationAccess, Observation
from toad.client.conversation import ConversationKind
from toad.client.resource_release import ResourceRelease
from toad.core.events import CoordinationObserved, Publication
from toad.core.events import Publication
from toad.core.source_events import TranscriptSourceWorkFinished
from toad.client.conversation_capabilities import (
ConversationActivity,
Expand Down Expand Up @@ -739,17 +739,6 @@ def reads_from(self, root: str | Path) -> bool:
def uses_observation(self, observation: Observation) -> bool:
return observation.observes(self.loader.root)

def observe_availability(self, view, access: CoordinationAccess, resume: Callable[[object], object]) -> ResourceRelease:
"""A wire conversation has no thread transcript scope (`NoTranscript.observe` is a
no-op), so a read paused on `CoordinationReadUnavailable` resumes on Core's own
coordination stream instead of wedging the tab in `WorkingTranscript` forever."""
release = ResourceRelease()
release.callback(
view.retire_core,
view.observe_core_callback(access.events, CoordinationObserved, resume),
)
return release

async def route_is_current(self) -> bool:
if self.closed:
return False
Expand Down
23 changes: 15 additions & 8 deletions src/toad/client/history_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@
from agent_comms.nominal.declared_family import DeclaredFamily
from agent_comms.nominal.lifecycle import LifecycleState
from agent_comms.transcript.transcripts import TranscriptPage
from agent_comms.ui_model.observation import ObserverUnattached
from agent_comms.ui_model.observation_wire import ObservationEnded

from toad.client.history_coverage import NO_COVERAGE, PAGE_COVERAGE, HistoryCoverage
from toad.client.history_preparation import NEWER_END, OLDER_END, PageRequest
from toad.client.resource_release import ResourceRelease
from toad.client.subscribers import CoreObserver

# Network drops, route changes and remote socket failures are recoverable outages, never
# permanent source corruption: defer the operation so CoordinationObserved resumes it
# when connectivity returns instead of retiring the tab into RetiredSourceTranscript.
# Network drops, route changes, observer restarts and remote socket failures are recoverable
# outages, never permanent source corruption: defer the operation so CoordinationObserved
# resumes it when connectivity returns instead of retiring the tab into RetiredSourceTranscript.
TRANSIENT_SOURCE_ERRORS = (
CoordinationReadUnavailable,
ObservationEnded,
ObserverUnattached,
RouteChangedError,
ConnectionError,
TimeoutError,
Expand Down Expand Up @@ -338,11 +342,9 @@ class WaitingSourceWork[Owner, Snapshot, Result]:

@contextmanager
def observe(self):
# The pager's page source owns how availability returns: a saved transcript watches
# its view's thread scope, while a wire conversation watches Core's coordination
# stream (`WirePageBuffer.observe_availability`) because its `thread_scope` is
# `NoTranscript` (whose `observe` is a no-op that left channel tabs wedged forever
# after any background/reconnect `CoordinationReadUnavailable`).
# `PreparedPageSource.observe_availability` watches both the view's thread scope
# (a no-op on wire conversations whose scope is `NoTranscript`) and Core's
# coordination stream so reconnection resumes paused transcript and wire reads alike.
view = self.owner.view
with self.owner.page_source.observe_availability(
view, self.owner.app.coordination_access, self.resume
Expand Down Expand Up @@ -389,6 +391,11 @@ def schedule_work(self, owner, work) -> SourceWork:
self.owed[key] = work
return DEFERRED_WORK

def publish(self) -> TranscriptState:
"""Advance the wrapped state without dropping this running operation before `finish_source_work`."""
object.__setattr__(self, "source", self.source.publish())
return self

def rows_published(self, owner) -> None:
self.source.rows_published(owner)

Expand Down
14 changes: 11 additions & 3 deletions src/toad/client/prepared_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from toad.client.resource_release import ResourceRelease
from toad.client.submission import ComposeAccess, SubmissionOwner, SubmissionStart, SubmittedText
from toad.commit_claims import RETAINED_SOURCE_CLAIM, CommitClaim, RetainedBlockClaim
from toad.core.events import CoordinationObserved
from toad.status_thread import NoStatusThread
from toad.work_preparation import (
PreparationRuntime,
Expand Down Expand Up @@ -434,9 +435,16 @@ def measure_held(self, pages: tuple[PreparedTranscriptPage, ...],
def observe_availability(
self, view, access: CoordinationAccess, resume: Callable[[object], object]
) -> ResourceRelease:
"""How a paused read learns its source can answer again: saved transcripts watch
their view's thread scope; wire conversations override this to watch Core's stream."""
return view.thread_scope.observe(view, access, resume)
"""How a paused read learns its source can answer again: watch both the view's thread
scope (a no-op on wire conversations whose scope is `NoTranscript`) and Core's
coordination stream so reconnection resumes paused transcript and wire reads alike."""
release = ResourceRelease()
release.enter_context(view.thread_scope.observe(view, access, resume))
release.callback(
view.retire_core,
view.observe_core_callback(access.events, CoordinationObserved, resume),
)
return release

def park(self, pages: tuple[PreparedTranscriptPage, ...],
projection: HeldProjection = NoProjection()) -> None:
Expand Down
4 changes: 4 additions & 0 deletions src/toad/qt/mailbox_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def __init__(self, app, project: Checkout, thread_incarnation: ThreadIncarnation
# made the empty page look already published and no first-page read was scheduled.
self._identity: ThreadIdentity | NoThreadIdentity = ThreadIdentity(thread_incarnation, root)
self._lay_out_thread(app, thread_incarnation.name, thread_incarnation)
# Qt's mailbox view never hosts a local ACP agent: its composer and submission path
# always send through Core's inbox, including when opened on a local desktop bus
# where `NativeThreadNavigation.bind` calls `apply_native_load_plan`.
self.operational_sources = self.mailbox_sources()

def composer_class(self) -> type[MailboxComposer]:
"""Textual's `MailboxSessionSources.prompt`: a `MailboxPrompt`."""
Expand Down
32 changes: 20 additions & 12 deletions src/toad/transcript_publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@
PreparedTranscriptPage,
UnreadTranscriptPage,
)
from toad.client.history_state import LiveTranscript, PreparedReplacementViewportRequest
from toad.client.history_state import (
TRANSIENT_SOURCE_ERRORS,
LiveTranscript,
PreparedReplacementViewportRequest,
)
from toad.client.reader_position import LatestPosition, TailPosition
from toad.worker_group import WorkerGroup

Expand Down Expand Up @@ -202,22 +206,26 @@ async def publish(self) -> bool:
try:
if await self.capture_application():
return await self.publish_applied()
except CoordinationReadUnavailable, StaleRevision, ReadAgain:
# No usable source snapshot was acquired. Keep the original operation,
# mounted history and work slot unchanged until a new observation
# or the existing preparation completion resumes source work. A read dropped
# because its observation closed (`ObserverRetired`, a `ReadAgain`) is one of
# these: it escaped here until 2026-11-21, ending the publication's task with
# an exception nobody took (Qt), or a failed worker (Textual).
except ReloadRequired:
# Must precede `ReadAgain`: `ReloadRequired` subclasses `ReadAgain`, so catching
# `ReadAgain` first left this arm unreachable and kept resending a stale witness.
# The published witness names a source that is gone, so the resumed operation
# reads from fresh bounds.
if self.current():
self.owner.current_read = NotPublished()
self.owner.source_requests.defer(self)
return False
except ReloadRequired:
# The published witness names a source that is gone, so resending it never
# answers: the resumed operation reads from fresh bounds.
except (*TRANSIENT_SOURCE_ERRORS, StaleRevision, ReadAgain) as error:
# No usable source snapshot was acquired. Keep the original operation,
# mounted history and work slot unchanged until a new observation
# or the existing preparation completion resumes source work. A read dropped
# because its observation closed (`ObserverRetired`, a `ReadAgain`) or the
# connector/observer restarted (`ObservationEnded`, `RouteChangedError`, etc.)
# defers here instead of failing the publication task and wedging the view.
if self.current():
self.owner.current_read = NotPublished()
self.owner.source_requests.defer(self)
if isinstance(error, TRANSIENT_SOURCE_ERRORS):
self.binding.view.app.coordination_access.check_route()
return False
return True

Expand Down
19 changes: 15 additions & 4 deletions tests/guards/test_shared_history_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,23 @@ def test_a_paused_source_observes_the_scope_its_pager_view_owns():
from toad.client.history_state import WaitingSourceWork
from toad.client.prepared_pages import PreparedPageSource
from toad.core.events import CoordinationObserved
from toad.transcript_scope import NoTranscript

observed = []
saved_subscribed = []
saved_retired = []

@contextmanager
def observe(owner, access, resume):
observed.append((owner, access, resume))
yield

access = SimpleNamespace(events=object())
view = SimpleNamespace(thread_scope=SimpleNamespace(observe=observe))
view = SimpleNamespace(
thread_scope=SimpleNamespace(observe=observe),
observe_core_callback=lambda stream, event_type, cb: (saved_subscribed.append((stream, event_type, cb)), "saved-sub")[1],
retire_core=lambda sub: saved_retired.append(sub),
)
owner = SimpleNamespace(
view=view,
page_source=PreparedPageSource(),
Expand All @@ -114,15 +121,19 @@ def observe(owner, access, resume):
waiting = WaitingSourceWork(owner, object(), lambda: None, object())

with waiting.observe():
pass
assert saved_subscribed == [(access.events, CoordinationObserved, waiting.resume)]
assert saved_retired == []

assert observed == [(view, access, waiting.resume)]
assert saved_retired == ["saved-sub"]

# A wire conversation has NoTranscript as thread_scope, so WirePageBuffer must watch
# Core's CoordinationObserved stream instead of silently returning an empty release.
# A wire conversation has NoTranscript as thread_scope and inherits the same
# PreparedPageSource.observe_availability so both transcript and wire reads wake on
# CoordinationObserved.
subscribed = []
retired = []
wire_view = SimpleNamespace(
thread_scope=NoTranscript(),
observe_core_callback=lambda stream, event_type, cb: (subscribed.append((stream, event_type, cb)), "sub")[1],
retire_core=lambda sub: retired.append(sub),
)
Expand Down
3 changes: 2 additions & 1 deletion tests/guards/test_shared_hook_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ def test_qt_live_blocks_survive_page_range_changes_and_retire_only_by_commit_cov
from toad.qt.thread_view import QtThreadView
from toad.transcript_publication import BoundView
from toad.client.committed_presentation import CommitTranscript, block_claim
from toad.client.history_state import LiveTranscript

from toad.arrivals import AnimatesArrivals
redrawn = []
Expand Down Expand Up @@ -986,7 +987,7 @@ async def apply_coverage():

async def check_commit_retirement():
commit = CommitTranscript(
source=SimpleNamespace(),
source=LiveTranscript(),
owner=fake_owner,
live_blocks=(uncovered_response,),
claims=(block_claim(uncovered_response),),
Expand Down
Loading
Loading