Skip to content

Redesign actor_addr as value type - #2409

Draft
Neverlord wants to merge 1 commit into
mainfrom
gh-2397-actor-addr-redesign
Draft

Redesign actor_addr as value type#2409
Neverlord wants to merge 1 commit into
mainfrom
gh-2397-actor-addr-redesign

Conversation

@Neverlord

Copy link
Copy Markdown
Member

The only purpose of actor_addr is to select actor handles that are stored as either actor or typed_actor<...>. However, internally it holds a weak pointer to the actor. At this point, only for historic reasons.

While holding a weak pointer internally works in a single-process setting, this design breaks in a distributed system. Sending a weak pointer is deeply problematic:

  • remote nodes hold strong references to actors they are communicating with; once the remote actor terminates this reference will be dropped automatically from the registry
  • when receiving a weak pointer to an unknown actor, there is no sensible thing the receiver might do other than discarding it:
    • creating a proxy would immediately expire the object again
    • there might exist weak references to the old proxy, creating a new one would mean those pointer would be unequal even though they represent the same actor
    • storing weak references in the registry would only introduce new problems w.r.t. proxy lifetimes, etc.

Since the purpose of actor_addr is to identify terminated actors in an exit_msg or down_msg, the much cleaner, safe alternative is to re-implement it as a simple value type holding an actor_id and a node_id: these two IDs uniquely and unambiguously identify any actor in a distributed CAF system.

Since sending weak pointers is fundamentally unsafe, we also remove the type ID for weak_actor_ptr.

This comment was marked as outdated.

@codecov

codecov Bot commented May 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.43182% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.01%. Comparing base (7442d66) to head (6ba4690).

Files with missing lines Patch % Lines
libcaf_core/caf/actor_addr.cpp 51.51% 15 Missing and 1 partial ⚠️
libcaf_core/caf/actor_addr.hpp 77.27% 3 Missing and 2 partials ⚠️
libcaf_core/caf/detail/compare.cpp 82.14% 4 Missing and 1 partial ⚠️
libcaf_io/caf/io/basp_broker.cpp 16.66% 5 Missing ⚠️
libcaf_core/caf/attachable.cpp 77.77% 2 Missing and 2 partials ⚠️
libcaf_core/caf/abstract_actor.cpp 84.21% 2 Missing and 1 partial ⚠️
libcaf_core/caf/actor.cpp 33.33% 1 Missing and 1 partial ⚠️
libcaf_core/caf/detail/monitor_action.cpp 0.00% 0 Missing and 2 partials ⚠️
libcaf_core/caf/typed_actor.hpp 84.61% 1 Missing and 1 partial ⚠️
libcaf_core/caf/send.hpp 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2409      +/-   ##
==========================================
- Coverage   73.12%   73.01%   -0.12%     
==========================================
  Files         635      637       +2     
  Lines       30525    30559      +34     
  Branches     3343     3353      +10     
==========================================
- Hits        22322    22313       -9     
- Misses       6289     6331      +42     
- Partials     1914     1915       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Neverlord
Neverlord force-pushed the gh-2397-actor-addr-redesign branch 2 times, most recently from 26449e4 to 793424d Compare May 3, 2026 09:03
@Neverlord
Neverlord requested a review from Copilot May 3, 2026 09:03

Copilot AI 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.

Pull request overview

Copilot reviewed 46 out of 46 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread libcaf_core/caf/actor_addr.hpp Outdated
Comment thread CHANGELOG.md
The only purpose of `actor_addr` is to select actor handles that are
stored as either `actor` or `typed_actor<...>`. However, internally it
holds a weak pointer to the actor. At this point, only for historic
reasons.

While holding a weak pointer internally works in a single-process
setting, this design breaks in a distributed system. Sending a weak
pointer is deeply problematic:
- remote nodes hold *strong* references to actors they are communicating
  with; once the remote actor terminates this reference will be dropped
  automatically from the registry
- when receiving a weak pointer to an unknown actor, there is no
  sensible thing the receiver might do other than discarding it:
  * creating a proxy would immediately expire the object again
  * there might exist weak references to the old proxy, creating a new
    one would mean those pointer would be unequal even though they
    represent the same actor
  * storing weak references in the registry would only introduce new
    problems w.r.t. proxy lifetimes, etc.

Since the purpose of `actor_addr` is to identify terminated actors in an
`exit_msg` or `down_msg`, the much cleaner, safe alternative is to
re-implement it as a simple value type holding an `actor_id` and a
`node_id`: these two IDs uniquely and unambiguously identify any actor
in a distributed CAF system.

Further, sending weak pointers is fundamentally unsafe. Hence, we also
remove the type ID for `weak_actor_ptr` and remove support for it from
the serialization API.
@Neverlord
Neverlord force-pushed the gh-2397-actor-addr-redesign branch from 793424d to 6ba4690 Compare May 3, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants