Skip to content

fix(provider): wait for launchd service removal before replacement - #1315

Merged
Gajesh2007 merged 5 commits into
masterfrom
fix/issue-1102-20261002
Oct 5, 2026
Merged

Gajesh2007 merged 5 commits into
masterfrom
fix/issue-1102-20261002

Conversation

@jonathan308

@jonathan308 jonathan308 commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When launchd returns from bootout before removing its service label, provider replacement can bootstrap too early and fail with an operation-in-progress error. Wait for confirmed removal of the exact label before replacement, preserve errors and the existing plist when confirmation fails, and stop treating numeric error 37 as successful bootstrap.

Linked issue

Related to #1102. This draft does not request issue closure.

Before

flowchart TD
    A["Caller requests install or drained restart"] --> B["LaunchAgent.unloadService: bootout returns"]
    B --> C["installAndStart sleeps 0.5s; restartAfterDrain proceeds"]
    C --> D["loadService calls bootstrap"]
    D --> E{"Old label still registered?"}
    E -->|"Yes"| F["Replacement fails; error 37 may be ignored"]
    E -->|"No"| G["kickstart starts provider"]
    classDef step fill:#dbeafe,stroke:#1d4ed8,color:#172554
    classDef bad fill:#fee2e2,stroke:#b91c1c,color:#450a0a
    classDef good fill:#dcfce7,stroke:#15803d,color:#052e16
    class A,B,C,D,E step
    class F bad
    class G good
Loading

After

flowchart TD
    A["Caller requests install or drained restart"] --> B["unloadService: bootout returns"]
    B --> C["waitForServiceRemoval polls exact label"]
    C --> D{"Confirmed absent?"}
    D -->|"Still loaded; budget remains"| C
    D -->|"Error or budget exhausted"| E["Throw; preserve plist; no replacement"]
    D -->|"Yes"| F["loadService bootstraps then kickstarts"]
    F --> G["Provider replacement completes"]
    F -->|"Operation-in-progress error"| H["Throw before kickstart"]
    classDef step fill:#dbeafe,stroke:#1d4ed8,color:#172554
    classDef bad fill:#fee2e2,stroke:#b91c1c,color:#450a0a
    classDef good fill:#dcfce7,stroke:#15803d,color:#052e16
    class A,B,C,D,F step
    class E,H bad
    class G good
Loading

Blue nodes show the lifecycle calls and decisions, green the successful observable result, and red explicit failure outcomes. Shared unload behavior also makes stop wait without reloading and uninstall preserve its plist if removal fails.

Current target and integration status

