Skip to content

Hosted macOS: stop leaves a LaunchServices copy from an earlier app attempt running #4127

Closed

Description

@janicduplessis

Problem

In a hosted macOS session, agent-device open <macos.host.bundleId> --remote-config <file> can launch a second copy of the app from an earlier app attempt's bundle in the same session. stim stop then reports "macOS app stopped" while that copy keeps running on the host, and stim worktree remove succeeds over it. The orphan also ignored SIGTERM for over 10 seconds.

Expected: per stim guide macos, every process running an app bundle from the workspace's directory is the workspace's owned app, including copies opened through LaunchServices (open, agent-device open), and stop ends all of them. For hosted sessions, either the host stops every process running from the session's apps/* bundles, or earlier attempts' bundles are unregistered or removed when a new attempt is delivered, so LaunchServices cannot resolve the shared <id>.hosted<slot> identifier to a stale copy.

Evidence

Mac mini on macOS 27.0 arm64, Stim 1.23.1 client and worker, agent-device 0.21.29, origin/main d7c2a9f. Steps:

  1. stim macos --remote-build janics-mac-mini --remote janics-mac-mini from apps/desktop (attempt 9ecccf52…, pid 60811).
  2. Ran it again after adding a launch argument (attempt a66039bd…, pid 69522). The first copy stopped as expected.
  3. agent-device disconnect and agent-device open dev.stim.desktop.development.hosted1 --platform macos --surface app with the session's remote config, around 01:04.
  4. stim stop, then stim worktree remove. Both reported success.

The host still had:

70192  ppid 1  started 01:04:19  …/device-host/sessions/b7c507a4-…/apps/9ecccf52-…/App.app/Contents/MacOS/StimDesktop

This is the first attempt's bundle, launched by LaunchServices with no arguments, while the second attempt (pid 69522) was running. SIGTERM did not end it within 10 s, and I removed it with SIGKILL after verifying the path was inside my own session.

Cause

Unconfirmed:

  • Both attempts' App.app bundles share the hosted bundle id dev.stim.desktop.development.hosted1, and the older one stays registered with LaunchServices.
  • agent-device open resolves by bundle id, so it can start the stale copy.
  • Hosted stop appears to stop only the recorded launch (supervisor child), not every process running from the session's bundles.

Fix idea

On hosted stop and on replacement, find every process whose executable lies under the session's apps/ directory, verifying identity as the local path does, and stop it with the documented SIGTERM, 5 s, SIGKILL sequence. Also remove or unregister superseded attempt bundles once their process exits. This preserves the one-app-per-workspace rule and the bundle-id slot reuse.

