Launching a signed AppKit app from a Python supervisor while preserving instance ownership and bounded cleanup

I'm looking for a supported way to launch a signed AppKit application for user interaction from a local Python supervisor, while retaining reliable supervision of the exact launched instance.

Environment

  • Apple M3 MacBook Air, macOS 14.5, build 23F79.
  • arm64 app built with Command Line Tools clang and the macOS 14.5 SDK, targeting macOS 14.0.
  • AppKit/Foundation with embedded CPython 3.12.
  • Apple Development signing, hardened runtime and strict signature checks passed.

Current launch and activation sequence

The supervisor directly launches the bundle executable with Popen: a fixed argument, empty environment, new process session, disconnected stdin, and an anonymous stdout pipe carrying fixed, nonsecret startup markers. There is no LaunchServices foreground handoff.

On its main thread, the app initializes NSApplication, confirms Regular activation policy, calls finishLaunching and activateIgnoringOtherApps:YES, then waits for isActive. Event-retrieval waits are capped at 20 ms; event dispatch itself may take longer. Existing timeout supervision remains active.

Our activation guard is two seconds from the readiness routine's start, subject to the remaining native timer. A separate overall test budget is 300 seconds from operator readiness, before preflight.

Observed result

The latest test exited with code 1 after approximately 2.57 seconds. The validated markers were:

absence.begin → absence.absent → fields.begin → ui.begin
→ app.shared.begin → app.shared.ready
→ policy.before → policy.already_regular → policy.postcondition
→ launch.finish.begin → launch.finish.ready
→ activation.requested → activation.wait.begin
→ stop.activation.timeout

The final recorded state was:

main=1 app=1 active=0 policy=0 window=0 visible=-1 key=-1

The app stopped before constructing the dialog. Adding event processing did not resolve activation. We have not established why activation failed or which events were delivered. The two-second deadline is our guard, not an asserted macOS activation guarantee.

Questions

  1. What supported launch and activation approach should this supervisor use for a foreground, interactive AppKit app?
  2. Can this direct-executable design be corrected narrowly, or should launching move to LaunchServices with a different communication and supervision arrangement?
  3. With the recommended approach, how should the supervisor identify the exact launched instance, receive startup status, enforce bounded termination, and establish that the process has exited before cleanup?

We reviewed a simple foreground-launch substitution, but it did not preserve our existing marker pipe and authoritative exit/reap evidence. That is a limitation of our proposed adaptation, not a claim that Apple's APIs cannot support these outcomes.

The essential requirements are exact-instance identification, nonsecret status reporting, bounded termination and verified cleanup. An anonymous pipe and direct-child waiting are current implementation choices, not requirements in themselves.

Answered by DTS Engineer in 917342022

The key question here is fidelity. You’re running the app as a child process. That’s not how apps are normally launched, and it can definitely affect the app’s behaviour [1]. So you have a trade-off to make:

  • Run the app as a child process, which gives you more control but means that the app won’t necessarily behave normally.
  • Run the app using NSWorkspace, which gives you less control but means that the app runs much as it would if you ran it from the Finder.

Note that NSWorkspace will give you back an NSRunningApplication instance, and from that you can get the pid. Annoyingly, there’s no way to get an audit token from it but, as the documentation for processIdentifier explains, you can use isEqual: to check for identity in a way that guards against pid reuse.

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

[1] I’ve seen this crop up in a number of different ways:

  • The app uses a lot of file descriptors, and thus bumps into the file descriptor limit in one case or the other.
  • The app relies on the current working directory.
  • The app relies on std{in,out,err}.

The key question here is fidelity. You’re running the app as a child process. That’s not how apps are normally launched, and it can definitely affect the app’s behaviour [1]. So you have a trade-off to make:

  • Run the app as a child process, which gives you more control but means that the app won’t necessarily behave normally.
  • Run the app using NSWorkspace, which gives you less control but means that the app runs much as it would if you ran it from the Finder.

Note that NSWorkspace will give you back an NSRunningApplication instance, and from that you can get the pid. Annoyingly, there’s no way to get an audit token from it but, as the documentation for processIdentifier explains, you can use isEqual: to check for identity in a way that guards against pid reuse.

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

[1] I’ve seen this crop up in a number of different ways:

  • The app uses a lot of file descriptors, and thus bumps into the file descriptor limit in one case or the other.
  • The app relies on the current working directory.
  • The app relies on std{in,out,err}.

Thanks, Quinn. Your distinction between a child-process launch and an NSWorkspace launch was helpful. We have a few focused follow-up questions about supervising an NSWorkspace-launched app:

  1. Is there a documented way to cancel or bound an outstanding asynchronous launch? If its completion arrives after the supervisor’s original deadline, what supported pattern would you recommend for handling that late completion and any resulting app instance?
  2. For an app that is not the supervisor’s direct child, what supported pattern would you recommend for identifying the exact launched instance and observing confirmed termination, including PID reuse and an instance that exits before observation is established?
  3. Can those outcomes reasonably be achieved with a narrowly scoped integration, without a separate foreground GUI bridge or process reparenting? If not, what minimum broader change would you suggest?

We understand that we still need to independently design and validate authenticated, per-attempt status reporting, admission against the original deadline, and cleanup. We are not assuming NSRunningApplication alone proves launch provenance, authorized control, or cleanup.

Written by CarlosDevLab in 917409022

1- Is there a documented way to cancel or bound an outstanding asynchronous launch?

That depend on how you define “asynchronous launch”:

  • NSWorkspace should call its completion handler promptly and that gives you an NSRunningApplication instance. You can use that terminate the launched process.
  • However, there’s no way to cancel the operation between the point where you call NSWorkspace and the point where it calls your completion handler.
  • However, I wouldn’t expect to see a large delay there. The completion handler doesn’t wait for the app to complete its launch cycle. It’ll be called shortly after the launched process is started.
Written by CarlosDevLab in 917409022

2- … what supported pattern would you recommend for identifying the exact launched instance …

NSRunningApplication. See the discussion above and in my previous response.

Written by CarlosDevLab in 917409022

3- Can those outcomes reasonably be achieved … ?

I don’t see why not.

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

Hi Quinn,

Thank you again for your guidance. I wanted to briefly clarify our overall goal so we can identify the simplest supported solution rather than continue experimenting with launch methods.

We’re building a local, owner-operated credential application for a supervised trading DEMO system. The credential UI runs separately from our Python supervisor, and we need to prevent unauthorized or late credential operations.

Our current blocker:

Launching the signed AppKit app directly as a supervised child preserves process ownership, startup messages and exit verification, but macOS 14.5 never reports the app as active. It reaches our two-second activation deadline and exits before displaying the credential window.

Your NSWorkspace recommendation provides a promising alternative, but we haven’t established how to preserve the required supervision protections.

Our three essential requirements are:

  1. Safe admission: An application launched late cannot perform credential operations after the supervisor’s original deadline.
  2. Authenticated communication: Authorization and nonsecret status messages must be bound to the exact launched application instance.
  3. Verified termination: The supervisor must distinguish requesting termination from observing the application’s actual exit and confirming cleanup.

Would you recommend NSWorkspace combined with XPC or another authenticated local IPC mechanism, with the application enforcing the original admission deadline? Or is there a simpler Apple-supported pattern?

If macOS doesn’t guarantee these outcomes directly, which parts should our application enforce itself?

A recommended architecture or relevant Apple example would be extremely helpful. We’re trying to avoid unnecessary helper applications or redesigning unrelated components.

Thank you for your time and guidance.