From df271b7066584276aa462d5244d983221cf63a7c Mon Sep 17 00:00:00 2001 From: Tristan Simas Date: Sat, 28 Nov 2026 11:40:20 -0500 Subject: [PATCH] Apply 9 mechanical NRA #664/#665/#666 Wave 4b recipes (6 P58 + 3 P51) --- .../cli_bridges/antigravity_protocol.py | 4 ---- .../cli_bridges/claude_protocol.py | 4 ---- src/agent_comms/cli_bridges/hook_requests.py | 23 ++++++++++++++----- .../cli_bridges/runtime_updates.py | 4 ++++ src/agent_comms/messaging/read_basis.py | 9 +++----- src/agent_comms/registry/thread_creation.py | 2 +- src/agent_comms/registry/thread_status.py | 21 ++++++++++------- .../storage/maintenance_barrier.py | 3 +-- src/agent_comms/storage/private_path.py | 16 ++++--------- src/agent_comms/storage/storage_room.py | 5 ---- src/agent_comms/storage/typed_table.py | 7 +----- src/agent_comms/transport/tool_denial.py | 2 +- 12 files changed, 45 insertions(+), 55 deletions(-) diff --git a/src/agent_comms/cli_bridges/antigravity_protocol.py b/src/agent_comms/cli_bridges/antigravity_protocol.py index eca863b9da..754486cdec 100644 --- a/src/agent_comms/cli_bridges/antigravity_protocol.py +++ b/src/agent_comms/cli_bridges/antigravity_protocol.py @@ -102,10 +102,6 @@ class AntigravityCatchUp(CatchUpReadingPhase, AntigravityReaderPhase): pending: tuple[StatusUpdate, ...] = () latest_info: tuple[RuntimeInfoObserved, ...] = () - def status(self, update: StatusUpdate) -> tuple[RuntimeUpdate, ...]: - self.pending = (update,) - return () - def window_ended(self, session: AntigravitySession) -> tuple[RuntimeUpdate, ...]: session.phase = AntigravityLive() return (*self.latest_info, *self.pending) diff --git a/src/agent_comms/cli_bridges/claude_protocol.py b/src/agent_comms/cli_bridges/claude_protocol.py index 0d17d58ac9..0b6fba4263 100644 --- a/src/agent_comms/cli_bridges/claude_protocol.py +++ b/src/agent_comms/cli_bridges/claude_protocol.py @@ -375,10 +375,6 @@ def offered(self, update: OfferedToolsObserved) -> tuple[RuntimeUpdate, ...]: self.latest_tools = (update,) return () - def status(self, update: StatusUpdate) -> tuple[RuntimeUpdate, ...]: - self.pending = (update,) - return () - def window_ended(self, session: ClaudeSession) -> tuple[RuntimeUpdate, ...]: session.phase = Live() return (*self.latest_tools, *self.latest_info, *self.pending) diff --git a/src/agent_comms/cli_bridges/hook_requests.py b/src/agent_comms/cli_bridges/hook_requests.py index 2c0db3af69..b0f90d783b 100644 --- a/src/agent_comms/cli_bridges/hook_requests.py +++ b/src/agent_comms/cli_bridges/hook_requests.py @@ -104,20 +104,31 @@ async def handle(self, service: MonitorService, peer: MonitorPeer) -> SessionRep return reply -@dataclass(frozen=True) -class ReadGateRequest(ReadGateProgram, HookRequest[GatedCall], declared_name=ReadGateProgram.wire_name()): +class GatedHookRequest(HookRequest, declared_name=None): + """A hook request decoded into a gated call via its declared event_type.""" + def decode_event(self, comms: Comms, binding: Binding, output: ResidentHookOutput) -> GatedCall: return self.event_type().of(self.payload, output=output, comms=comms, binding=binding) + +@dataclass(frozen=True) +class ReadGateRequest( + GatedHookRequest, + ReadGateProgram, + HookRequest[GatedCall], + declared_name=ReadGateProgram.wire_name(), +): def run_hook(self, event: GatedCall, comms: Comms, binding: Binding) -> None: event.judge() @dataclass(frozen=True) -class ReminderRequest(ReminderProgram, HookRequest[ReminderCall], declared_name=ReminderProgram.wire_name()): - def decode_event(self, comms: Comms, binding: Binding, output: ResidentHookOutput) -> ReminderCall: - return self.event_type().of(self.payload, output=output, comms=comms, binding=binding) - +class ReminderRequest( + GatedHookRequest, + ReminderProgram, + HookRequest[ReminderCall], + declared_name=ReminderProgram.wire_name(), +): def run_hook(self, event: ReminderCall, comms: Comms, binding: Binding) -> None: event.warn(*event.take(comms, binding, event.completed())) diff --git a/src/agent_comms/cli_bridges/runtime_updates.py b/src/agent_comms/cli_bridges/runtime_updates.py index 323cde1893..475c8b1e2c 100644 --- a/src/agent_comms/cli_bridges/runtime_updates.py +++ b/src/agent_comms/cli_bridges/runtime_updates.py @@ -365,6 +365,10 @@ def runtime_info(self, update: RuntimeInfoObserved) -> tuple[RuntimeUpdate, ...] class CatchUpReadingPhase(ReadingPhase): """A transcript reading phase that buffers catch-up updates before going live.""" + def status(self, update: StatusUpdate) -> tuple[RuntimeUpdate, ...]: + self.pending = (update,) + return () + def runtime_info(self, update: RuntimeInfoObserved) -> tuple[RuntimeUpdate, ...]: self.latest_info = (update,) return () diff --git a/src/agent_comms/messaging/read_basis.py b/src/agent_comms/messaging/read_basis.py index d05a87f9b1..d499822712 100644 --- a/src/agent_comms/messaging/read_basis.py +++ b/src/agent_comms/messaging/read_basis.py @@ -604,6 +604,9 @@ def in_targets(self, targets: Collection[str], snapshot: RegistryProvenance) -> class NamedConversation(Conversation, declared_name=None): """A conversation whose identity does not depend on per-incarnation DM resolution.""" + def recorded_keys(self, snapshot: RegistryProvenance) -> Iterable[Conversation]: + return (self,) + def resolved(self, snapshot: RegistryProvenance) -> Self: return self @@ -619,9 +622,6 @@ def scope(self, snapshot: RegistryProvenance) -> AllChannelDisplayScope: def sql_keys(self, snapshot: RegistryProvenance): return (('', ''),) - def recorded_keys(self, snapshot: RegistryProvenance): - return (self,) - def in_targets(self, targets: Collection[str], snapshot: RegistryProvenance) -> bool: return True @@ -636,9 +636,6 @@ def scope(self, snapshot: RegistryProvenance) -> ChannelDisplayScope: def sql_keys(self, snapshot: RegistryProvenance) -> Iterable[tuple[str, str]]: return ((self.target, ""),) - def recorded_keys(self, snapshot: RegistryProvenance) -> Iterable[Conversation]: - return (self,) - def in_targets(self, targets: Collection[str], snapshot: RegistryProvenance) -> bool: return self.target in targets diff --git a/src/agent_comms/registry/thread_creation.py b/src/agent_comms/registry/thread_creation.py index ede7c358a5..9a8e583e48 100644 --- a/src/agent_comms/registry/thread_creation.py +++ b/src/agent_comms/registry/thread_creation.py @@ -19,7 +19,7 @@ def __init__(self) -> None: super().__init__("Registry creation identities collide.") -class CreationTime(float, WireValue, ABC): +class CreationTime(float, WireValue): @abstractmethod def distinct_from(self, used: Set[float]) -> CreationTime: ... diff --git a/src/agent_comms/registry/thread_status.py b/src/agent_comms/registry/thread_status.py index 3a592480d7..b7565d978b 100644 --- a/src/agent_comms/registry/thread_status.py +++ b/src/agent_comms/registry/thread_status.py @@ -518,7 +518,18 @@ def in_view(self, visibility: RosterVisibility) -> bool: return False -class ServiceThreadStatus(PublishingPresence, HiddenThreadStatus): +class UnrestorableThreadStatus(ThreadStatus, declared_name=None): + """A thread status that remains unchanged when restoration is requested.""" + + def restored(self) -> ThreadStatus: + return self + + +class ServiceThreadStatus( + UnrestorableThreadStatus, + PublishingPresence, + HiddenThreadStatus, +): """A service can publish, but has no executable roster row or owner controls.""" def external_registered(self, thread: PresenceThread, now: float) -> ThreadStatus: @@ -527,11 +538,8 @@ def external_registered(self, thread: PresenceThread, now: float) -> ThreadStatu def after_heartbeat(self, name: str) -> ThreadStatus: return self - def restored(self) -> ThreadStatus: - return self - -class ArchivedThreadStatus(OrphansHolds, VacantThreadStatus): +class ArchivedThreadStatus(UnrestorableThreadStatus, OrphansHolds, VacantThreadStatus): def require_checkout_adoption(self) -> None: """Only retired declarations can surrender their checkout grants.""" @@ -542,9 +550,6 @@ def is_archived(self) -> bool: def in_view(self, visibility: RosterVisibility) -> bool: return visibility.archived - def restored(self) -> ThreadStatus: - return self - def active_checkout_matches(self, thread): return () diff --git a/src/agent_comms/storage/maintenance_barrier.py b/src/agent_comms/storage/maintenance_barrier.py index c963805b1f..28bdacd741 100644 --- a/src/agent_comms/storage/maintenance_barrier.py +++ b/src/agent_comms/storage/maintenance_barrier.py @@ -18,7 +18,6 @@ from pathlib import Path from typing import Annotated, ClassVar, Literal, Self -from agent_comms.coordination.errors import DrainUnavailable from agent_comms.errors import RelationViolationError from agent_comms.execution.process_identity import ProcessIdentity from agent_comms.execution.launch_runtime import LaunchRuntime @@ -47,7 +46,7 @@ from agent_comms_hooks import ToolRefusedError -class MaintenanceHeldError(RelationViolationError, ToolRefusedError, DrainUnavailable): +class MaintenanceHeldError(RelationViolationError, ToolRefusedError): """The bus is in maintenance: its readers close and wait for READY. A drain that meets the hold is unavailable until maintenance ends, never stopped: an install must not fail every unit whose inbox drains during its window.""" diff --git a/src/agent_comms/storage/private_path.py b/src/agent_comms/storage/private_path.py index e5b0c0f53d..236d6c4875 100644 --- a/src/agent_comms/storage/private_path.py +++ b/src/agent_comms/storage/private_path.py @@ -216,6 +216,10 @@ def accepts_links(cls, nlink: int) -> bool: class DirectoryFilesystemRole(FilesystemRole, declared_name=None): """A filesystem role that requires and opens a directory.""" + @classmethod + def kind_flags(cls) -> int: + return os.O_DIRECTORY + @classmethod def accepts_kind(cls, mode: int) -> bool: return stat.S_ISDIR(mode) @@ -244,10 +248,6 @@ def require_private_tree( cls.require( directory.lstat(), refusal("Native Pi session directory must be owner-only")) - @classmethod - def kind_flags(cls) -> int: - return os.O_DIRECTORY - class PrivateSocketRole(NonBlockingFilesystemRole): @classmethod @@ -274,20 +274,12 @@ def address(cls, path: Path) -> Iterator[Path]: class OwnedDirectoryRole(DirectoryFilesystemRole): - @classmethod - def kind_flags(cls) -> int: - return os.O_DIRECTORY - @classmethod def accepts_permissions(cls, observed: os.stat_result) -> bool: return True class TrustedAncestorRole(DirectoryFilesystemRole): - @classmethod - def kind_flags(cls) -> int: - return os.O_DIRECTORY - @classmethod def require_path(cls, directory: Path, refusal: Exception) -> None: for ancestor in (directory, *directory.parents): diff --git a/src/agent_comms/storage/storage_room.py b/src/agent_comms/storage/storage_room.py index 5e435101ad..ab64569920 100644 --- a/src/agent_comms/storage/storage_room.py +++ b/src/agent_comms/storage/storage_room.py @@ -162,11 +162,6 @@ def _open_reader( connection.close() raise - @classmethod - def schema_change(cls, path: Path) -> WriterOwnedFile: - """The host-wide ledger is carried under its writer lock, outside any one bus.""" - return WriterOwnedFile() - def dead_claims(self): # Dead/replaced processes cannot hold room, but are never replayed. with self.snapshot() as db: diff --git a/src/agent_comms/storage/typed_table.py b/src/agent_comms/storage/typed_table.py index b8d80c4178..894a01da2c 100644 --- a/src/agent_comms/storage/typed_table.py +++ b/src/agent_comms/storage/typed_table.py @@ -3678,9 +3678,8 @@ def path(self) -> Path: return self.path_in(self.root) @classmethod - @abstractmethod def schema_change(cls, path: Path) -> SchemaChange: - """Whether this file's schema belongs to installation or its runtime.""" + return WriterOwnedFile() @classmethod def declares_schema(cls) -> bool: @@ -3730,10 +3729,6 @@ class DerivedStore(TypedStore, DerivedTables, RuntimeWriter): file instead of rebuilding this one under the writer's lock. """ - @classmethod - def schema_change(cls, path: Path) -> SchemaChange: - return WriterOwnedFile() - def __init_subclass__(cls, **kwargs: object) -> None: super().__init_subclass__(**kwargs) schema = json.dumps(cls.declared_schema(), sort_keys=True).encode() diff --git a/src/agent_comms/transport/tool_denial.py b/src/agent_comms/transport/tool_denial.py index 3b5bb23f0f..230ea90fce 100644 --- a/src/agent_comms/transport/tool_denial.py +++ b/src/agent_comms/transport/tool_denial.py @@ -9,5 +9,5 @@ class SelectedToolDenied(ToolRefusedError): # noqa: N818 - nominal fail-closed """A rejected request, including duplicate or uncertain prior consumption.""" -class StorageDenied(SelectedToolDenied, ToolRefusedError): # noqa: N818 - existing nominal refusal +class StorageDenied(SelectedToolDenied): # noqa: N818 - existing nominal refusal """The storage preflight refused an operation before it executed, or found no room for it."""