Activity

  1. added
    type: bugBreaks documented or expected behavior
    priority: P2Normal; default when unsure
    area: clipackages/stim-cli, including its README and guide
    on Oct 21, 2026
  2. janicduplessis commented on Oct 23, 2026

    @janicduplessis
    CollaboratorAuthor

    More evidence from 2026-10-22/23 on janics-mac-mini, stim-server 1.25.0:

    • Hosted macOS session 36b8fdfa (workspace .worktrees/4297-desktop) had journal state stopped, but its app process (pid 22793, bundle dev.stim.desktop.development.hosted1, started 17:00) was still running hours later.
    • The Keep a per-build ledger and show build history in Stim Desktop #4329 agent's own sessions 419929eb and 77c486df also left app processes running after stim stop, and it killed them by hand.
    • A later session reused app slot 1, so it had the same bundle id. Running agent-device open ... --relaunch against it probably ended the leftover process from 36b8fdfa.

    So a stopped hosted macOS session can leave its app running, and a later session can then share its bundle id with that orphan.

  3. janicduplessis commented on Oct 26, 2026

    @janicduplessis
    CollaboratorAuthor

    Possibly the same root cause, seen 2026-10-25 on janics-mac-mini while visually verifying PR #4381.

    • stim macos --remote-build janics-mac-mini --remote janics-mac-mini (global stim 1.27.0, mini stim-server 1.26.0): the first launch gave an inspectable window, with 34 AX nodes.
    • Every later launch, including after stim stop, agent-device close and a 20 s wait, gave 0 AX nodes and a frozen screenshot of the earlier state. agent-device press then failed with UNSUPPORTED_OPERATION: the point is outside the app's on-screen windows.
    • The relaunched app process was running: its client log showed the seeded payload. So agent-device is probably attached to a leftover copy from an earlier attempt, or the new copy has no on-screen window. Either way, a hosted macOS app can't be driven again after its first launch.
  4. janicduplessis commented on Oct 26, 2026

    @janicduplessis
    CollaboratorAuthor

    Claimed: fix/4127-hosted-macos-stop-apps-dir

  5. janicduplessis commented on Oct 26, 2026

    @janicduplessis
    CollaboratorAuthor

    2026-10-26 on janics-mac-mini (Stim 1.27.0 client): stim macos --remote-build janics-mac-mini --remote janics-mac-mini from apps/desktop, stim stop, then the same command again. The relaunch gave a drivable window (37 AX nodes, agent-device snapshot -i and screenshot working), so the 0 AX nodes / frozen screenshot symptom did not reproduce. One agent-device open right after the relaunch returned an error I did not capture; the next open succeeded.

    The orphan described in this issue is real in the code: hosted stop and install scan for running copies only under the workspace macos/ directory, not under the session's apps/<attempt> bundles. Fix in #4456, unverified on the mini because the worker code reaches it only through a stim-server release.

  6. github-actions commented on Oct 28, 2026

    @github-actions

    Released: stale claim, 2.2 days old (2026-10-26), with no open pull request for this issue.
    Branch fix/4127-hosted-macos-stop-apps-dir is not on origin.
    Posted by scripts/stale-claims.mjs. Comment Claimed: <branch> to take the issue.

  7. janicduplessis commented on Nov 1, 2026

    @janicduplessis
    CollaboratorAuthor

    Claimed: codex/4127-verify-hosted-stop. Verifying the already-merged #4456 cleanup on one owned hosted Desktop session on janics-mac-mini, including reopening an earlier owned attempt and stopping it. No shared server update or source change is planned unless current acceptance reveals a real gap.

  8. janicduplessis commented on Nov 1, 2026

    @janicduplessis
    CollaboratorAuthor

    Claim handoff: codex/4127-verify-hosted-stop is now owned by the Desktop runtime agent, continuing the existing verification-only claim. I will first trace current ownership/LaunchServices behavior, then use only an isolated owned Desktop session after the shared mini performance baseline finishes. No foreign apps or shared service changes.

  9. janicduplessis commented on Nov 1, 2026

    @janicduplessis
    CollaboratorAuthor

    Verified the existing fix on janics-mac-mini with Stim/stim-server 1.38.0, host build 6364c6c7fb0859df, and agent-device 0.21.35. No server update or product patch was needed.

    In one new owned hosted session:

    • Launched app attempt A normally, then opened a second copy from that exact bundle through LaunchServices. Both executables were verified under the session with ps and lsof; the extra copy had parent PID1.
    • Replaced A with attempt B using different launch arguments. Both A processes exited. B's actual arguments, worker-recorded PID, and native accessibility PID agreed, with an inspectable 34-node tree.
    • Reopened the retained old A bundle while B was running, verified both processes again, then ran stim stop. Neither process remained, and both attempts' app bundles were removed. No manual signals were sent.

    This verifies #4456's stop boundary and replacement boundary. The installed build predates #4682, so this does not claim to validate its additional replacement-time pruning.

    The older stale accessibility snapshot symptom did not reproduce: fresh named automation sessions matched A's normal window/PID and B's playground window/PID. Temporary arguments were restored, the owned session stopped, and no unrelated app or device was touched. Closing as addressed by the existing fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: clipackages/stim-cli, including its README and guidearea: serverpackages/serverpriority: P2Normal; default when unsuretype: bugBreaks documented or expected behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions