Skip to content

fix(provider): uninstall never deletes under a running cluster service; the chooser says what each option removes (stacked on #1778) - #1780

Merged
jonathan308 merged 5 commits into
devfrom
fix/uninstall-running-cluster-service
Nov 4, 2026
Merged

jonathan308 merged 5 commits into
devfrom
fix/uninstall-running-cluster-service

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #1778; retargets to dev once #1778 merges. Review only this PR's commits.

Summary

darkbloom uninstall no longer deletes the app under a running cluster service. The 0.10.8 candidate (c3) hit this on the member of a serving pair, with the DevNet app beside the production app. The uninstall skipped "Stop serving" and "Remove this install's cluster service", because the service was a session's and had no launchd agent. It then deleted the app while darkbloom-dev cluster service was still running, so the member's part died mid-run and the leader looped (B16).

Now the uninstall finds whose cluster service holds the lock, from its pid file and its executable with links resolved, and only counts a process whose arguments are <cli> cluster service:

  • with no other install, step 2 is unchanged (cluster stop --service): it stops any darkbloom cluster service, launchd's or a session's, wherever it runs from, and a service under another name fails the step with that stop's own message;
  • beside the other install, this install's service is stopped and the other install's is left running. Anything else holding the lock is refused: a service from neither app, a pid that is no cluster service, or a lock or pid file that can't be read;
  • in both paths, a check right before the first deletion keeps every file, and the run exits 1, while a cluster service of this install, or one it can't tell apart, holds the lock.

The chooser's option lines now say only what each choice removes on this Mac (B21).

Linked issue

None: the 0.10.8 candidate's findings B16 and B21 (c3 on pair-2); a follow-up to #1772.

Test plan

The runs were made on the validated local branch, on 8b2eb2f33e, whose tree is #1778's head's (26a1013cde). This PR's head has the identical tree (6b640d90f7).

  • swift build --build-tests (prod and dev identities)
  • Prod, sandboxed: swift test --skip-build --filter 'ProviderUninstallTests|UninstallCommandTests|LaunchAgentRemovalTests|LaunchAgentLifecycleTests|WatchdogLaunchAdapterTests|ClusterServiceAgentTests': 93/93 (8 new tests across both rounds)
  • Prod, sandboxed: fix(cluster): on a paired Mac, darkbloom start/stop/restart/status control the pair; plain cluster status --json (stacked on #1764) #1774's stop-path set (ClusterConsoleCommandTests|ParsedInCodeTests|ClusterPairClusterCommandsTests|ClusterStatusPlainTests|ClusterPairControlTests|ClusterPairHabitCommandsTests|StatusCommandRunTests|ClusterPairTruthTests|ClusterPairValidatorFindingsTests): 66 in 9
  • Dev identity, sandboxed: ProviderUninstallTests|UninstallCommandTests: 30/30
  • Validator B's real-process cases (throwaway sleepers in a temporary dir): executables run through links resolve to the right install
  • Red first, both rounds: runtime probes and tests at each base, plus compile reds for the new seams
  • make docs-check, make docs-impact-check BASE=8b2eb2f33e, make changelog-check, git diff --check
    • Again on this PR's head 0c89e825c9: make docs-check 206 OK · make changelog-check 52 valid · make docs-impact-check BASE=01176687d6 OK (11 files) · git diff --check 01176687d6 clean
  • Pair-2 rerun, the B16 case: on a Mac with both apps, where the DevNet candidate's session cluster service runs and its pair serves, darkbloom-dev uninstall --keep-models. Step 1 ends "…; this install's cluster service is running (pid N)"; step 2 says "stopped it (pid N), so this Mac's part ended cleanly; …"; ps shows the service gone before the first "Delete" line; the leader logs a clean member stop, not the "part ended (exit 1) … starting it again" loop; the pairing, the cable port setup and ~/.darkbloom/cluster* stay; the command exits 0
  • Pair-2 rerun, the SIGTERM stop's timing on a serving pair: how long the session service takes to release the lock (the bound is 360 s); the run neither stalls nor reports a timeout
  • Pair-2 rerun, the other install's service: with the production app's service holding the lock, darkbloom-dev uninstall leaves that service running (same pid), and its pair keeps serving
  • Pair-2 rerun, a refusal: in the shared path, with a service from a development build outside both apps, the uninstall deletes nothing, exits 1 and prints "Stop it first with darkbloom-dev cluster stop --service …"; after that stop, a rerun finishes
  • Pair-2 rerun, the dry run on the same Macs: for the running service it says "stop it first (pid N, running from this install)" or "refused, deleting nothing", whichever applies
  • Pair-2 rerun, a one-install Mac with a session service (the unshared path): cluster stop --service (stopDetached) stops it, and nothing is deleted before the lock is free (so far verified only by reading)

Components touched

  • provider-swift (Swift CLI)
  • native runtime / MLX
  • landing (Next.js)
  • enclave (Swift)
  • CI / provider release
  • docs

Protocol / interface changes

  • No protocol/interface changes. The --dry-run --json plan is unchanged; no new flags.
  • Yes — described above and matching side updated

Documentation impact

  • Canonical documentation updated:
    • docs/provider/cli-reference.md (darkbloom uninstall: option lines, steps 1, 2 and 9);
    • docs/provider/installation.md;
    • docs/provider/troubleshooting.md;
    • docs/provider/two-mac-cluster.md (the two installs' names).
  • No documentation needed — reason:

Changelog

  • Added or updated this PR's unique changelog.d/<topic>.md fragment and ran make changelog-check. A line in the still-unreleased changelog.d/provider-uninstall-keep-or-remove.md.
  • No user-visible change, or an explicitly authorized release/history change.

Notes for reviewers

  • Commits: signed cherry-picks (-x) of the validated local commits, in order:

    • bdaeb0192d (from 4ce38617b2): the B16 and B21 tests;
    • 1311cf38f8 (from 31d2a79a29): the fix;
    • 4a70de9a25 (from da7dc43b89): the refactor pass;
    • 6ccc39127d (from cbc083da6c): the tests for validator B's minors;
    • 0c89e825c9 (from d944c49c8d): their fix.
  • Owner lookup. ProviderUninstall.liveRunningClusterService reads:

    • the service lock three ways (free, held, can't be read);
    • the pid in service.pid;
    • the process's executable and arguments (KERN_PROCARGS2).

    It resolves the executable's links and matches its install root to this install's app or the other install's. A pid counts only when it is a cluster service: this build's by ClusterService.isClusterService (the check cluster stop --service makes), the other install's by its own <cli> cluster service arguments. liveStopClusterService signals only such a pid.

  • Shared path (both apps on the Mac). Step 2 refuses a service from neither app, then:

    • boots out this install's own agent (launchd's service ends);
    • stops a session service of this install with SIGTERM, waiting for the lock, as cluster stop --local-only ends one;
    • leaves the other install's service running.

    The pairing and the cable port setup stay, as in feat(provider): darkbloom uninstall, remove everything or keep models #1772.

  • Unshared path. Cluster.Stop.parse(["--service"]) is unchanged. It stops a session service whose command is this build's <cli> cluster service, wherever it runs from (ClusterService.stopDetached). A service under another name makes the step fail with stopDetached's message, and nothing is deleted.

  • Both paths. Before the first deletion, a check fails the run while a cluster service of this install, or one it can't tell apart, still runs. Every deletion is then skipped and the run exits 1. Files are never deleted from under a running service.

  • Step 1 says when a cluster service serves here instead of the provider.

  • Tests use stand-ins for the lock holder and its stop: never real launchd or processes.

  • Limit: the live lookup and SIGTERM are reviewed, not exercised. A run on pair-2 is the proof.

Independent validation

Validator B, at the refactor pass's head (4a70de9a25 here; local da7dc43b89): PASS WITH NOTES, 0 blockers, 0 majors, 4 minors, 3 nits.

  • No path deletes under a running cluster service of this install, or under one it can't attribute. Every way the lookup can fail ends in a refusal: a missing or unreadable pid file, an unreadable executable, a process of another user, a pid that is gone. Scripted lookups that change between calls, and a stop that "succeeds" while the service runs on, are caught by the check before the deletions; nothing was deleted in any such run.
  • The other install's service is never classed as this install's: of 11 real throwaway processes, from different executables and paths, none was claimed by both installs.
  • Reran, sandboxed: prod 89/89, fix(cluster): on a paired Mac, darkbloom start/stop/restart/status control the pair; plain cluster status --json (stacked on #1764) #1774's set 66, dev 26/26; the PR's tests don't compile on the base, for the stated reason; the docs gates and git diff --check clean.
  • The minors: m1, a service started through a link read as unknown; m2, SIGTERM went to service.pid's pid without checking it is a cluster service; m3, an unreadable lock counted as "no service"; m4, the one-install path was described as the shared one. The nits: n1, "pid 0" with no readable pid; n2, the check ran right after step 2, not right before the first deletion; n3, two names for the other install. All are fixed in 6ccc39127d and 0c89e825c9.

Delta check at the final head (0c89e825c9 here; local d944c49c8d, the same tree): PASS. All four minors and three nits are fixed, with no regression.

  • m1: the executable's links are resolved before its install root; the validator's real-process cases, which both failed before, pass 2/2.
  • m2: only a cluster service is anyone's, and liveStopClusterService checks isClusterService again right before kill. Given three pids that are no cluster service, the live stop threw, and all three stayed running.
  • m3: the lock reads three ways; an unreadable lock is unknown and refused.
  • m4: the dry run and the docs word step 2 per path.
  • n1–n3: no "pid 0" claim; the check runs right before the first deletion, after steps 3–8; one name per install.
  • No regression: the shared path still skips steps 7–8 and keeps the pairing and cable; the unshared step 2 and the live wiring are unchanged.
  • Reran, sandboxed: prod 93/93, fix(cluster): on a paired Mac, darkbloom start/stop/restart/status control the pair; plain cluster status --json (stacked on #1764) #1774's set 66/66, dev 30/30, its scratch suite 5/5 on real throwaway processes; the new tests don't compile on the refactor pass's head; the docs gates and git diff --check clean.

Nit left (d1, cosmetic, no action needed): the unshared step 2 still decides on ClusterService.running(), which folds an unreadable lock into "free". Under an unreadable lock that step reads "skipped: no cluster service on this Mac", then the final check fails with the unreadable-lock note. It is safe (nothing is deleted); only the two lines disagree.

The pair-2 rerun boxes in the Test plan stay open: the live lookup and stop are exercised only on throwaway processes and seams.

Before And After

flowchart LR
  subgraph Before["Before (c3 on pair-2)"]
    direction TB
    b1["darkbloom-dev uninstall<br/>(member of a serving pair; session cluster service, no agent)"] --> b2["step 1: provider service not running → skipped"]
    b2 --> b3["step 2 (shared): no own agent → skipped"]
    b3 --> b4["delete ~/.darkbloom-dev<br/>under the running service"]
    b4 --> b5["member's part dies; leader loops<br/>'part ended … starting it again'"]
  end
  subgraph After
    direction TB
    a1["darkbloom-dev uninstall"] --> a2["runningClusterService():<br/>lock, service.pid, KERN_PROCARGS2 → owner"]
    a2 -->|this install| a3["boot out own agent; SIGTERM the session service;<br/>wait for the lock"]
    a2 -->|other install| a4["left running; said so"]
    a2 -->|neither| a5["step 2 fails: nothing deleted, exit 1;<br/>'stop it first with cluster stop --service'"]
    a3 --> a6["check before deleting: no service of this install runs"]
    a4 --> a6
    a6 --> a7["delete this install's files; pairing and cable stay"]
  end
Loading
flowchart LR
  subgraph Code["Code path (After)"]
    direction TB
    c1["UninstallCommand.plan / operations"] --> c2["ProviderUninstall.liveRunningClusterService<br/>(ProviderUninstall+ClusterService.swift)"]
    c2 --> c3["ProviderUninstall.owner(ofExecutable:paths:)"]
    c1 --> c4["ProviderUninstall.run"]
    c4 --> c5["shared: removeOwnClusterService<br/>(agent → stopClusterService)"]
    c4 --> c6["unshared: stopClusterPart = Cluster.Stop --service (unchanged)"]
    c5 --> c7["stillRunningStep check → deletions or refusal"]
    c6 --> c7
  end
Loading

Refactor Pass

Done: 4a70de9a25 (removeOwnClusterService, no force unwraps, one lock check). Validator B: PASS WITH NOTES (0/0/4/3). All four minors and three nits are fixed in 6ccc39127d and 0c89e825c9, and the prod and dev sets, #1774's 66 and the docs gates were rerun.

A dedicated refactor subagent reviewed the fix and added one behaviour-preserving commit:
4a70de9a25 refactor(provider): name step 2's own-service function for its step, drop the path it replaced.
No test changed, and every printed line and exit code is the same.

Changed

  • Removed ProviderUninstall.removeOwnClusterAgent. The fix left it with no caller, and its doc comment had stayed on top of the new function's.
  • Renamed step 2's function after its step: handleOwnClusterService → removeOwnClusterService. Its detail is built from one list, without a force unwrap.
  • The dry run's shared step 2 binds the running service instead of force-unwrapping it twice.
  • The command probes the cluster service lock once; the Plan's init sets clusterServiceRunning from runningClusterService.
  • Named the "Models" label that option 2's line compares against (linkedModelsLabel).
  • docs/provider/cli-reference.md, step 2: names the function step 2 calls, and says the bootout ends launchd's service and SIGTERM a session's.

Left as is

  • RunningClusterService.described stays with the engine's other step reasons.
  • The runningClusterService and stopClusterService seams are left as they are.
  • The live lookup and stop are left as they are: no test can exercise them.

Follow-up (outside this PR): one shared KERN_PROCARGS2 reader in ClusterService, for processCommand(pid:) (executablePath(pid:) before the minors' fix) and processArguments(pid:).

After it (sandboxed, filtered, at 4a70de9a25):

Final (this head): prod 93/93, #1774's set 66/66, dev 30/30, and the gates, as in the Test plan.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

jonathan308 and others added 5 commits November 3, 2026 22:10
…st (B16, B21)

The 0.10.8 candidate (c3) on pair-2: on the member of a serving pair, the
DevNet app's uninstall skipped "Stop serving" and "Remove this install's
cluster service", then deleted the app while `darkbloom-dev cluster
service` (a session service, no launchd agent) was still running from it.
As tests, with stand-ins for the lock holder (never real launchd or
processes):

- Beside the other install, this install's running cluster service is
  stopped before the first deletion (both directions); step 1 says what
  serves here; the dry run and the summary say so; the pairing and the
  shared files stay.
- The other install's running service is left running, and said so.
- A running service that is neither install's keeps every file and fails
  the run (exit 1); so does this install's service when it did not stop.
- B21: beside the other install, option 1 does not promise the pairing or
  models it keeps, and option 2 says the models stay either way.

Red at 8b2eb2f33e: a runtime probe with the old API deleted the app under
the running service and showed the old option lines; the tests above do
not compile (no `RunningClusterService`, `runningClusterService:`,
`stopClusterService:`, `owner(ofExecutable:)`, `stillRunningStep`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 4ce38617b2e3f2a919a4bddcf5bcfd39c75ec6df)
B16: before deleting anything, the uninstall now finds whose cluster
service holds this Mac's lock (`ClusterService.running`, the service's
pid file, the process's executable from the kernel, matched to an install
by `ClusterServiceAgentPlan.installRoot`).

- Beside the other install (step 2's shared path), this install's running
  service, launchd's or a session's, is stopped first (SIGTERM, as
  `cluster stop --local-only` ends one, waiting for its lock), so the
  member's part ends cleanly; then its agent goes; the pairing and cable
  port setup stay. The other install's service is left running. One from
  neither install is refused.
- In both paths, a check before the first deletion fails the run when a
  cluster service of this install, or one it can't tell apart, still
  runs: nothing is deleted, the summary says to stop it with `cluster stop
  --service` and run the uninstall again, and the command exits 1. The
  unshared path keeps `Cluster.Stop.parse(["--service"])`, which already
  ends a session service of this build (`ClusterService.stopDetached`).
- Step 1 says when a cluster service serves here instead of the provider.
- B21: option 1's line names only what it removes on this Mac (no pairing
  while another install shares it, "all models" only when none stays);
  option 2 says when the models stay either way.

The CLI reference, the installation and troubleshooting sections and the
changelog fragment say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 31d2a79a293c89ad863911796872f420e0a9097f)
…drop the path it replaced

Behaviour-preserving cleanup of the uninstall's running cluster service
fix (31d2a79a29). Every printed line and exit code is the same; no test
changed.

- `removeOwnClusterAgent` had no caller left, and its doc comment sat on
  top of the new function's. It is removed.
- `handleOwnClusterService` is `removeOwnClusterService`, after its step
  ("Remove this install's cluster service") and the function it
  replaced. Its detail is built from one list without a force unwrap;
  each outcome reads as before.
- The dry run's shared step 2 binds the running service instead of
  force-unwrapping it twice; its default branch is the base's line again.
- The command probes the cluster service lock once: the Plan's init sets
  `clusterServiceRunning` from `runningClusterService`, and the live
  lookup is non-nil exactly when `ClusterService.running()` is true.
- `linkedModelsLabel` names the "Models" label the inventory gives a
  linked model cache, which option 2's line (`keepsModels`) compares with.
- The CLI reference's step 2 names the function step 2 calls, and says
  that booting out the agent ends launchd's service and SIGTERM a
  session's (it said both were stopped first with SIGTERM). The
  installation section's long line is rewrapped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit da7dc43b8973420ebdf615b017500e7b607d9354)
…, unreadable locks

Validator B's notes on the B16 fix, as tests:

- m1: a cluster service started through a link (`bin/<cli>`, or a link
  elsewhere into an app) is told apart by where the link leads, both
  directions.
- n2: a service that starts again during the steps after step 2 (the
  cable step can wait for a password) still keeps every file.
- m2, m3, n1: the lock reads three ways (free, held, can't be read), a lock
  that can't be read or a pid that is not a cluster service is nobody's,
  a missing pid makes no claim about whose, and the stop refuses to signal
  a process that is not a cluster service.
- m4: with no other install, the dry run says what `cluster stop
  --service` does to the service running here: stops this install's, stops
  any `<cli> cluster service`, and stops nothing else.

Red at da7dc43b89: m1 (6 issues) and n2 (2: files deleted, no check) run
and fail; with the others the suite does not compile (no
`runningClusterService(lock:pidFile:paths:isClusterService:)`,
`unreadableLockNote`, `isThisCLI`, `note`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit cbc083da6c9178e3cfea16f37af53f384075409e)
…care

Validator B's minors and nits on the B16 fix:

- m1: the executable is resolved (links included) before telling whose it
  is, as the install roots are.
- m2: only a cluster service is anyone's. This build's is checked with
  `ClusterService.isClusterService`, the check `cluster stop --service`
  makes; the other install's by its own `<cli> cluster service` arguments.
  A pid that is no cluster service (a stale pid file) reads as unknown and
  is refused, and the stop never signals one.
- m3: the lock reads three ways; one that can't be opened is unknown and
  refused, not "no service".
- m4: the docs, the dry run and the changelog say what each path does:
  with no other install, step 2 stops any `darkbloom cluster service`, and
  a service under another name fails it with that stop's own message.
- n1: without a readable pid the step says so and claims no owner.
- n2: the "still running" check runs right before the first deletion,
  after the steps that can wait (the cable step's password).
- n3: one name for the other install in the uninstall docs: the
  production Darkbloom, Darkbloom Dev.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit d944c49c8d795f4e0a63a248347a1ddada8b8946)
@jonathan308
jonathan308 requested a review from davidtai November 4, 2026 06:13
@vercel

vercel Bot commented Nov 4, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
d-inference Error Error Nov 4, 2026 6:13am UTC
d-inference-console-ui-dev Error Error Nov 4, 2026 6:13am UTC
d-inference-landing Ready Ready Preview Nov 4, 2026 6:13am UTC
darkbloom-status Ready Ready Preview Nov 4, 2026 6:13am UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 4, 2026 6:13am UTC

Request Review

This branch had an error being deployed

2 failed and 3 active deployments
Preview – eigen-homepages-darkbloom — 0c89e825 Deployed Nov 4, 2026 by vercel[bot]
Preview – d-inference-landing — 0c89e825 Deployed Nov 4, 2026 by vercel[bot]
Preview – darkbloom-status — 0c89e825 Deployed Nov 4, 2026 by vercel[bot]
Preview – d-inference — 0c89e825 Deployed Nov 4, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 0c89e825 Deployed Nov 4, 2026 by vercel[bot]
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.

1 participant