Clarification on Workflow Patching/Versioning in Python

Looking for clarification on this part of the documentation:

Specifically, when can we deploy workflow.deprecate_patch("my-patch").

Looks like there is 4 states:

  1. Initial (pre-patch)
  2. Patched
  3. Deprecated
  4. Removed Patched / Final

When going from PatchedDeprecated, the docs says:

After ensuring that all Workflows started with pre_patch_activity code have left retention, you can deprecate the patch.

It says “retention”, does it mean that we cannot deploy a deprecated_patch’d code until ALL pre-patch workflows (even completed ones) is removed from Temporal History? Or could we safely deploy a deprecated_patch’d as soon as all workflows are running the Patched code (regardless if there are any pre-patched workflows that are completed in Temporal History)?

Also, the same question apply for DeprecatedRemoved Patched. It also uses the word
”retention”.

i think for both cases you mention, if for your use case you do not need to query (workflow query) closed executions, you can deploy when there are no running workflows. otherwise until they are removed (closed workflows removed when they hit namespace retention period)