Skip to content

chore: ntx builder actor deactivation#1705

Merged
Mirko-von-Leipzig merged 12 commits intonextfrom
santiagopittella-ntx-builder-actor-deactivation
Mar 12, 2026
Merged

chore: ntx builder actor deactivation#1705
Mirko-von-Leipzig merged 12 commits intonextfrom
santiagopittella-ntx-builder-actor-deactivation

Conversation

@SantiagoPittella
Copy link
Collaborator

Closes the third task of #1694

  • Add actor sterility timeout: default 5 min
  • Re-activate deactivated actors when new notes target them via send_targeted, which now returns inactive target account IDs so the builder can re-spawn actors.
  • Add coordinator unit tests for shutdown approval/rejection and targeted notification routing.
  • Improves a bit the tests helpers org.

@SantiagoPittella SantiagoPittella force-pushed the santiagopittella-ntx-code-organization branch from e8864fa to 712ece2 Compare February 25, 2026 14:53
@SantiagoPittella SantiagoPittella force-pushed the santiagopittella-ntx-builder-actor-deactivation branch from c30c953 to d56b50b Compare February 25, 2026 14:55
@SantiagoPittella SantiagoPittella force-pushed the santiagopittella-ntx-code-organization branch from 712ece2 to acacbf3 Compare February 25, 2026 14:58
@SantiagoPittella SantiagoPittella force-pushed the santiagopittella-ntx-builder-actor-deactivation branch from d56b50b to ac9086b Compare February 25, 2026 14:58
@SantiagoPittella SantiagoPittella force-pushed the santiagopittella-ntx-code-organization branch from acacbf3 to 9bede8d Compare February 26, 2026 13:03
@SantiagoPittella SantiagoPittella force-pushed the santiagopittella-ntx-builder-actor-deactivation branch from 75f97f5 to ebf9d91 Compare February 26, 2026 13:05
Comment on lines +179 to +191
ActorShutdownReason::IdleTimeout(account_id) => {
tracing::info!(account_id = %account_id, "Account actor shut down due to idle timeout");

// Remove the actor from the registry, but check if a notification arrived
// just as the actor timed out. If so, the caller should respawn it.
let should_respawn =
self.actor_registry.remove(&account_id).is_some_and(|handle| {
let notified = handle.notify.notified();
tokio::pin!(notified);
notified.enable()
});

Ok(should_respawn.then_some(account_id))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This works, but I really still think we shouldn't need ActorShutdownReason. The actor return value can just be a anyhow::Result<()>. You'll also notice that next returns a result, but we never actually return a result.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We use the ActorShutdownReason in the coordinator side to determinate if we should re-spawn it

Copy link
Collaborator

@Mirko-von-Leipzig Mirko-von-Leipzig Mar 12, 2026

Choose a reason for hiding this comment

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

Yes but there is only one reason to respawn it (currently, and for the foreseeable future imo)

  • if the actor itself decides to shutdown, and
    • if the actor had unhandled notifications
    • then we should restart it

An actor currently shuts down (on purpose) if:

  • it idles for too long
  • its creation tx was reverted

Everything else is a crash/error/bug.

We can therefore in theory say that all Ok(()) means check notify and possibly respawn, and all Err(_) means increment crash counter and respawn.

I'm okay with merging as is, and we can litigate/discuss after. Basically I want to reduce the number of branches and conditionals because these lead to edge cases and bugs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh ok, I misunderstood before. It should be a simple change. To avoid generating conflicts in this PR #1712 I will address this there since it is related to that PR too

@SantiagoPittella SantiagoPittella force-pushed the santiagopittella-ntx-code-organization branch 2 times, most recently from 24eca2c to 429b63e Compare March 10, 2026 15:10
Base automatically changed from santiagopittella-ntx-code-organization to next March 11, 2026 10:57
@SantiagoPittella SantiagoPittella force-pushed the santiagopittella-ntx-builder-actor-deactivation branch from ebf9d91 to 870292b Compare March 11, 2026 17:59
@Mirko-von-Leipzig Mirko-von-Leipzig merged commit b51c9b8 into next Mar 12, 2026
19 checks passed
@Mirko-von-Leipzig Mirko-von-Leipzig deleted the santiagopittella-ntx-builder-actor-deactivation branch March 12, 2026 12:45
@SantiagoPittella SantiagoPittella restored the santiagopittella-ntx-builder-actor-deactivation branch March 12, 2026 14:42
@SantiagoPittella SantiagoPittella deleted the santiagopittella-ntx-builder-actor-deactivation branch March 12, 2026 14:43
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