Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): macOS boot service stops the launch agent without bootout --wait #26088

Openjuliusmarmingewants to merge 10 commits intomain fromrefs/pull/26088/headopened View on GitHub

juliusmarmingecommented

Problem

On macOS 15, launchctl bootout --wait <service-target> is a usage error: it exits 64 and stops nothing. The launchd boot service ran exactly that as an optional stop step, so the error was ignored and the strict launchctl bootstrap that follows failed with EIO (exit 5) because the old job still held the label. t3 service install over a loaded agent, t3 update, restart and failed-update recovery all failed, and t3 service uninstall left the job loaded. Reported on macOS 15.7.9 (Darwin 24.6.0) with boot-service.log showing exit 64, then exit 5.

Change

  • The launchd stop and deactivate steps run plain launchctl bootout <service-target>.
  • They then poll launchctl print <service-target> every 500 ms until the label is gone, within the existing 120 s stop timeout. Only a print that runs and exits non-zero ends the wait; one that fails to run or times out keeps it polling. A plain bootout can return while the job is still draining through ExitTimeOut, either with exit 0 or with 36 (EINPROGRESS), and a bootstrap during the drain fails EIO.
  • The step succeeds once the label is gone, whatever bootout exited with. An agent that is not loaded stays a no-op: one print call. The step is no longer optional, so an agent still loaded at the 120 s deadline fails install, restart and uninstall instead of letting them bootstrap over it or delete its plist.
  • BootServiceStep gains one optional field, waitWhile, which runSteps handles. systemd is unchanged.

Scope and approval

Fixes pingdotgg/t3code#11995

The maintainer confirmed the bug and the fix direction on the issue: drop --wait, then bootout and poll launchctl print within the 120 s stop timeout.

Verification

  • vp test run apps/server/src/cloud/bootService.test.ts at 9eab482907: 38 passed.
  • The test harness now models macOS 15 launchctl at the process-runner level:
    • any --wait exits 64 and changes nothing;
    • bootout of an unloaded job exits 3;
    • a booted-out job that is still draining makes bootout exit 36 and keeps print succeeding;
    • bootstrap over a loaded label exits 5.
  • New tests:
    • reinstall over a loaded agent;
    • uninstall unloads the agent;
    • a draining agent is waited for before bootstrap;
    • a print that times out while the agent drains does not end the wait;
    • an agent still loaded at the deadline fails uninstall and keeps its plist.
  • Against main's bootService.ts, the PR's tests fail 9 of 38: the five new tests, plus four existing darwin tests that now use the launchctl model. The earlier commit that skipped the wait after a non-zero bootout failed the drain test, 993cfc5edd failed the print-timeout test, and 47e0f56777 failed the deadline test.
  • vp run check:changed passes.
  • No visible surface, so no captures.
  • cannot-verify macos: no Mac is available here, so real launchctl was not run. The exit codes in the model come from the report (64, 5) and from launchctl's known behaviour (3, 36, 113).
Test transcript at 993cfc5edd (PR tests against main's bootService.ts, then against the branch head; later commits add two tests: 9 failed / 29 passed against main, 38 passed at 9eab482907)
# #11995 proof transcript (Linux VM; launchctl modelled at the ProcessRunner level; real macOS not available)
# 1) PR tests against main's bootService.ts (d1c4b52b7c)
[18:59:53.314] ERROR (#140): Error [AssertionError]: expected [ …(2) ] to deeply equal [ …(3) ]
  step: 'starting the service',
  exitCode: 5,
[18:59:53.604] ERROR (#331): Error [AssertionError]: expected undefined to deeply equal { _id: 'Duration', …(2) }
[18:59:53.696] ERROR (#372): Error [AssertionError]: expected { _id: 'Option', _tag: 'Some', …(1) } to deeply equal { _id: 'Option', _tag: 'None' }
      step: 'starting the service',
      exitCode: 5,
[18:59:53.707] ERROR (#378): Error [AssertionError]: expected true to be false // Object.is equality
  step: 'starting the service',
  exitCode: 5,
  step: 'starting the service',
  exitCode: 5,
     × preserves a newer version that finishes updating during stop on darwin 28ms
     × install with start=false rewrites files, preserves service.env, and marks a restart pending on darwin 20ms
     × installs, reports current state, and uninstalls on macOS 21ms
     × reinstalls over a loaded launch agent when launchctl rejects bootout --wait 19ms
     × uninstall unloads the launch agent when launchctl rejects bootout --wait 11ms
     × waits for a booted-out launch agent to exit before bootstrapping it again 19ms
     × keeps failed launch agent installs pending until activation succeeds 25ms
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 7 ⎯⎯⎯⎯⎯⎯⎯
AssertionError: expected [ …(2) ] to deeply equal [ …(3) ]
    625|             exitCode: Number(result.code),
AssertionError: expected undefined to deeply equal { _id: 'Duration', …(2) }
AssertionError: expected { _id: 'Option', _tag: 'Some', …(1) } to deeply equal { _id: 'Option', _tag: 'None' }
+     "exitCode": 5,
AssertionError: expected true to be false // Object.is equality
      Tests  7 failed | 29 passed (36)

# 2) Branch head 993cfc5edd
      Tests  36 passed (36)

Model and harness: Claude Opus 5.5 (Claude Code) as lead, implementer and red-test writer, with GPT-6.1 Sol (Codex) and Claude Opus 5.5 as reviewers.

🤖 Generated with Claude Code

    1. Pushed5ef49f9

Sign in to join this conversation.