MacOS services failed to start after reboot

Hello I have an App in macOS that is based on two services The first is running as a Daemon The second running as Agent(GUI) I use a script in my app installer (postinstall) that copies the plist files into the folders /Library/LaunchDaemons /Library/LaunchAgents/ And then run for the Daemons: launchctl load <plist file path> And for each user who is currently connected su <user name> -c "launchctl load <plist file path> That is working.

But when I reboot my machine only the Daemons is running The Agent is not running and in the log "launchctl" There are errors that i can not find any documentation or explanation

2024-01-04 08:01:11.047284 (gui/503 [100004]) <Notice>: Bootstrap by launchctl[1769] for /Library/LaunchAgents/com.sysaid.SessionUtilities.plist succeeded (0: )
2024-01-04 08:01:11.047289 (gui/503 [100004]) <Notice>: exiting bootstrap mode
2024-01-04 08:01:11.047299 (gui/503/SysAid.Agent [1771]) <Notice>: internal event: SOURCE_ATTACH, code = 0
2024-01-04 08:01:11.048031 (user/503) <Notice>: service inactive: com.apple.xpc.launchd.unmanaged.su.1768
2024-01-04 08:01:11.048039 (user/503) <Notice>: removing inactive unmanaged service: com.apple.xpc.launchd.unmanaged.su.1768
2024-01-04 08:01:11.050192 (gui/503/SysAid.Agent [1771]) <Notice>: Requesting first run LWCR update
2024-01-04 08:01:11.064345 (pid/1759 [AgentCPP]) <Notice>: uncorking exec source upfront
2024-01-04 08:01:11.064352 (pid/1759 [AgentCPP]) <Notice>: created
2024-01-04 08:01:11.085689 (gui/503/SysAid.Agent [1771]) <Error>: Service could not initialize: Unable to verify trusted spawn(/Applications/SysAid Helpdesk.app/Contents/MacOS/AgentSessionUtilities, /Library/LaunchAgents/com.sysaid.SessionUtilities.plist, SysAid.Agent, 3, 503), error 0xa1 - Service cannot be launched because of BTM policy
2024-01-04 08:01:11.085697 (gui/503/SysAid.Agent [1771]) <Error>: initialization failure: 23C71: xpcproxy + 31472 [460][6960F486-3261-3A05-9150-1B1F72E3ADB0]: 0xa1
2024-01-04 08:01:11.085698 (gui/503/SysAid.Agent [1771]) <Error>: Untrusted service was denied launch by BTM. Removing.
2024-01-04 08:01:11.085699 (gui/503/SysAid.Agent [1771]) <Notice>: internal event: INIT, code = 161
2024-01-04 08:01:11.086095 (gui/503/SysAid.Agent [1771]) <Notice>: xpcproxy exited due to exit(78)
2024-01-04 08:01:11.086101 (gui/503/SysAid.Agent [1771]) <Notice>: exited due to exit(78)
2024-01-04 08:01:11.086106 (gui/503/SysAid.Agent [1771]) <Notice>: already handled failed init, ignoring
2024-01-04 08:01:11.086115 (gui/503/SysAid.Agent [1771]) <Notice>: service state: exited
2024-01-04 08:01:11.086123 (gui/503/SysAid.Agent [1771]) <Notice>: internal event: EXITED, code = 0
2024-01-04 08:01:11.086127 (gui/503 [100004]) <Notice>: service inactive: SysAid.Agent
2024-01-04 08:01:11.086131 (gui/503 [100004]) <Notice>: removing service: SysAid.Agent
2024-01-04 08:01:11.086151 (gui/503/SysAid.Agent [1771]) <Notice>: internal event: PETRIFIED, code = 0
2024-01-04 08:01:11.086155 (gui/503/SysAid.Agent [1771]) <Notice>: service state: not running

The app and the Installer signed and notarized Can you help me figure out what I'm missing

Replies

And for each user who is currently connected su …

I’m surprised that works. su only switches the BSD components of your execution context [1], and launchctl relies on stuff beyond that.

2024-01-04 08:01:11.085698 (gui/503/SysAid.Agent [1771]) <Error>: Untrusted service was denied launch by BTM. Removing.

This suggests that your agent is being blocked by the backtrace task infrastructure we added in macOS 13. In this context BTM stands for Background Task Management. This is the same meaning used by sfltool in its dumpbtm and resetbtm subcommands.

If you disable the above-mentioned su stuff and instead always restart after installation, does your agent load?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] As described in the Execution Contexts section of Technote 2083 Daemons and Agents.