SMAppService fails to register agent with MDM

I have a menu bar app which should be triggered to start when a system extension is successfully installed.

The menu bar app is configured as a agent which should be started by SMAppServer.

SMAppService register/unregister the agent successfully when the program is running locally.

When doing the program installation through JamfNow, which is a MDM system, it fails with following error.

I think the problem here is that the backgroundtaskmanagementd trys to register the agent with an invalid uid=-1 or uid: 4294967295(0xFFFFFFFF).

2024-10-02 10:45:33.100537+0200 0x156d4    Activity    0x1b927              88     0    smd: (BackgroundTaskManagement) BTMManager.getEffectiveDisposition
2024-10-02 10:45:33.103478+0200 0x156dd    Default     0x1b927              282    0    backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] effectiveItemDisposition: appURL=file:///Applications/Company%20Agent.app/, type=agent, url=Contents/Library/LaunchAgents/com.Company.agent.notifier.plist -- file:///, config={
    BTMConfigArguments =     (
    );
    BTMConfigBundleIdentifiers =     (
    );
    BTMConfigExecutablePath = "Contents/Resources/CompanyNotifier.app/Contents/MacOS/CompanyNotifier";
    BTMConfigLabel = "com.Company.agent.notifier";
}
2024-10-02 10:45:33.103544+0200 0x156dd    Info        0x1b927              282    0    backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] effectiveItemDisposition: result=[disabled, allowed, visible, not notified]
2024-10-02 10:45:33.105120+0200 0x156d4    Default     0x1b927              88     0    smd: (BackgroundTaskManagement) [com.apple.backgroundtaskmanagement:main] getEffectiveDisposition: disposition=[disabled, allowed, visible, not notified], have LWCR=true
2024-10-02 10:45:33.105181+0200 0x156d4    Default     0x0                  88     0    smd: [com.apple.xpc.smd:all] Found status: 0 for <private>
2024-10-02 10:45:33.240190+0200 0x154da    Default     0x0                  88     0    smd: [com.apple.xpc.smd:SMAppServiceFactory] Setting up BundleProgram keys for <private>
2024-10-02 10:45:33.240250+0200 0x154da    Default     0x0                  88     0    smd: [com.apple.xpc.smd:SMAppServiceFactory] Setting up BundleProgram keys for <private>
2024-10-02 10:45:33.240388+0200 0x154da    Activity    0x1b92a              88     0    smd: (BackgroundTaskManagement) BTMManager.registerLaunchItemWithAuditToken
2024-10-02 10:45:33.243990+0200 0x156dd    Default     0x1b92a              282    0    backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] registerLaunchItem: pid=3626, uid=-1, type=agent, parentURL=<private>, url=<private>, config=<private>
2024-10-02 10:45:33.244917+0200 0x156dd    Default     0x1b92a              282    0    backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] registerLaunchItem: found existing item: uuid=AC0DBC9B-7A16-443E-ABFC-05DF0F534C08, name=CompanyNotifier, type=managed agent, disposition=[disabled, allowed, visible, notified], identifier=com.Company.agent.notifier, url=Contents/Library/LaunchAgents/com.Company.agent.notifier.plist -- file:///
2024-10-02 10:45:33.245238+0200 0x156dd    Debug       0x1b92a              282    0    backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] BTMStore: save scheduled.
2024-10-02 10:45:33.245281+0200 0x156dd    Debug       0x1b92a              282    0    backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] RecordSet notification scheduled for uid -1
....
2024-10-02 10:45:33.252358+0200 0x154da    Error       0x0                  88     0    smd: [com.apple.xpc.smd:SMAppService] Unable to submit job: <private> error: Error Domain=OSLaunchdErrorDomain Code=112 UserInfo={NSLocalizedFailureReason=<private>}
2024-10-02 10:45:33.252707+0200 0x156d4    Default     0x1b92a              88     0    smd: [com.apple.xpc.smd:all] Update request for identifier: <private> uid: 4294967295
2024-10-02 10:45:33.253190+0200 0x156dd    Default     0x1b92a              282    0    backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] getItemWithIdentifier: identifier=com.Company.agent.notifier, uid=-1
2024-10-02 10:45:33.253759+0200 0x156d4    Error       0x1b92a              88     0    smd: [com.apple.xpc.smd:btm] Error getting BTMItem with Identifier: <private> uid: 4294967295 error: (null)
2024-10-02 10:45:33.253803+0200 0x156d4    Error       0x1b92a              88     0    smd: [com.apple.xpc.smd:all] Unable to find BTMItem for <private> in 4294967295
2024-10-02 10:45:33.253835+0200 0x156d4    Error       0x1b92a              88     0    smd: [com.apple.xpc.smd:all] Update operation returned error: 3, but no reply expected so error will be silent
2024-10-02 10:45:33.661537+0200 0x156dd    Debug       0x0                  282    0    backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] sending notification for uid -1, type 131080
2024-10-02 10:45:33.665159+0200 0x154fa    Info        0x1b853              282    0    backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] fetchSFLItemsMatching: type=managed user item app
2024-10-02 10:45:33.665374+0200 0x154fa    Activity    0x15dd3              282    0    backgroundtaskmanagementd: (BackgroundTaskManagement) BTMManager.userDataDidChange
2024-10-02 10:45:33.666041+0200 0x154da    Activity    0x1b92d              88     0    smd: (BackgroundTaskManagement) BTMManager.userDataDidChange
2024-10-02 10:45:33.666651+0200 0x154fa    Debug       0x15dd3              282    0    backgroundtaskmanagementd: (BackgroundTaskManagement) [com.apple.backgroundtaskmanagement:main] -[BTMManager handleUserDataDidChangeNotification:]: uid=-1, type=131080
2024-10-02 10:45:33.666085+0200 0x154da    Debug       0x1b92d              88     0    smd: (BackgroundTaskManagement) [com.apple.backgroundtaskmanagement:main] -[BTMManager handleUserDataDidChangeNotification:]: uid=-1, type=131080
2024-10-02 10:45:36.218160+0200 0x154fa    Debug       0x0                  282    0    backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] -[BTMStore handleWriteTimer] entered
2024-10-02 10:45:36.218254+0200 0x154fa    Debug       0x0                  282    0    backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] -[BTMStore _save] entered
2024-10-02 10:45:36.224738+0200 0x154fa    Default     0x0                  282    0    backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] BTMStore: store saved to /var/db/com.apple.backgroundtaskmanagement/BackgroundItems-v9.btm

Could it be a problem from the MDM system JamfNow or somewhere else?

The whole logs is as attached.

Thanks!

Registering the menu bar app as login item through JamfNow has the similar behavior: uid=-1

In order to investigate this we'll need more diagnostic information. Would you please reproduce the issue, capture a sysdiagnose, and submit feedback? This post has all the information you need in order to do that.

The feedback has been submitted with bug number FB15488021

The feedback has been submitted with bug number FB15488021

I believe it is not possible to use SMAppService.agent from a process that is not running in the console. That is why you can get it to work when you launch it, but not when installing from an MDM. https://forums.developer.apple.com/forums/thread/737038

SMAppService fails to register agent with MDM
 
 
Q