Pattern to trigger continue-as-new after worker upgrade

I’ve just started using Temporal for a chat bot, with one workflow per chat session, which can last months. Once a new worker version is deployed, I would like every running workflow to call continue-as-new as soon as possible. This way I don’t have to handle patches or older deployments for more than one previous version and I find it easier to reason about.

The best way I could figure out how to do this is for an external supervisor thread to send a signal to every running workflow with the current worker version, and to supply the current version as input to every workflow. If they don’t match, continue-as-new is triggered. So like this pseudo code:

VERSION = "v1"

class Workflow:
   def run(self, version):
       self.version = version
       self.needs_upgrade = False

       await workflow.wait_condition(lambda: self.needs_upgrade)
       workflow.continue_as_new(VERSION)

   @workflow.signal
   def loaded(self, worker_version):
       if self.version != worker_version:
           self.needs_upgrade = True

def supervisor():
   for handle in all_workflows:
      handle.signal("loaded", VERSION)

Another way I tried doing it which seemed more hacky was:

if not workflow.unsafe.is_replaying() and self.version != VERSION:
   self.needs_upgrade = True

I wonder if there is a better way of handling this? It would be ideal if the worker versioning system could somehow provide the information that a new version is available, perhaps as part of the call to is_continue_as_new_suggested().