fix(server): macOS service install and restart from inside T3 hand off to launchd #28565
Problem#
On macOS, t3 service install, t3 service restart and a restarting t3 update run from inside T3 (a T3 terminal or an agent shell, so a descendant of the com.t3tools.t3code.service launchd job) run launchctl bootout --wait on their own job. The bootout kills the caller before launchctl bootstrap, and a booted-out job is not restarted by KeepAlive, so the service stays down. systemd already hands this work to the service manager; launchd had no handoff, and the inside-service check never matched on macOS because the plist sets T3_BOOT_SERVICE_UNIT=com.t3tools.t3code.service.plist while the check compared against t3code.service.
Reproduced on main (ce9e016406) as two failing tests in the darwin harness of apps/server/src/cloud/bootService.test.ts, with the marker the launch agent really sets: an in-service install() and restart each issue launchctl bootout --wait gui/501/com.t3tools.t3code.service from the caller.
Change#
- The inside-service check compares
T3_BOOT_SERVICE_UNITwith the detected manager's own unit file name, so the existing macOS marker matches (the plist is unchanged, so installed services stay current). BootServiceManager.handoffnow hasinstallandrestartentries for both managers;install()andrestart()no longer branch onkind. The systemd handoff (transient unit for install,restart --no-block) is moved there unchanged.- On launchd, a handoff writes a one-shot job plist (its own unique label
com.t3tools.t3code.service.handoff.<id>,RunAtLoad, noKeepAlive,PATHandHOMEonly, no service marker, output appended toboot-service.log) under<baseDir>/runtime, bootstraps it intogui/<uid>, and removes the file. The job runs outside the service's job, so stopping the service does not kill it. Unique labels mean a second in-service call never unloads a handoff that is still running.- install: the job runs the target runtime's
service install --base-dir <baseDir> [--allow-downgrade], which takes the normal stop-first path; the caller returnshandedOff. - restart: the job runs launchd's own stop and start steps through
/bin/sh(notkickstart -k, which neither reloads a rewritten plist nor spares the caller, and not the installed plist's program, which may benodeon old npm installs); the caller returnsqueued.
- install: the job runs the target runtime's
t3 update's handed-off message says "from outside the service" instead of "from a separate systemd unit".
Scope and approval#
Fixes pingdotgg/t3code#28552
Triaged via the automated issue flow.
Verification#
vp test run apps/server/src/cloud/bootService.test.ts apps/server/src/cli/update.test.ts apps/server/src/cli/service.test.tson the branch: 59 passed.- The same
bootService.test.tsagainst main'sbootService.ts(ce9e016406): 2 failed, 35 passed:
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯
FAIL |t3| src/cloud/bootService.test.ts > boot service install > hands an in-service install to launchd without booting out the running agent
AssertionError: expected [ Array(1) ] to deeply equal []
- Expected
+ Received
- []
+ [
+ "launchctl bootout --wait gui/501/com.t3tools.t3code.service",
+ ]
FAIL |t3| src/cloud/bootService.test.ts > boot service install > queues an in-service restart on macOS without booting out the running agent
AssertionError: expected [ …(2) ] to deeply equal []
- Expected
+ Received
- []
+ [
+ "launchctl bootout --wait gui/501/com.t3tools.t3code.service",
- New and extended tests: in-service install on macOS hands off without booting out the service, leaves state and plist untouched, and the job runs
<entry> service install --base-dir <baseDir>without the marker; in-service restart is queued, two restarts load two distinct jobs with no bootout, the job script stops and bootstraps the launch agent, carries no marker orKeepAlive, and leaves no plist behind. Existing systemd handoff tests pass unchanged. vp run check:changed: format, lint, knip, typecheck (3 packages) and tests pass.- No visible surface, so no captures.
cannot-verify macos: nothing here ran on a Mac. Not checked natively: launchd bootstrap of the handoff plist, the job's environment and survival across the service bootout, and whether macOS 13+ Background Task Management shows a notice per handoff job. On macOS 15, wherebootout --waitis a usage error (pingdotgg/t3code#11995), the handed-off install or restart still fails inside the job as it does from a terminal, leaving the old service running; that is fixed separately.
Model and harness: Claude Opus 5.5 (Claude Code) as lead, implementer and test writer, with GPT-6.1 Sol (Codex) and Claude Opus 5.5 reviewers, run through T3 Code.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Approved at
b5bb533Macroscope's review found this PR approvable — macOS service install and restart now run through a one-shot launchd job so stopping the service does not kill the operation. The change is limited to requested per-user service operations, with existing install safeguards and terminal-based recovery preserved.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB +29 B (+0.6%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB +29 B (+2.3%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 21.5 KiB 21.6 KiB +41 B (+0.2%) 24.4 KiB ✅ Codex Live turn messages 1 2 +1 (+100.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.3 KiB 1.3 KiB 0 B (0.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅ Claude Live turn messages 2 2 0 (0.0%) 8 ✅ Baseline:
37d7615· PR result:b5bb533· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: fix/issue-28552
- File: .coderabbit.config.ts
- Commit: b5bb533
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
6d8b3819-a1cb-4562-b9d5-77a40b7f285b
Commits-
Reviewing files that changed from the base of the PR and between 37d7615a91d880c3776d575e1152b9c955104de2 and b5bb5330fc6a16c7ec5ee5b6c3eed1f47b5aba46.
Files selected for processing: 3-
apps/server/src/cli/update.tsapps/server/src/cloud/bootService.test.tsapps/server/src/cloud/bootService.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
Walkthrough
-
In-service installation and restart now use manager-specific handoffs. On macOS, launchd handoffs use uniquely labeled one-shot jobs. Service detection compares the configured marker with the detected manager’s unit basename.
Changes: Service manager handoffs
Layer / File(s) Summary Manager handoff contracts and implementations
apps/server/src/cloud/bootService.tsBootServiceManager.handoffnow defines install and restart callbacks. Systemd and launchd provide manager-specific handoff behavior. Launchd handoffs use one-shot plist jobs with command arguments, environment values, and log paths.In-service routing and handoff execution
apps/server/src/cloud/bootService.ts,apps/server/src/cloud/bootService.test.ts,apps/server/src/cli/update.tsIn-service detection compares the marker with the detected manager’s unit basename. Installation and restart use the manager’s handoff callbacks. The tests check macOS handoff behavior, and the update status message now says the switch runs “from outside the service.” Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
- pingdotgg/t3code issue 11995: The launchd stop sequence still uses
launchctl bootout --wait, which the issue reports can fail on macOS 15. - pingdotgg/t3code issue 12627: Installation uses the target runtime CLI, intersecting with the issue’s concern about the CLI protocol used to write service state.
- pingdotgg/t3code issue 24755: Launchd handoff output is sent to the service log path discussed in the issue.
- pingdotgg/t3code issue 24910: The handoff plist uses the service log path under the T3 base directory, the path policy discussed in the issue.
Suggested reviewers:
rookmate,macroscopeapp,maria-rcks - pingdotgg/t3code issue 11995: The launchd stop sequence still uses
Merge Risk:
Minimal · up tob5bb5-
No actionable regression is established for this change. Native macOS handoff behavior has not been verified, but that uncertainty alone does not block merging.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the main change: macOS service installs and restarts invoked inside T3 now hand off to launchd. Description check The description includes complete Problem, Change, Scope and approval, and Verification sections. It explains the failure, implementation, linked issue, test results, unverified native macOS behavior,… Linked Issues check Issue #28552has coding requirements. The change detects the launchd marker from the detected unit filename. It adds install and restart handoffs for launchd. Each launchd handoff uses a unique one-sh…Out of Scope Changes check The changes stay within issue #28552. The production changes implement manager-owned install and restart handoffs, marker detection, launchd job creation and cleanup, and the related update message. T…Full details: Description check
-
Explanation
The description includes complete Problem, Change, Scope and approval, and Verification sections. It explains the failure, implementation, linked issue, test results, unverified native macOS behavior, and the separate macOS 15 limitation.
Full details: Linked Issues check
-
Explanation
Issue
#28552has coding requirements. The change detects the launchd marker from the detected unit filename. It adds install and restart handoffs for launchd. Each launchd handoff uses a unique one-shot job with noKeepAlive, no service marker, and output appended toboot-service.log. Install runs the target CLI'sservice install; restart runs launchd stop and start steps outside the service job. The caller returnshandedOfforqueued. The existing update restart path uses the updated service restart handoff, and its message no longer claims a systemd-only handoff. The added tests cover marker detection, install and restart handoffs, unique jobs, preserved service files, job contents, and cleanup. The reported verification also passes the relevant tests and checks.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within issue
#28552. The production changes implement manager-owned install and restart handoffs, marker detection, launchd job creation and cleanup, and the related update message. The test harness and regression tests support these requirements. The systemd code preserves the existing handoff behavior while moving it into the shared handoff interface. No unrelated product behavior or unrelated files are introduced.
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:gate-failed
Wladefant(GitHub profile, opens in a new tab) requested changes
Independent macOS launchd lifecycle review — CHANGES_REQUESTED#
Reviewed exact HEAD
b5bb5330fc6a16c7ec5ee5b6c3eed1f47b5aba46against recorded base37d7615a91d880c3776d575e1152b9c955104de2. Reviewer: GPT-6 (Wladefant, separate from PR author). Implementer-model provenance is not fully declared; the initial RED reproduction commitbc171f1lists Claude Opus 5.5 as co-author. Applied the temporary #1899 review-family exception; no self-review.P2 — concurrent in-service handoffs can race the same launchd service. At
apps/server/src/cloud/bootService.ts:427-448, each call creates a distinct RunAtLoad one-shot job with a unique label. At lines 472-475, each restart job independently executes the samebootout --wait→enable→bootstrapsequence. The test deliberately callsinside.restarttwice and asserts two distinct jobs, but it only inspects the generated plists; it never executes overlapping jobs or proves serialization. There is no per-baseDir/service lock or single-flight queue aroundrunHandoff,install, orrestartin the inspected path.Two RunAtLoad jobs can therefore interleave their bootout/bootstrap steps against the same label. One can boot out the other's newly loaded service, or a later required bootstrap can fail because the label is already loaded;
shellScriptOfchains required steps with&&, so that failure stops the remainder. This can leave the requested service restart incomplete or the service down. This is a source-derived concurrency risk, not a reproduced launchd host incident.Required correction: serialize handoff jobs for the same user + T3 home (including install-vs-restart), or route them through one durable coordinator that coalesces/reconciles requests without allowing two stop/bootstrap sequences to overlap. Add a deterministic regression that releases two queued restart jobs concurrently and an install/restart overlap; assert one-at-a-time execution, no second bootout after the first successful bootstrap, and a terminal receipt that distinguishes queued from completed/failed.
Separate integration/CI gate: current T3 main is
09a54f01bc0ae83865347a965ced50f8c8ec2953; this PR's recorded base37d7615a91d880c3776d575e1152b9c955104de2is 858 commits behind main, and GitHub reportsmergeable:false. The exact-head all-event inventory contains only the 1 Nov run set: CI#41288396404succeeded on this old candidate, while Test Web, Release Smoke, Rust, Mobile Native Static Analysis and preview jobs were skipped. No current-main composed candidate or current-main CI is established. Preserve the separate #29528 kickstart composition gate already recorded in #6716983042.No macOS host/service/session was touched. This review does not authorize installation, restart, credential access or landing.
tanstack-source added labelsbug
Confirming this on a released build: on macOS,
t3 service restartrun by Codex inside T3 stopped the service and it never came back; the launchd system log shows the stop chainlaunchctl <- t3 CLI <- codex <- T3 server.We carry the same fix (handoff to a one-shot launchd job) in a fork, and added a macOS-only test against the real launchd: an isolated label and HOME, a process of the service runs the real
t3 service restart, and the test waits on a FIFO until the restarted service writes its new pid, with the caller dead. It passes in ~2.4s on macOS 15.1 and cleans up after itself. Happy to share it if useful for this PR.
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes