Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): wait for launchd shutdown safely #7874

Closedlastobelus(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/7874/headopened View on GitHub

What Changed

  • use the supported launchctl bootout <service-target> form
  • wait for launchctl print to confirm the exact job has left the user domain before enabling and bootstrapping it again
  • bound shutdown verification to 120 seconds and surface timeout, permission, domain, and unexpected-output failures
  • keep the already-absent case idempotent only when launchd returns its exact not-loaded response

Why

launchctl bootout can return while a job is still honoring its plist shutdown timeout. Immediately bootstrapping the replacement can then race the draining process and fail. The prior --wait argument is not a supported launchctl option, and treating stop/enable failures as optional could hide real lifecycle failures.

This keeps install and uninstall deterministic without changing the service definition or launching anything during tests.

Validation

  • 21 focused boot-service tests
  • server typecheck
  • targeted lint, formatting, and diff checks

Checklist

  • This PR is small and focused
  • I explained what changed and why

LastCode counterpart: lastobelus/lastCode#56.

Implemented by OpenAI Codex (GPT-5.6) in the T3 Code Codex harness.


Note

Medium Risk Changes macOS launch-agent stop/start sequencing, which can affect background service install, repair, and uninstall if launchctl output or timing is misclassified.

Overview Stops racing a draining macOS launch agent on reinstall. launchctl bootout no longer uses the unsupported --wait flag; the flow polls launchctl print until launchd confirms the exact job left the user domain (or 120s timeout).

Optional stop/enable steps are gone. Already-absent is treated as success only on launchd’s exact not-loaded / no-such-process messages. Permission, missing-domain (on install), unexpected print output, and timeout now fail closed with a clearer BootServiceCommandError. Uninstall still succeeds when the GUI domain itself is missing.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 7c5adc45ea3ee7456e04339430c2433e3486ffd7. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Replace launchctl bootout --wait with polling verification in BootService

  • Removes the --wait flag from launchctl bootout (not supported by macOS) and replaces it with explicit polling of launchctl print until launchd confirms the agent is absent, bounded by STOP_STEP_TIMEOUT (120s)
  • Introduces isConfirmedLaunchdNotLoaded and isConfirmedLaunchdBootoutNotLoaded to distinguish benign not-loaded responses from real errors by exact stderr/stdout text matching
  • Replaces the optional step flag with a tagged operation: 'launchd-bootout' union carrying verifyAbsent metadata; runLaunchdBootout dispatches bootout, tolerates only specific not-loaded conditions, then polls for confirmation
  • Adds timedOut field to BootServiceCommandError so timeout failures render a clear message
  • Risk: optional: true is removed entirely — launchctl enable failures now abort the flow instead of being ignored; all BootServiceStep call sites must specify operation: 'launchd-bootout' with verifyAbsent data for launchd stop steps
Macroscope summarized 7c5adc4.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 73b2f920-f58b-4062-94f7-403d2e26be8d

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. 💡 Codex Review

      Here are some automated review suggestions for this pull request.

      Reviewed commit: 7eaa23c233

      ℹ️ About Codex in GitHub

      Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

      • Open a pull request for review
      • Mark a draft as ready
      • Comment "@codex review".

      If Codex has suggestions, it will comment; otherwise it will react with 👍.

      Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    4. Approvability

      Verdict: Skipped

      Macroscope did not run approvability analysis for this PR. Macroscope could not determine whether this PR modifies its approvability configuration, so the PR was not approved automatically. A PR that may change the rules that govern approval is never approved automatically.

    5. Codex Review: Didn't find any major issues. Chef's kiss.

      Reviewed commit: 7c5adc45ea

      ℹ️ About Codex in GitHub

      Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

      • Open a pull request for review
      • Mark a draft as ready
      • Comment "@codex review".

      If Codex has suggestions, it will comment; otherwise it will react with 👍.

      Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    6. juliusmarminge closed this

    7. Closing as part of the open-PR backlog sweep (wave 1).

      Reason: launchctl bootout --wait already on main Related: main bootService.ts

      Reopen if this is still wanted and you’re willing to rebase onto current main.

Sign in to join this conversation.