Mail Extension not always recognised

Hello, we developed a Mail Extension as part of our product but, unfortunately, sometimes it is not recognized by the operating system. We still do not have a solid reproducer but I believe it is related to the automatic plugin discovery.

We can reliably reproduce the scenario on one dev machine only - we tried several reinstalls of the app, unfortunately with no change in the plugin's discovery behavior. We use .pkg installer created using Packages.

In the console logs, I can see several messages related to the plugin:

  1. Installer launched,
  2. logs that the application's plugin was discovered by LaunchServices, and a plugin notification was sent (com.apple.LaunchServices.pluginsregistered),
  3. logs that the plugin was found by Finder, NotificationCenter, pkd, Google Chrome, and other apps' LaunchServices observers,
  4. a message that mod date of the application has changed followed by the application unregister notification (com.apple.LaunchServices.applicationUnregistered),
  5. application register notifications again (com.apple.LaunchServices.applicationRegistered) but without any plugin-related messages.

Not sure what is going on at points (4) and (5) or if the apps found at (2) were some leftovers removed by the installer (which should not be the case as it was always a clean install). Also, whether the Mail app runs during the installation or not, makes no difference. It does not know about the extension in any case. The plugin is neither in the Mail's settings nor listed in its console logs. Command pluginkit -m -D -i <bundle id> -v does not return any match either.

On other machines, the problem occurs only with very few installations. When it does, a restart of the Mail app does not help, nor restart of the app which contains the plugin. Sometimes it starts working when the parent app is restarted using launchctl. Registering the plugin manually using pluginkit -a <path to appex> works every time.

Does anybody experienced similar behavior or know what could be the cause? Thanks for any tips.