Integrated current master 34f0e6dd (after #1324, #1338, #1340 and the merge of #1336) with signed merge commits dfa6bdcb, dc6e955f and b07fac6a; the resolved source tree is bdb93f35. Only CHANGELOG.md conflicted, each time where new entries are inserted, and every entry is kept. This branch's entry now sits after the verification-concurrency section, away from that insertion point. Master changed none of this pull request's Swift files since the previous integration, so the provider change is exactly what was validated before.

On the merged head, docs lint (330 files) and docs impact pass. The Swift lifecycle suites were not re-run locally on this head; CI runs them. This pull request does not touch the coordinator, so the reorganization in #1324 required no code movement here.

Previous integration (2026-10-02)

Integrated current master c56b98e8638f1895b80e22c00122880bed9b11b9 with a signed merge commit 1431f4f1ef6cd776665077454cc28d6e8a7aee0c; the resolved source tree is b382a615dd2a55222c2f78b4cb4f05f988ff8e6d. The merge preserves the focused fix and incoming master behavior. The consumed SDK is 1ee8675a035d0d842d5df663938d66cfedf88a8e.

Fresh local validation: 27 lifecycle cases and 34 adjacent plist/config/watchdog cases passed, with zero skips. The current-master control had 14 expected failures and 13 passing controls. Docs lint (330 files) and docs impact (five paths) passed. This is an offline Foundation component harness using scripted launchctl and virtual time, exact SDK defaults and explicitly declared configuration fixtures; full native provider/SDK, real launchd and GPU execution remain unrun.

Ready for maintainer review after reproducing the deterministic lifecycle failure on current master and verifying candidate success in the scoped scripted-launchctl harness. Latest-head CI remains pending; real launchd/native qualification is not claimed. Local component results do not establish production deployment or full native qualification.

Earlier qualification

The original candidate e58ae161c2c3a8d2c3e408897ecbc29b78e9e971 was qualified against base 27a165e831e23dd9276f0b279068abe948982902. Those results remain historical; the current-base results and outstanding gates are stated above.

Components touched

  • provider-swift (Swift CLI)
  • docs

Protocol / interface changes

  • No protocol, configuration-key or CLI-flag changes.

Documentation impact

  • Canonical CLI lifecycle reference and CHANGELOG updated.

Notes for reviewers

The ten-second monotonic polling budget allows at most 101 post-bootout probes at a 100 ms cadence. It is not a hard subprocess wall timeout: an individual launchctl invocation still uses the existing Process runner without a deadline. Unknown print errors, permission errors, another label's missing-service diagnostic and spawn failures propagate. Explicit already-loaded bootstrap wording remains compatible.

Runner/home test seam design follows the existing coverage proposal in #1296; its unchanged lifecycle algorithm does not implement removal confirmation. No dependency on that unmerged PR is introduced. The test fixture also injects time without sleeping in real time. Current CLI process-drain logic and the reporter's provider 0.9.4 environment are outside the bounded fixture; this draft does not claim live OS reproduction or full qualification.

Hosted checks on the current target composition remain pending. No runner or setting change is part of this PR. The unchanged figures were checked in actual GitHub rendering; that check does not constitute a full theme/accessibility or unobstructed-label audit.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@vercel

vercel Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Ready Ready Preview Oct 4, 2026 11:53pm UTC
d-inference-console-ui-dev Ready Ready Preview Oct 4, 2026 11:53pm UTC
d-inference-landing Ready Ready Preview Oct 4, 2026 11:53pm UTC
eigen-homepages-darkbloom Ready Ready Preview Oct 4, 2026 11:53pm UTC

Request Review

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head b07fac6a545d against base 34f0e6dde6a8.

Review not completed for this head. Previous findings are superseded, not confirmed resolved.
Ten-PR pilot complete; maintainer evaluation required

Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging.

Coverage: 0/0 source units; cross-file integration pending. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned.

Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 0 reused batch(es), 0 provider cache-hit tokens.

Saved findings and earlier report · Historical findings are not confirmed resolved.

jonathan308 and others added 2 commits October 4, 2026 12:18
Only CHANGELOG.md conflicted. Both entries are kept: this branch's launchd
removal note and the entries master added since.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CHANGELOG.md conflicted again at the top of the file. Both sides are kept;
master's new entries go first so later entries there do not collide with
this branch's section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CHANGELOG.md conflicted at the top of the file again, this time with the
entry master gained when #1336 merged. Every entry is kept. This branch's
entry now sits after the verification-concurrency section, away from the
spot where other open changes insert theirs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Gajesh2007 Gajesh2007 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed exact head b07fac6 against 34f0e6d, with the target delta through current master f9f2b41 inspected. No actionable introduced defect found. Exact-label absence confirmation closes #1102's bootout/replacement race; timeout/unknown/permission/spawn errors prevent replacement, preserve the plist and avoid false bootstrap success on error 37. Relevant CLI/drain/restart/update/stop/uninstall/watchdog callers were traced.

Local isolated validation: the exact production lifecycle component harness passed 63 expanded cases, including independent boundary/command-duration controls. The base algorithm reproduced 14 expected new-lifecycle failures plus passing controls: install bootstraps at 0.5s and drained restart at 0s before a 3s label release; head waits until removal. The ten-second timeout performs no bootstrap/kickstart and preserves original plist bytes.

Exact-head native Swift build passed (395.61s), with input paths, new removal-wait object symbols and source provenance verified against independent copied artifacts. Native focused lifecycle tests passed 52 executed functions/56 expanded cases; one real-launchd opt-in test was disabled. Broader native ProviderCore service selection passed (235 tests declared in 34 suites). The CLI selection (308 declared tests/46 suites) had one unchanged cache-path test fail under our fixed Foundation-home override; that exact test passes alone without the override, while all other private state/keychain settings remain. The broader combined selection remains exit 1 and is not claimed as an aggregate pass. No tracked source/test assertion changed.

Limits: no real user service was replaced/stopped, no reporter-OS/live launchd reproduction, and no full native provider/GPU aggregate or full-model qualification for this PR. Native execution used local Swift 6.4/Xcode 27 and verified source-matched cached Metal resources; CI uses its pinned toolchain. An individually hung existing launchctl process can still exceed the polling budget, as documented. Fresh head unchanged; current-head CI, Integration Tests and Contribution Policy pass, docs/link/impact checks pass. Protected benchmarks remain waiting; advisory threat reports are incomplete, and fresh hosted Mermaid rendering remained behind SAML. Approval is for this exact head and stated lifecycle scope.

@Gajesh2007
Gajesh2007 merged commit ae642f6 into master Oct 5, 2026
32 of 33 checks passed

This branch was successfully deployed

4 active deployments
Preview – d-inference — b07fac6a Deployed Oct 4, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — b07fac6a Deployed Oct 4, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — b07fac6a Deployed Oct 4, 2026 by vercel[bot]
Preview – d-inference-landing — b07fac6a Deployed Oct 4, 2026 by vercel[bot]
benchmarks — b07fac6a Deployed Oct 4, 2026 by jonathan308 via E2E Benchmarks #2224
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants