Skip to content

Stop actors when a dispatch update changes its merge identity - #318

Merged
Marenz merged 2 commits into
frequenz-floss:v1.x.xfrom
Marenz:fix-identity-change-orphans-actor
Nov 13, 2026
Merged

Marenz merged 2 commits into
frequenz-floss:v1.x.xfrom
Marenz:fix-identity-change-orphans-actor

Conversation

@Marenz

@Marenz Marenz commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Updating a running dispatch could change its merge identity, start a new actor, and leave the old one running.

Remember the identity each dispatch was routed to, stop the old actor when the identity changes (unless another running dispatch still uses it), and drop stale retries.

Fixes #310

@Marenz
Marenz requested a review from a team as a code owner October 22, 2026 13:31
@Marenz
Marenz requested review from stefan-brus-frequenz and removed request for a team October 22, 2026 13:31
@github-actions github-actions Bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:dispatcher Affects the high-level dispatcher interface labels Oct 22, 2026
Comment on lines +421 to +423
self._dispatch_identities[dispatch.id] = identity
self._running_dispatches[dispatch.id] = dispatch
self._failed_dispatches.pop(identity, None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have a class for dispatch status, this can probably be done as one operation in that class, hopefully making manipulating stuff less bug prone (if we forget to update one dict it could be bad).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. A start or update now replaces one DispatchStatus, and a stop pops one. The dispatch and its identity can no longer drift between separate maps.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the dispatch side looks good now. A start or update replaces a single DispatchStatus, so the dispatch and its identity are always updated together.

The actor side is still updated inline, though. _handle_dispatch repeats the same steps in three places (L440-L445, L465-L467 and L477-L482): get the ActorStatus, check if it holds a failed dispatch, and pop it. Two of those places also check that the failed dispatch is the one being handled. A small helper method, something like _drop_failed_dispatch(identity, dispatch_id=None), would keep that rule in one place, which is what I was after with this comment.

Two smaller things about the new dataclasses:

  • ActorStatus holds either a running actor or a failed dispatch. Both fields are optional, though, so nothing prevents both from being set or both from being None. A union of two small types, something like RunningActor | FailedStart, would let the type checker rule that out.
  • ActorStatus, DispatchStatus and MergeContext are public names on ActorDispatcher, which is public too, so they'll show up in the API docs. Prefixing them with _ would keep them internal. ActorAndChannel is already exposed the same way, so this could also go in a separate cleanup.

All of this is optional. I'm approving anyway, so feel free to merge as is or leave it for a follow-up.

Comment thread RELEASE_NOTES.md Resolved
@Marenz
Marenz force-pushed the fix-identity-change-orphans-actor branch from 6573546 to 07c983c Compare October 23, 2026 12:19
The v1.0.4 notes were still present after the release.
Restore the empty template before adding new entries.

Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
Remember each dispatch's routed identity in one status record. If it changes,
stop the old actor unless another running dispatch still uses it.

Keep failed starts with actor state so retries cannot drift from routing state.

Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
@Marenz
Marenz force-pushed the fix-identity-change-orphans-actor branch from 07c983c to aa8dfce Compare November 4, 2026 16:56

@llucax llucax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I left an optional suggestion in one thread. Feel free to merge as is.

Comment on lines +421 to +423
self._dispatch_identities[dispatch.id] = identity
self._running_dispatches[dispatch.id] = dispatch
self._failed_dispatches.pop(identity, None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the dispatch side looks good now. A start or update replaces a single DispatchStatus, so the dispatch and its identity are always updated together.

The actor side is still updated inline, though. _handle_dispatch repeats the same steps in three places (L440-L445, L465-L467 and L477-L482): get the ActorStatus, check if it holds a failed dispatch, and pop it. Two of those places also check that the failed dispatch is the one being handled. A small helper method, something like _drop_failed_dispatch(identity, dispatch_id=None), would keep that rule in one place, which is what I was after with this comment.

Two smaller things about the new dataclasses:

  • ActorStatus holds either a running actor or a failed dispatch. Both fields are optional, though, so nothing prevents both from being set or both from being None. A union of two small types, something like RunningActor | FailedStart, would let the type checker rule that out.
  • ActorStatus, DispatchStatus and MergeContext are public names on ActorDispatcher, which is public too, so they'll show up in the API docs. Prefixing them with _ would keep them internal. ActorAndChannel is already exposed the same way, so this could also go in a separate cleanup.

All of this is optional. I'm approving anyway, so feel free to merge as is or leave it for a follow-up.

Comment thread RELEASE_NOTES.md Resolved
@Marenz
Marenz merged commit a0e81e2 into frequenz-floss:v1.x.x Nov 13, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:dispatcher Affects the high-level dispatcher interface part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Actor is never stopped when a dispatch update changes its merge identity

2 participants