Skip to content

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

Open
lastobelus wants to merge 1 commit into
pingdotgg:mainfrom
lastobelus:fix/launchd-lifecycle
Open

fix(server): wait for launchd shutdown safely#7874
lastobelus wants to merge 1 commit into
pingdotgg:mainfrom
lastobelus:fix/launchd-lifecycle

Conversation

@lastobelus

@lastobelus lastobelus commented Aug 22, 2026

Copy link
Copy Markdown

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 for commit 7c5adc4. Bugbot is set up for automated code reviews on this repo. Configure here.

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.

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

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.

@lastobelus

Copy link
Copy Markdown
Author

@codex review

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 22, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread apps/server/src/cloud/bootService.ts
@macroscopeapp

macroscopeapp Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

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.

@lastobelus
lastobelus force-pushed the fix/launchd-lifecycle branch from 7eaa23c to 7c5adc4 Compare August 22, 2026 05:31
@lastobelus

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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".

lastobelus added a commit to lastobelus/lastCode that referenced this pull request Aug 22, 2026
LastCode inherits the same macOS background-service lifecycle race as
upstream: `launchctl bootout` can return before the old job finishes
draining, while the prior unsupported `--wait` form and optional-error
handling can let reinstall proceed without proving the job is gone.

This is the patch-identical LastCode port of [upstream PR
pingdotgg#7874](pingdotgg#7874), from upstream
commit
[`7c5adc45ea3ee7456e04339430c2433e3486ffd7`](7c5adc4).
It uses supported `launchctl bootout`, polls the exact service with
`launchctl print` until launchd confirms absence, and fails closed on
timeout, permission, domain, or unexpected-output errors before enabling
and bootstrapping.

Provenance:

- upstream commit: `7c5adc45ea3ee7456e04339430c2433e3486ffd7`
- stable patch ID: `e5e07203e79b88a6051cc6eea2159118e4486604`
- LastCode port commit: `f52d715a97460fca99afaebc522788a85a8ae1c0`

Progresses #39.

Validation:

- 21 focused boot-service tests
- server typecheck
- targeted lint, formatting, and diff checks
- guarded `pnpm lastcode:ci:quick` pre-push gate

Implemented by OpenAI Codex (GPT-5.6) in the T3 Code Codex harness.
lastobelus added a commit to lastobelus/lastCode that referenced this pull request Aug 22, 2026
LastCode inherits the same macOS background-service lifecycle race as
upstream: `launchctl bootout` can return before the old job finishes
draining, while the prior unsupported `--wait` form and optional-error
handling can let reinstall proceed without proving the job is gone.

This is the patch-identical LastCode port of [upstream PR
pingdotgg#7874](pingdotgg#7874), from upstream
commit
[`7c5adc45ea3ee7456e04339430c2433e3486ffd7`](7c5adc4).
It uses supported `launchctl bootout`, polls the exact service with
`launchctl print` until launchd confirms absence, and fails closed on
timeout, permission, domain, or unexpected-output errors before enabling
and bootstrapping.

Provenance:

- upstream commit: `7c5adc45ea3ee7456e04339430c2433e3486ffd7`
- stable patch ID: `e5e07203e79b88a6051cc6eea2159118e4486604`
- LastCode port commit: `f52d715a97460fca99afaebc522788a85a8ae1c0`

Progresses #39.

Validation:

- 21 focused boot-service tests
- server typecheck
- targeted lint, formatting, and diff checks
- guarded `pnpm lastcode:ci:quick` pre-push gate

Implemented by OpenAI Codex (GPT-5.6) in the T3 Code Codex harness.
lastobelus added a commit to lastobelus/lastCode that referenced this pull request Aug 22, 2026
LastCode inherits the same macOS background-service lifecycle race as
upstream: `launchctl bootout` can return before the old job finishes
draining, while the prior unsupported `--wait` form and optional-error
handling can let reinstall proceed without proving the job is gone.

This is the patch-identical LastCode port of [upstream PR
pingdotgg#7874](pingdotgg#7874), from upstream
commit
[`7c5adc45ea3ee7456e04339430c2433e3486ffd7`](7c5adc4).
It uses supported `launchctl bootout`, polls the exact service with
`launchctl print` until launchd confirms absence, and fails closed on
timeout, permission, domain, or unexpected-output errors before enabling
and bootstrapping.

Provenance:

- upstream commit: `7c5adc45ea3ee7456e04339430c2433e3486ffd7`
- stable patch ID: `e5e07203e79b88a6051cc6eea2159118e4486604`
- LastCode port commit: `f52d715a97460fca99afaebc522788a85a8ae1c0`

Progresses #39.

Validation:

- 21 focused boot-service tests
- server typecheck
- targeted lint, formatting, and diff checks
- guarded `pnpm lastcode:ci:quick` pre-push gate

Implemented by OpenAI Codex (GPT-5.6) in the T3 Code Codex harness.
lastobelus added a commit to lastobelus/lastCode that referenced this pull request Aug 22, 2026
LastCode inherits the same macOS background-service lifecycle race as
upstream: `launchctl bootout` can return before the old job finishes
draining, while the prior unsupported `--wait` form and optional-error
handling can let reinstall proceed without proving the job is gone.

This is the patch-identical LastCode port of [upstream PR
pingdotgg#7874](pingdotgg#7874), from upstream
commit
[`7c5adc45ea3ee7456e04339430c2433e3486ffd7`](7c5adc4).
It uses supported `launchctl bootout`, polls the exact service with
`launchctl print` until launchd confirms absence, and fails closed on
timeout, permission, domain, or unexpected-output errors before enabling
and bootstrapping.

Provenance:

- upstream commit: `7c5adc45ea3ee7456e04339430c2433e3486ffd7`
- stable patch ID: `e5e07203e79b88a6051cc6eea2159118e4486604`
- LastCode port commit: `f52d715a97460fca99afaebc522788a85a8ae1c0`

Progresses #39.

Validation:

- 21 focused boot-service tests
- server typecheck
- targeted lint, formatting, and diff checks
- guarded `pnpm lastcode:ci:quick` pre-push gate

Implemented by OpenAI Codex (GPT-5.6) in the T3 Code Codex harness.
lastobelus added a commit to lastobelus/lastCode that referenced this pull request Aug 22, 2026
LastCode inherits the same macOS background-service lifecycle race as
upstream: `launchctl bootout` can return before the old job finishes
draining, while the prior unsupported `--wait` form and optional-error
handling can let reinstall proceed without proving the job is gone.

This is the patch-identical LastCode port of [upstream PR
pingdotgg#7874](pingdotgg#7874), from upstream
commit
[`7c5adc45ea3ee7456e04339430c2433e3486ffd7`](7c5adc4).
It uses supported `launchctl bootout`, polls the exact service with
`launchctl print` until launchd confirms absence, and fails closed on
timeout, permission, domain, or unexpected-output errors before enabling
and bootstrapping.

Provenance:

- upstream commit: `7c5adc45ea3ee7456e04339430c2433e3486ffd7`
- stable patch ID: `e5e07203e79b88a6051cc6eea2159118e4486604`
- LastCode port commit: `f52d715a97460fca99afaebc522788a85a8ae1c0`

Progresses #39.

Validation:

- 21 focused boot-service tests
- server typecheck
- targeted lint, formatting, and diff checks
- guarded `pnpm lastcode:ci:quick` pre-push gate

Implemented by OpenAI Codex (GPT-5.6) in the T3 Code Codex harness.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant