From 948c705dc01be9d3664796060c19573c4923b5bc Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Tue, 24 Nov 2026 11:33:57 +0000 Subject: [PATCH] Make actor dispatcher bookkeeping classes private ActorAndChannel, ActorStatus, DispatchStatus and MergeContext track internal dispatcher state. No public method accepts or returns them. Mark them private and document the removal of the ActorAndChannel name, which was accessible in v1.0.4. Signed-off-by: Leandro Lucarella --- RELEASE_NOTES.md | 4 +-- src/frequenz/dispatch/_actor_dispatcher.py | 36 +++++++++++----------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 29020a4..a928e1d 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -8,10 +8,10 @@ -* `ActorDispatcher.ActorAndChannel` is no longer frozen and has a new required `current_dispatch` field. Code that builds it directly will break; use `ActorDispatcher` itself instead. +* `ActorDispatcher.ActorAndChannel` was exposed by mistake. This internal helper is now private and is no longer available under its old name. * Dispatch now accepts `frequenz-channels >= 1.13.0, < 3`, including v2. * The minimum `frequenz-core` version is now 1.6.0, and the minimum `typing-extensions` version is now 4.16.0. These versions are required by `frequenz-channels` 1.13.0 too. -* The internal timers now use `MonotonicTimer`, and channel shutdown uses `aclose`. These replace APIs that `frequenz-channels` v2 removes. The public dispatch API and behavior are unchanged. +* The internal timers now use `MonotonicTimer`, and channel shutdown uses `aclose`. These replace APIs that `frequenz-channels` v2 removes. ## New Features diff --git a/src/frequenz/dispatch/_actor_dispatcher.py b/src/frequenz/dispatch/_actor_dispatcher.py index 9d700c1..0c52d94 100644 --- a/src/frequenz/dispatch/_actor_dispatcher.py +++ b/src/frequenz/dispatch/_actor_dispatcher.py @@ -374,7 +374,7 @@ async def manage(dispatcher: Dispatcher) -> None: """ @dataclass(kw_only=True) - class ActorAndChannel: + class _ActorAndChannel: """An actor and its dispatch update sender.""" actor: Actor @@ -397,21 +397,21 @@ class ActorAndChannel: """ @dataclass(frozen=True, kw_only=True) - class ActorStatus: + class _ActorStatus: """The running actor or failed dispatch for one actor identity.""" - actor_and_channel: "ActorDispatcher.ActorAndChannel | None" = None + actor_and_channel: "ActorDispatcher._ActorAndChannel | None" = None failed_dispatch: Dispatch | None = None @dataclass(frozen=True, kw_only=True) - class DispatchStatus: + class _DispatchStatus: """The latest dispatch and identity routed for one dispatch ID.""" dispatch: Dispatch identity: DispatchActorId @dataclass(frozen=True, kw_only=True) - class MergeContext: + class _MergeContext: """The merge filter and the dispatches it evaluates.""" dispatch_filter: Callable[[Mapping[DispatchId, Dispatch], Dispatch], bool] @@ -482,8 +482,8 @@ def __init__( # pylint: disable=too-many-arguments, too-many-positional-argumen self._dispatch_rx = running_status_receiver self._retry_timer_rx = MonotonicTimer(retry_interval, SkipMissedAndDrift()) self._actor_factory = actor_factory - self._actors: dict[DispatchActorId, ActorDispatcher.ActorStatus] = {} - self._dispatch_status: dict[DispatchId, ActorDispatcher.DispatchStatus] = {} + self._actors: dict[DispatchActorId, ActorDispatcher._ActorStatus] = {} + self._dispatch_status: dict[DispatchId, ActorDispatcher._DispatchStatus] = {} self._recently_continued: set[DispatchActorId] = set() """Identities whose actor was just re-keyed away by a continuation. @@ -492,7 +492,7 @@ def __init__( # pylint: disable=too-many-arguments, too-many-positional-argumen instead of WARNING. Each identity is removed from this set the first time that happens, so it can't grow without bound. """ - self._merge_context: ActorDispatcher.MergeContext | None = None + self._merge_context: ActorDispatcher._MergeContext | None = None def start(self) -> None: """Start the background service.""" @@ -504,14 +504,14 @@ def _set_merge_context( known_dispatches: Mapping[DispatchId, Dispatch], ) -> None: """Set the merge filter and its complete dispatch context.""" - self._merge_context = ActorDispatcher.MergeContext( + self._merge_context = ActorDispatcher._MergeContext( dispatch_filter=dispatch_filter, known_dispatches=known_dispatches, ) def _find_unique_continuation_candidate( self, dispatch: Dispatch - ) -> tuple[DispatchActorId, "ActorDispatcher.ActorAndChannel"] | None: + ) -> tuple[DispatchActorId, "ActorDispatcher._ActorAndChannel"] | None: """Find the single running actor `dispatch` exactly continues, if any. Args: @@ -610,7 +610,7 @@ def _matching_predecessors( async def _continue_actor( self, predecessor_identity: DispatchActorId, - predecessor: "ActorDispatcher.ActorAndChannel", + predecessor: "ActorDispatcher._ActorAndChannel", dispatch: Dispatch, ) -> "_ContinuationOutcome": """Try to route `dispatch` to `predecessor`'s actor as a continuation. @@ -691,7 +691,7 @@ async def _continue_actor( new_identity = self._dispatch_identity(dispatch) del self._actors[predecessor_identity] predecessor.current_dispatch = dispatch - self._actors[new_identity] = ActorDispatcher.ActorStatus( + self._actors[new_identity] = ActorDispatcher._ActorStatus( actor_and_channel=predecessor ) self._recently_continued.add(predecessor_identity) @@ -706,7 +706,7 @@ async def _continue_actor( async def _discard_unresponsive_predecessor( self, predecessor_identity: DispatchActorId, - predecessor: "ActorDispatcher.ActorAndChannel", + predecessor: "ActorDispatcher._ActorAndChannel", ) -> None: """Stop and remove a predecessor whose continuation outcome is unknown. @@ -726,7 +726,7 @@ async def _discard_unresponsive_predecessor( async def _try_handover( self, dispatch: Dispatch - ) -> tuple[bool, tuple[DispatchActorId, "ActorDispatcher.ActorAndChannel"] | None]: + ) -> tuple[bool, tuple[DispatchActorId, "ActorDispatcher._ActorAndChannel"] | None]: """Try a continuation handover for `dispatch`. Args: @@ -807,13 +807,13 @@ async def _start_actor(self, dispatch: Dispatch, identity: DispatchActorId) -> N dispatch.type, exc_info=e, ) - self._actors[identity] = ActorDispatcher.ActorStatus( + self._actors[identity] = ActorDispatcher._ActorStatus( failed_dispatch=dispatch ) else: # No exception occurred, so we can add the actor to the list - self._actors[identity] = ActorDispatcher.ActorStatus( - actor_and_channel=ActorDispatcher.ActorAndChannel( + self._actors[identity] = ActorDispatcher._ActorStatus( + actor_and_channel=ActorDispatcher._ActorAndChannel( actor=actor, channel=channel, sender=channel.new_sender(), @@ -951,7 +951,7 @@ async def _handle_dispatch(self, dispatch: Dispatch) -> None: "Dispatch identity changed", ) - self._dispatch_status[dispatch.id] = ActorDispatcher.DispatchStatus( + self._dispatch_status[dispatch.id] = ActorDispatcher._DispatchStatus( dispatch=dispatch, identity=identity, )