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
2 changes: 1 addition & 1 deletion src/agent_comms/messaging/historical_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def page(self, view: HistoryView, presentation: BusPresentation, bounds: PageBou
current = replace(bounds, traversal=traversal.for_source(index == start))
request = view.page_request(view.capture(snapshot), current)
current_snapshot = presentation.registry.snapshot()
document = presentation.bus.reads.read()
document = presentation.bus.reads.read_shared()
opened = Bus(Bus.path_in(Path(source.root)))
raw = request.read_opened(opened)
projected = replace(raw, messages=tuple(
Expand Down
2 changes: 1 addition & 1 deletion src/agent_comms/messaging/human_read_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def ledger(self) -> ReadLedger:

@cached_property
def document(self) -> ReadDocument:
return self.ledger.read()
return self.ledger.read_shared()
2 changes: 1 addition & 1 deletion src/agent_comms/messaging/message_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _unread_cut(
self, name: str, snapshot: RegistrySnapshot, target: NamedTarget, after: InboxStart,
bounds: PageBounds,
) -> Iterator[UnreadCut]:
catalog = self._channels.read()
catalog = self._channels.read_shared()
require_channel = partial(self.channel_in, catalog)
delivery = DeliveryScope.capture(name, snapshot, catalog)
selection = delivery.selection(target, snapshot, require_channel)
Expand Down
4 changes: 2 additions & 2 deletions src/agent_comms/messaging/published_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__[Registry](self, root: Path, registry: Registry, publisher: type[Wri


def require_channel(self, target: str) -> Channel:
return self.channel_in(self._channels.read(), target)
return self.channel_in(self._channels.read_shared(), target)

def channel_in(self, catalog: CatalogAccess, target: str) -> Channel:
"""A lookup needs its own channel's clocks only. Every inbox read makes several, and the
Expand All @@ -50,4 +50,4 @@ def channel_in(self, catalog: CatalogAccess, target: str) -> Channel:

def channel_declarations(self):
with self.opened_activity() as activity:
return self._channels.read().views(activity)
return self._channels.read_shared().views(activity)
4 changes: 2 additions & 2 deletions src/agent_comms/messaging/read_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def advance(document: ReadDocument) -> DocumentChange[ReadDocument, ReadDocument
def cursor(
self, viewer: str, snapshot: RegistryProvenance, *, document: ReadDocument | None = None
) -> ReadCursor:
document = self.read() if document is None else document
document = self.read_shared() if document is None else document
return document.cursor(viewer, snapshot, ObservedPath.at(Bus.path_in(self.path.parent)))

def displayed_recipient(
Expand Down Expand Up @@ -263,7 +263,7 @@ def _transcript_key(viewer: str, source: str, inode: int) -> tuple[str, str, int
def transcript_seen(
self, viewer: str, source: str, inode: int, *, document: ReadDocument | None = None
) -> int:
document = self.read() if document is None else document
document = self.read_shared() if document is None else document
return document.transcripts.get(self._transcript_key(viewer, source, inode), 0)

def mark_transcript(
Expand Down
19 changes: 7 additions & 12 deletions src/agent_comms/storage/locked_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1524,28 +1524,23 @@ def _decode_retained(self, source: DocumentBytes) -> DecodedDocument[T]:
def _read_current(self) -> DecodedDocument[T]:
return self._decode_retained(self._copy_sources(self)[0])

def _read_shared(self) -> T:
"""Read the cached document without copying; callers must treat the value as read-only."""
def _read_with(self, extract: Callable[[DecodedDocument[T]], T]) -> T:
try:
revision = FileRevision.from_stat(self.path.stat())
except FileNotFoundError:
_read_cache.pop(self.path, None)
return self.empty()
return self._read_captured(
lambda: self._cached_value(revision, self._read_current),
lambda captured: captured.value,
extract,
)

def read_shared(self) -> T:
"""Read the cached document without copying; callers must treat the value as read-only."""
return self._read_with(lambda captured: captured.value)

def read(self) -> T:
try:
revision = FileRevision.from_stat(self.path.stat())
except FileNotFoundError:
_read_cache.pop(self.path, None)
return self.empty()
return self._read_captured(
lambda: self._cached_value(revision, self._read_current),
lambda captured: captured.detached(),
)
return self._read_with(lambda captured: captured.detached())

def _publish_encoded_unlocked(self, encoded: JsonValue) -> None:
_read_cache.pop(self.path, None)
Expand Down
2 changes: 1 addition & 1 deletion src/agent_comms/transport/connector_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def empty(self) -> ConnectorGrants:

def caller_for(self, token: str) -> ConnectorCaller:
"""Resolve one bearer without deep-copying the grants document on every HTTP request."""
return self._read_shared().caller_for(token)
return self.read_shared().caller_for(token)

def thread_granted(self, thread: str) -> str:
token = secrets.token_urlsafe(32)
Expand Down
Loading