diff --git a/changelog.d/cluster-candidate-findings.md b/changelog.d/cluster-candidate-findings.md index e74220352b..93513e1705 100644 --- a/changelog.d/cluster-candidate-findings.md +++ b/changelog.d/cluster-candidate-findings.md @@ -16,5 +16,8 @@ and what to do on that Mac (turn on Darkbloom under Privacy & Security → Local Network, through Screen Sharing on a Mac with no display), instead of "the other Mac did not answer". Retry starts a stopped pair again, q leaves a start's wait at once, and the joining Mac's window shows how the leading Mac's start is going. +- The Local Network ✗ no longer ends with a line that repeated its instruction and was cut off mid-sentence, and a ✗ + line too long for the screen is cut at a word and marked with "…". In the DevNet app, the pairing screen's firewall + hint and its line about a reinstall name Darkbloom Dev. - The card after a start says "Starts by itself at login on both Macs." only when the cluster service on both Macs does; otherwise it names the Mac where it doesn't, or says the other Mac doesn't say (an older Darkbloom there). diff --git a/changelog.d/cluster-everyday-commands-on-a-pair.md b/changelog.d/cluster-everyday-commands-on-a-pair.md index bc0f9ee081..2fc450f2b1 100644 --- a/changelog.d/cluster-everyday-commands-on-a-pair.md +++ b/changelog.d/cluster-everyday-commands-on-a-pair.md @@ -52,3 +52,6 @@ so when it is slow; past that they show this Mac's own view. - `darkbloom unenroll` (leaving fully) and the app's local mode no longer stop with an internal error when they stop or drain the provider first. +- `status` and `cluster status` no longer say "loading" while macOS keeps a Mac off the local network: both Macs say + the pair is not serving and what to turn on, on which Mac. A stopped pair reads stopped even when the other Mac has + gone. diff --git a/changelog.d/provider-agent-setup-guide.md b/changelog.d/provider-agent-setup-guide.md index a52b7d3f2c..474ce21799 100644 --- a/changelog.d/provider-agent-setup-guide.md +++ b/changelog.d/provider-agent-setup-guide.md @@ -3,5 +3,5 @@ - New provider how-to, `docs/provider/agent-setup.md`, for a person to hand to their own AI agent. The agent installs and checks the signed release, logs in with the person's help, and either serves on one Mac or pairs two Macs over a Thunderbolt 5 cable. It then proves the result with `darkbloom status`, `darkbloom cluster status --json` (its exit status and `state`) and a test request, instead of trusting the setup screen alone. - It lists, up front, what only the person can do, such as the Terms of Service, the Darkbloom login, the RDMA switch, the macOS password and Local Network prompts, the pairing code, the model choice and Screen Sharing for headless Macs. It also sets the agent's safety rules, among them: no security settings changed, no Darkbloom files or Keychain items deleted by hand, no `darkbloom cluster link --remove` unless asked, and no large download without asking. - Once a pair is set up, the agent checks it with `darkbloom cluster status --json` and starts or stops both Macs with `darkbloom start` and `darkbloom stop`, all without a terminal. The page also covers changing the model, pairing again, `--solo`, troubleshooting by message, and `darkbloom uninstall`. -- Checked by an agent that followed it on a real two-Mac pair: it now has a DevNet variant (`darkbloom-dev`, the DevNet installer, `Darkbloom Dev.app`; a pair's local API on port 8000 in both apps), tells the agent to have the person turn on Local Network access in System Settings on each Mac instead of waiting for a macOS prompt, quotes the screens that say when macOS keeps a Mac off the local network, and covers the app switch that offers no **Pair again**. +- Checked by an agent that followed it on a real two-Mac pair: it now has a DevNet variant (`darkbloom-dev`, the DevNet installer, `Darkbloom Dev.app`; a pair's local API on port 8000 in both apps), tells the agent to have the person turn on Local Network access in System Settings on each Mac instead of waiting for a macOS prompt, quotes the screens and the `darkbloom cluster status` reason that say when macOS keeps a Mac off the local network (the agent then stops and asks instead of waiting), and covers the app switch that offers no **Pair again**. - Documentation only: no provider artifact changes. diff --git a/changelog.d/provider-uninstall-keep-or-remove.md b/changelog.d/provider-uninstall-keep-or-remove.md index c391778a7f..7c42794791 100644 --- a/changelog.d/provider-uninstall-keep-or-remove.md +++ b/changelog.d/provider-uninstall-keep-or-remove.md @@ -7,4 +7,5 @@ - On a Mac with both the production Darkbloom and Darkbloom Dev, uninstalling one keeps this Mac's pairing, cluster setup and cable port setup, which the other still uses, removes only its own cluster service, and says so; uninstall the other one too to remove them. When your models folder is `~/.darkbloom` itself, the summary says Darkbloom is not fully removed and what to do. A dry run also names a cluster service running without a login agent. - A cluster service that runs without its login agent (development builds, or a Mac where launchd did not take it) is now stopped before anything is deleted: with one install, any `darkbloom cluster service` is; beside the other install, only this install's, and the other's keeps running. A cluster service it doesn't stop, or can't tell apart, makes the uninstall delete nothing and say why. The two choices' lines say only what each removes on this Mac. - Uninstalling one install of a serving pair beside the other install on this Mac now stops the pair first, on both Macs, as `darkbloom stop` does, so the other Mac no longer keeps restarting its part. It says so before it waits for accepted requests to finish (up to about 6 min); if the other Mac doesn't answer, the summary names it and the command to run there. +- Uninstalling Darkbloom Dev beside the production Darkbloom also removes Darkbloom Dev's own cluster incident log (with its lock and corrupt copy), which it kept in the shared cluster folder, and names it in the summary. - For scripts and agents: `--everything` or `--keep-models` with `--yes`, and `--dry-run` (with `--json`) to list every action and path without changing anything. `darkbloom stop --uninstall` works as before. diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index 12fc3e9ce5..1fb3044720 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -468,16 +468,22 @@ checks that compile the screens without the package set theirs with `use`), the pair commands and the live operations read it (`ClusterPairSummary.cli`, `OnboardingLive.cli`), and ProviderCore's texts are named with it (`ClusterOnboardingCommand.named`). Every line that names the app as macOS -lists it under Local Network reads `ClusterService.appName` -(`BuildEnvironment.current.appDisplayName`): the screens and the link -follower's refusal. Both apps serve a pair's API on port 8000, +lists it under Local Network or in its firewall reads `ClusterService.appName` +(`BuildEnvironment.current.appDisplayName`): the screens (through +`ClusterOnboardingCommand.app`, including the pairing hint's firewall line and +the line that asks to pair again after a reinstall) and the link follower's +refusal. Both apps serve a pair's API on port 8000, so one of them serves a pair on a Mac at a time. Each keeps its own cluster incident log, owned by `DarkbloomClusterRemote` (`ClusterIncidentLog.defaultFile(homeDirectory:install:)`): production's is `~/.darkbloom/cluster/incidents.json`, another install's its own file, such as `incidents.dev.json`, which a build from before installs had their own files never reads or rewrites; a corrupt one is kept beside it under its own name -(`incidents.corrupt.json`, `incidents.dev.corrupt.json`). Every reader and writer opens this build's with +(`incidents.corrupt.json`, `incidents.dev.corrupt.json`). `ClusterIncidentLog.files` +names a log's files: the log, its lock sidecar and that corrupt copy. +`darkbloom uninstall` removes an install's own with it while the shared folder +stays for the other install; production's shared `incidents.json` stays. Every +reader and writer opens this build's with `ClusterIncidentLog.forThisInstall`. Each record also names the install that wrote it (`ClusterIncident.install`), and a build reads only its own, counting records without one as production's (`ClusterIncidentLog.install`). The @@ -3939,7 +3945,19 @@ away; mixed pairs are first-class). logs only a change, so a setting just turned on clears first; `refusalIsCurrent`). The ✗ is worded for the screen that shows it (`OnboardingLive.localNetworkLine`): a wait the joining Mac forwarded names - that Mac. + that Mac. Its line for the refused part says only that the part can't reach + the local network (`errorLines`' `refusalSaid`), and every ✗ line too long for + its bound is cut at a word, never inside a parenthesis, and marked + (`ClusterConsoleText.boundedAtWord`). `status` and `cluster status` read the + same refusal by the same rule (`ClusterLocalNetworkAccess.Refused`): on the + refused Mac its own service's state, on the leading Mac the other Mac's + status, asked (`otherMacStatus`) only while the pair has been starting past + the settle time (`otherMacRefused`). They say `not_serving` in the screens' + words, ending with the command that starts the pair again instead of the + screen's Retry (`statusWords`, through the `then` of + `localNetworkRefusalLines` and `localNetworkBlockedLines`). A stopped pair + reads stopped whatever the other Mac's presence + (`ClusterPairSummary.state(ofStatus:started:leaderMode:)`). - **The person's family:** `useMode` keeps the chosen family for every model (`OnboardingLive.keptFamily`), never inferred from the listing's order, which says nothing of the plan; `localAdopt` plans again in it only when the listed diff --git a/docs/provider/agent-setup.md b/docs/provider/agent-setup.md index 9c12276147..80776d41ee 100644 --- a/docs/provider/agent-setup.md +++ b/docs/provider/agent-setup.md @@ -206,12 +206,15 @@ On DevNet, use the [DevNet names](#devnet-testers-only) in every command below. A newly installed app has its own Secure Enclave key, but it can take over the pairing another app made on this Mac (a local build, or the production - app before DevNet). `darkbloom cluster` offers **Pair again** only when it - sees that the key changed, and it may not: then it shows the old pairing as - usual, or says the other Mac isn't answering. After installing another app - on a paired Mac, choose **Start over (unpair and set up again)** → - **Yes, start over** on both Macs in [step 5](#5-two-macs-pair-them), with the - human's go. + app before DevNet). After installing another app on a paired Mac, run + `darkbloom cluster` on both Macs in [step 5](#5-two-macs-pair-them), and act + on what each Mac shows. When it sees that the key changed, it says + ``This Mac's Secure Enclave key changed after it paired (…), so the Macs + must pair again to serve through Darkbloom.`` and offers only **Pair again** + and **Quit**: choose **Pair again** on that Mac. If it shows the old pairing + as usual instead, or says the other Mac isn't answering, choose + **Start over (unpair and set up again)** → **Yes, start over** on that Mac. + Either way, only with the human's go. With two Macs, both must show the same version. If `darkbloom update` can't bring them to the same version, **STOP** and ask. @@ -340,11 +343,15 @@ On DevNet, use the [DevNet names](#devnet-testers-only) in every command below. 3. Both Macs need free memory for the pair, and a model that single-Mac serving has loaded uses memory. Run `darkbloom status --solo` on each Mac - (on a paired Mac, plain `darkbloom status` shows the pair instead and has no - `Daemon:` line). If it shows `Daemon: running` and lists warm models, - **STOP** and ask the human whether to stop single-Mac serving there before - the pair starts. On a Mac that isn't paired yet that is `darkbloom stop`; on - one that is paired already, `darkbloom stop --solo`. + (on a paired Mac, plain `darkbloom status` shows the pair instead). On a + paired Mac, go on when it prints ``Single-Mac serving: off (this Mac serves + in its two-Mac cluster: `darkbloom cluster status`)`` (on DevNet, + `darkbloom-dev cluster status`), or when `Daemon: running` comes with + ``This is the cluster's part on this Mac, not single-Mac serving (…)``: + that is the pair's own part. Otherwise, if it shows `Daemon: running` and + lists warm models, **STOP** and ask the human whether to stop single-Mac + serving there before the pair starts. On a Mac that isn't paired yet that is + `darkbloom stop`; on one that is paired already, `darkbloom stop --solo`. ### 5. Two Macs: pair them @@ -549,8 +556,10 @@ Check all three: | Exit status | `state` | Do | |---|---|---| | `0` | `serving` | Go on | - | `3` | `loading`, `not_serving`, `unknown` | `loading`: check again every few minutes, for up to 15 minutes, without restarting anything (rule 8). Otherwise follow `next` and [troubleshooting](#troubleshooting) | - | `4` | `stopped` | The pair is stopped. **STOP**: ask the human, then run `darkbloom start` | + | `3` | `not_serving` with `reason` ``This Mac can't reach the other Mac over the cable: macOS keeps Darkbloom off the local network`` or ``The other Mac can't reach this Mac over the cable: macOS keeps Darkbloom there off the local network`` (on DevNet, both name Darkbloom Dev) | macOS keeps that Mac off the local network, and nothing changes until someone turns it on. Don't wait. **STOP**: ask the human to do this on the Mac `next` names: System Settings → Privacy & Security → Local Network → turn on “Darkbloom” (on DevNet, “Darkbloom Dev”), through Screen Sharing on a Mac with no display. Then run `darkbloom start` (on either Mac), or choose **Retry** in `darkbloom cluster` on the leader ([Local Network](#on-a-two-mac-pair)) | + | `3` | `not_serving` with another `reason` | Follow `next` and [troubleshooting](#troubleshooting) | + | `3` | `loading`, `unknown` | Check again every few minutes, for up to 15 minutes, without restarting anything (rule 8). If it still says so after 15 minutes, **STOP**: the human runs `darkbloom cluster` on the leader, which shows more | + | `4` | `stopped` | The pair is stopped. If the other Mac isn't answering too, the lines add ``The other Mac (…) isn't answering over the cable.``. **STOP**: ask the human, then run `darkbloom start` | | `5` | `other_mac_away` | The other Mac isn't answering over the cable. **STOP**: `next` says why and what to run on that Mac | | `6` | `not_paired` | This Mac isn't in a pair. Go back to [step 5](#5-two-macs-pair-them) | | `7` | `pairing_unreadable` | This Mac's pairing record couldn't be read. **STOP**: the human runs `darkbloom cluster` on this Mac to check it | @@ -610,9 +619,9 @@ otherwise ([stopping and starting again](two-mac-cluster.md#stopping-and-startin | To | On | Do | |---|---|---| | See whether the pair serves, and why not | Either Mac | `darkbloom cluster status` (`--json` for you). `darkbloom status` starts with the same block | -| Stop the pair | Either Mac | `darkbloom stop`, the same as `darkbloom cluster stop`. Both Macs stop and stay stopped after a restart. While it waits it says `Waiting for both Macs to stop; accepted requests finish first (up to about 6 min).` and `Waiting for both Macs' parts to end (up to 1 min).`. Once both parts have ended it says `Stopped on both Macs.` and `Memory freed on both Macs ✓` (exit status 0). `Asked both Macs to stop; …` with what still runs means a part hasn't ended yet (exit status 1): run `darkbloom stop` again a minute later | -| Start it again | Either Mac | `darkbloom start`. Without a terminal it starts the saved model on both Macs and says `Waiting until the pair serves (up to 10 min).`, repeating an unchanged status each minute (`Still waiting (up to 10 min in all): …`). It waits through reasons the Macs fix by themselves, then prints a result block. Exit status `0` means it serves, `3` not yet, `4` stopped, `5` the other Mac isn't answering, `1` it couldn't start. If this Mac's cluster service runs from a terminal session, it first says ``This Mac's cluster service runs from a terminal session: replacing it with its login agent, which starts at login (this Mac's part restarts).``. If macOS keeps this Mac off the local network, it ends at once with where to turn it on and ``…; then run `darkbloom start` again.``, exit status 1. In a terminal it opens the `darkbloom cluster` screen | -| Restart it with the same model | Either Mac | `darkbloom restart`, with the same result block and exit statuses, and the same waiting lines (the parts' wait is up to 5 min). If a part hasn't released its memory after the stop, it doesn't start again and exits with status 1 | +| Stop the pair | Either Mac | `darkbloom stop`, the same as `darkbloom cluster stop`. Both Macs stop and stay stopped after a restart. If it takes a while, it says `Waiting for both Macs to stop; accepted requests finish first (up to about 6 min).` and `Waiting for both Macs' parts to end (up to 1 min).`. Once both parts have ended it says `Stopped on both Macs.` and `Memory freed on both Macs ✓` (exit status 0). `Asked both Macs to stop; …` with what still runs means a part hasn't ended yet (exit status 1): run `darkbloom stop` again a minute later | +| Start it again | Either Mac | `darkbloom start`. Without a terminal it starts the saved model on both Macs; if it has to wait, it says `Waiting until the pair serves (up to 10 min).`, repeating an unchanged status each minute (`Still waiting (up to 10 min in all): …`). It waits through reasons the Macs fix by themselves, then prints a result block. Exit status `0` means it serves, `3` not yet, `4` stopped, `5` the other Mac isn't answering, `1` it couldn't start. If this Mac's cluster service runs from a terminal session, it first says ``This Mac's cluster service runs from a terminal session: replacing it with its login agent, which starts at login (this Mac's part restarts).``. If macOS keeps this Mac off the local network, it ends at once with where to turn it on and ``…; then run `darkbloom start` again.``, exit status 1. In a terminal it opens the `darkbloom cluster` screen | +| Restart it with the same model | Either Mac | `darkbloom restart`, with the same result block and exit statuses. If it takes a while, it says the same waiting lines (the parts' wait is up to 5 min). If a part hasn't released its memory after the stop, it doesn't start again and exits with status 1 | | Change or test the model, or switch between serving through Darkbloom and locally only | The leader, in a terminal | `darkbloom cluster`, or `darkbloom start` in a terminal ([below](#the-pairs-model-list)) | | Start over and pair again | Either Mac, in a terminal | `darkbloom cluster` → **Start over (unpair and set up again)** → **Yes, start over**. Then run `darkbloom cluster` on the other Mac and choose **Start over (unpair and set up again)**, or **Pair again**, if it offers it ([pairing again](two-mac-cluster.md#pairing-again)) | | Update | Every Mac | `darkbloom update` on each Mac, and the pair restarts together. Automatic updates are on by default | @@ -737,7 +746,7 @@ yet"](troubleshooting.md#a-two-mac-cluster-says-not-serving-yet) and | Signal | Cause | Do | |---|---|---| -| The leader's ✗ says ``The other Mac can't reach this Mac over the cable: macOS keeps Darkbloom there off the local network.``, then ``The other Mac (…): System Settings → Privacy & Security → Local Network → turn on “Darkbloom” (on a Mac with no display, through Screen Sharing). Then choose Retry here.``. On that other Mac: ``This Mac can't reach the other Mac over the cable: macOS keeps Darkbloom off the local network.`` (on DevNet, both name Darkbloom Dev) | macOS keeps that Mac's cluster service off the local network, so its link to the other Mac is refused | **STOP**: the human, at that Mac's screen (Screen Sharing if it has no display), opens System Settings → Privacy & Security → Local Network and turns on “Darkbloom” (on DevNet, “Darkbloom Dev”). Then choose **Retry** where the ✗ offers it (usually on the leader). `darkbloom start` on that Mac ends at once with the same lines and exit status 1 until then | +| The leader's ✗ says ``The other Mac can't reach this Mac over the cable: macOS keeps Darkbloom there off the local network.``, then ``The other Mac (…): System Settings → Privacy & Security → Local Network → turn on “Darkbloom” (on a Mac with no display, through Screen Sharing). Then choose Retry here.``. On that other Mac: ``This Mac can't reach the other Mac over the cable: macOS keeps Darkbloom off the local network.`` (on DevNet, both name Darkbloom Dev). `darkbloom cluster status` shows the same reason as ``✗ Not serving: .``, then ``Next: …`` (`--json`: `state` `not_serving`, exit status 3), on that Mac at once and on the leading Mac once its part has run 20 seconds | macOS keeps that Mac's cluster service off the local network, so its link to the other Mac is refused | **STOP**: the human, at that Mac's screen (Screen Sharing if it has no display), opens System Settings → Privacy & Security → Local Network and turns on “Darkbloom” (on DevNet, “Darkbloom Dev”). Then choose **Retry** where the ✗ offers it (usually on the leader), or run `darkbloom start` on either Mac, as `next` says. Until then, `darkbloom start` on the Mac that is kept off ends at once with the same lines and exit status 1 | | doctor: ``[FAIL] cluster savedConfiguration: saves this Mac's cluster setup, but other users can open it (mode 644); run `chmod 600 ` …`` | The saved setup is in a file other users can open | **STOP**: tell the human, and run that `chmod 600` command only with their go ([step 2](#2-log-in-and-check-the-mac-every-mac)) | | After installing another Darkbloom app on a paired Mac (DevNet beside production, or the signed release over a local build), `darkbloom cluster` shows the old pairing as usual, or says the other Mac isn't answering, and offers no **Pair again** | The apps share the pairing, and the new app may not notice that its key differs | With the human's go, choose **Start over (unpair and set up again)** → **Yes, start over** on both Macs, then pair as in step 5. It unpairs the Mac for both apps | | doctor: `[FAIL] cluster localLinkIsolation.rdma_enN: clusterSubnetInUse: The cluster port enN cannot be isolated yet (the cluster subnet 10.219/16 is already used on this Mac) …`, on a version below 0.10.8 | A known false alarm on paired Macs: macOS reaches the port's own address through a loopback route | Don't stop for it, and never run `darkbloom cluster link --remove` because of it. Verify serving instead, and update both Macs. 0.10.8 no longer reports it | @@ -811,7 +820,7 @@ Code that prints the lines quoted here: | `darkbloom cluster status`, its exit statuses and `--json` | `provider-swift/Sources/darkbloom/ClusterDiagnosticsCommand.swift` (`Cluster.Status`), `ClusterPairSummary.JSON` | | `darkbloom cluster stop` and the `link --remove` question | `provider-swift/Sources/darkbloom/ClusterServiceCommand.swift` (`Cluster.Stop.mode`), `provider-swift/Sources/darkbloom/ClusterLinkCommand.swift` (`Cluster.Link.removalGate`) | | `darkbloom uninstall` | `Uninstall`, `ProviderUninstall.invocation` | -| Local Network: the step, the follower's refusal and the lines that name it | `provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterLocalNetworkAccess.swift` (`ClusterLocalNetworkAccess.serviceState`), `provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift` (`ClusterService.followerRefusal`), `provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift` (`localNetworkRefusalLines`), `ClusterOnboardingDriver.localNetworkBlockedLines`, `provider-swift/Sources/darkbloom/ClusterLinkFollowerCommand.swift` | +| Local Network: the step, the follower's refusal and the lines that name it, also in `darkbloom cluster status` | `provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterLocalNetworkAccess.swift` (`ClusterLocalNetworkAccess.serviceState`, `statusWords`), `provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift` (`ClusterService.followerRefusal`), `provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift` (`localNetworkRefusalLines`), `ClusterOnboardingDriver.localNetworkBlockedLines`, `provider-swift/Sources/darkbloom/ClusterLinkFollowerCommand.swift` | | doctor's cluster checks and the saved setup's file mode | `provider-swift/Sources/darkbloom/DoctorClusterChecks.swift`, `provider-swift/Sources/ProviderCore/Config/ClusterConfigurationInstalledReference.swift` (`notPrivate`) | | The pair's local API port | `provider-swift/Sources/ProviderCore/Inference/Distributed/Installed/ClusterLocalServing.swift` (`sharedPort`, `servingPorts`) | | DevNet names (`darkbloom-dev`, `Darkbloom Dev.app`, `~/.darkbloom-dev`, single-Mac port `8001`) | `provider-swift/identity/provider-identity.json` | diff --git a/docs/provider/cli-reference.md b/docs/provider/cli-reference.md index 8cd92da39a..4535e4ed43 100644 --- a/docs/provider/cli-reference.md +++ b/docs/provider/cli-reference.md @@ -708,12 +708,29 @@ Next: Leave both Macs running: Darkbloom retries by itself. Or serve locally onl | Exit status | `state` | Meaning | |---|---|---| | `0` | `serving` | The pair serves (through Darkbloom, or on the leading Mac's local API) | -| `3` | `loading`, `not_serving`, `unknown` | Not serving yet: loading, or a reason in `reason` | -| `4` | `stopped` | Stopped (Stop in `darkbloom cluster`, or `darkbloom cluster stop`) | -| `5` | `other_mac_away` | The other Mac isn't answering over the cable (its cluster service is off, it sleeps, or waits for a login) | +| `3` | `loading`, `not_serving`, `unknown` | Not serving yet: loading, or a reason in `reason` (such as macOS keeping a Mac off the local network, below) | +| `4` | `stopped` | Stopped (Stop in `darkbloom cluster`, or `darkbloom cluster stop`), also while the other Mac isn't answering | +| `5` | `other_mac_away` | The pair is started and the other Mac isn't answering over the cable (its cluster service is off, it sleeps, or waits for a login) | | `6` | `not_paired` | This Mac isn't in a cluster | | `7` | `pairing_unreadable` | This Mac's pairing record couldn't be read, so it may be in a cluster; `reason` says why when known | +While macOS's Local Network setting keeps a Mac's link follower off the cable, both Macs read `not_serving` (exit 3) +by the setup screens' rule and in their words (`ClusterLocalNetworkAccess.statusWords`), instead of a load that never +ends. The DevNet app names "Darkbloom Dev" and `darkbloom-dev`. +- On the Mac that is kept off (its own cluster service's refusal), `reason` is "This Mac can't reach the other Mac over + the cable: macOS keeps Darkbloom off the local network" and `next` is "On this Mac: System Settings → Privacy & + Security → Local Network → turn on “Darkbloom” (on a Mac with no display, through Screen Sharing); then run + `darkbloom start` here, or choose Retry in `darkbloom cluster` on the other Mac." +- On the leading Mac, once its part has run about 20 seconds (the ✗'s rule; it then asks the other Mac's status), + `reason` is "The other Mac can't reach this Mac over the cable: macOS keeps Darkbloom there off the local network" + and `next` names that Mac: "The other Mac (Apple M5 Max, 128 GB): System Settings → Privacy & Security → Local + Network → turn on “Darkbloom” (on a Mac with no display, through Screen Sharing). Then run `darkbloom start` here, + or choose Retry in `darkbloom cluster`." + +A stopped pair reads `stopped` (exit 4) even while the other Mac isn't answering, as after a stop the other Mac asked +for before it left (its uninstall does): `lines` are "Stopped; last model …" and "The other Mac (…) isn't answering +over the cable.", with `other_mac.answers` `false`. + When the pairing record can't be read, the plain output is the reason and what to do, and `--json` gives `paired`, `role`, `other_mac`, `model` and `serves` as `null`: @@ -1626,7 +1643,12 @@ What no choice deletes (the summary lists them): skipped (`kept: on this Mac also uses it`), the files every install shares stay (`~/.darkbloom/cluster*` and `~/.config/darkbloom/clusters`; the rest of those folders goes), and step 2 - removes only this install's own cluster service. The screen, + removes only this install's own cluster service. One exception in the shared + folder goes: Darkbloom Dev's own incident log, with its lock and corrupt copy + (`ClusterIncidentLog.defaultFile(homeDirectory:install:)`, listed as `This + install's incident log`), which no other install reads. Production's log there + is the shared `incidents.json`, which an older build of the other install still + writes, so it stays with the folder. The screen, the dry run, `--json` and the summary list it, here for `darkbloom-dev uninstall`, and the summary's first line names the install it removed (`Darkbloom Dev is removed from this Mac.`): diff --git a/docs/provider/two-mac-cluster.md b/docs/provider/two-mac-cluster.md index fde2c13159..bbcc57e4dd 100644 --- a/docs/provider/two-mac-cluster.md +++ b/docs/provider/two-mac-cluster.md @@ -1029,10 +1029,15 @@ passed. The follower's own refusal decides: - the leading Mac's ✗ says the same of the other Mac without waiting for the start to give up, once the leading Mac's part has run about 20 seconds (long enough for the follower to dial it again, so a setting just turned on shows - first); a start run from the joining Mac's own window says it of that Mac; + first); a start run from the joining Mac's own window says it of that Mac. + Its line for that Mac then says only that its part can't reach the local + network, and a line too long for the ✗ is cut at a word, marked with "…"; - once the follower has connected, or a later dial failed another way, an earlier refusal no longer counts, and a part that has stopped counts as not blocked until its new follower dials; +- `darkbloom status` and `darkbloom cluster status` say the same on both Macs, + by the same rule: `not_serving`, with the steps on the Mac that is kept off, + instead of a load that never ends (the CLI reference quotes their words); - `darkbloom start` ends its wait with the same instruction, and says first when it replaces a cluster service running from a terminal session with the login agent. diff --git a/libs/darkbloom-cluster/Sources/DarkbloomClusterRemote/ClusterIncidentLog.swift b/libs/darkbloom-cluster/Sources/DarkbloomClusterRemote/ClusterIncidentLog.swift index 9863433185..d5654edd52 100644 --- a/libs/darkbloom-cluster/Sources/DarkbloomClusterRemote/ClusterIncidentLog.swift +++ b/libs/darkbloom-cluster/Sources/DarkbloomClusterRemote/ClusterIncidentLog.swift @@ -204,6 +204,13 @@ public final class ClusterIncidentLog: @unchecked Sendable { } public let file: URL + /// The files this log keeps on disk, in this order: the log, its lock sidecar, and the copy a corrupt log is moved + /// aside to. `darkbloom uninstall` removes an install's own with it. + public var files: [URL] { [file, lockFile, corruptCopy] } + /// Where a corrupt log is moved aside, named after its file, so each install keeps its own. + var corruptCopy: URL { + file.deletingLastPathComponent().appendingPathComponent(file.deletingPathExtension().lastPathComponent + ".corrupt.json") + } /// This install, stamped on each record it adds; its feed holds its own records and the older unstamped ones /// (`unstampedInstall`). Nil: every record, and the records it adds stay unstamped. Each install also keeps its own /// file (`defaultFile(homeDirectory:install:)`); the stamp is the second check. @@ -360,7 +367,7 @@ public final class ClusterIncidentLog: @unchecked Sendable { case .corrupt: // Kept for whoever investigates, never trusted, never blocking; named after its file, so each install // keeps its own (`incidents.corrupt.json`, `incidents.dev.corrupt.json`). - let aside = directory.appendingPathComponent(file.deletingPathExtension().lastPathComponent + ".corrupt.json") + let aside = corruptCopy _ = unlink(aside.path) _ = rename(file.path, aside.path) stored = .init(schemaVersion: ClusterIncidentFeed.schemaVersion, epoch: Self.newEpoch(), nextSeq: 1, incidents: []) diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Console/ClusterConsoleText.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Console/ClusterConsoleText.swift index 4e99af5b29..08555ea176 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Console/ClusterConsoleText.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Console/ClusterConsoleText.swift @@ -10,6 +10,32 @@ enum ClusterConsoleText { }.prefix(maximum)) } + /// `text` as one printable line of at most `maximum` characters (`bounded`). One that is longer is cut at a word, + /// never inside a parenthesis, and ends with "…" (the leader's Local Network ✗ cut a line at "(its part is still + /// running": the pair-2 re-test, R-4). + static func boundedAtWord(_ text: String, maximum: Int) -> String { + let line = bounded(text, maximum: .max) + guard line.count > maximum, maximum > 1 else { return line } + var kept = line.prefix(maximum - 1) + if let space = kept.lastIndex(of: " ") { kept = kept[.. 0: + depth -= 1 + if depth == 0 { open = nil } + default: break + } + } + if let open { kept = kept[.. String { let formatter = ISO8601DateFormatter() diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterLocalNetworkAccess.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterLocalNetworkAccess.swift index 9882c7008d..f466b0073e 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterLocalNetworkAccess.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterLocalNetworkAccess.swift @@ -191,3 +191,59 @@ public enum ClusterLocalNetworkAccess { return process.terminationStatus == 0 } } + +// MARK: - The status commands' view of a refusal + +extension ClusterLocalNetworkAccess { + /// Which Mac's link follower macOS keeps off the local network, so the pair can't serve until someone turns the + /// setting on there (`statusWords`). + public enum Refused: Sendable, Equatable { + /// This Mac's: its cluster service's follower (`serviceState` reads `.blocked`). + case thisMac + /// The other Mac's, which this Mac's part waits for (`otherMacRefused`). + case otherMac + } + + /// On the leading Mac, whether the other Mac's part reports the refusal now (`otherMacRefused(member:own:now:)`). That + /// Mac is asked (`otherMacStatus`) only once this Mac's part has run long enough for its answer to count; before + /// that, asking would not tell. + public static func otherMacRefused() -> Bool { + let own = ClusterService.published()?.child, now = Date().timeIntervalSince1970 + guard OnboardingLive.refusalIsCurrent(own: own, now: now) else { return false } + return otherMacRefused(member: otherMacStatus()?.child, own: own, now: now) + } + + /// Whether the other Mac's part reports the refusal, by the rule of the setup screen's ✗: that part runs and says so + /// (`OnboardingLive.otherMacRefused`), and this Mac's part has run long enough for one more dial to reach it + /// (`OnboardingLive.refusalIsCurrent`). + static func otherMacRefused(member: ClusterServiceStatus.Child?, own: ClusterServiceStatus.Child?, now: Double) -> Bool { + OnboardingLive.otherMacRefused(member) && OnboardingLive.refusalIsCurrent(own: own, now: now) + } + + /// The other Mac's cluster service status: one `status` command over the cable, as the ✗'s readiness asks it, within + /// `OnboardingLive.answerSeconds`; nil when it doesn't answer. + static func otherMacStatus() -> ClusterServiceStatus? { + guard let pairing = try? ClusterSetupLinkExchange.pairing(), let selection = try? LiveContext.defaultLinkSelection(), + let body = try? JSONEncoder().encode(ClusterServiceCommand(op: .status)), + let answer = try? ClusterSetupLinkExchange.command(pairing: pairing, selection: selection, peerAddress: nil, + body: body, seconds: OnboardingLive.answerSeconds) else { return nil } + return try? JSONDecoder().decode(ClusterServiceStatus.self, from: answer.reply) + } + + /// `cluster status`'s reason and next step for `refused`, in the setup screens' words: on the refused Mac the joining + /// Mac's lines (`ClusterOnboardingDriver.localNetworkBlockedLines`), on the other Mac the ✗'s + /// (`OnboardingLive.localNetworkRefusalLines`). Each ends with the command that starts the pair again, instead of the + /// screen's own step. `otherMac`: the other Mac as a sentence starts; `cli`: this build's command. + public static func statusWords(_ refused: Refused, otherMac: String, app: String, cli: String) -> (reason: String, next: String) { + switch refused { + case .thisMac: + let lines = ClusterOnboardingDriver.localNetworkBlockedLines( + app: app, then: "then run `\(cli) start` here, or choose Retry in `\(cli) cluster` on the other Mac") + return (lines[0].hasSuffix(".") ? String(lines[0].dropLast()) : lines[0], lines[1]) + case .otherMac: + let lines = OnboardingLive.localNetworkRefusalLines( + otherMac: otherMac, app: app, then: "Then run `\(cli) start` here, or choose Retry in `\(cli) cluster`") + return (lines[0], lines[1]) + } + } +} diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFlow.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFlow.swift index 929a487610..d3d3a4ca00 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFlow.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFlow.swift @@ -184,8 +184,8 @@ public enum ClusterOnboardingPairingProblem: Sendable, Equatable { public var line: String { switch self { case .keyChanged: - return "This Mac's Secure Enclave key changed after it paired (Darkbloom was reinstalled, or this Mac moved between " - + "the Darkbloom and DevNet apps), so the Macs must pair again to serve through Darkbloom." + return "This Mac's Secure Enclave key changed after it paired (\(ClusterOnboardingCommand.app) was reinstalled, or " + + "this Mac moved between the Darkbloom and DevNet apps), so the Macs must pair again to serve through Darkbloom." } } } @@ -1027,13 +1027,14 @@ public struct ClusterOnboardingPairing: Sendable, Equatable { public static let otherMacLine = "Run `darkbloom cluster` on the other Mac." /// Said once while the pairing still has not found the other Mac (2026-11-04, the candidate on pair 2: a firewall - /// that drops the discovery probe left both Macs waiting with no hint); the wait goes on. - public static let otherMacNotFoundLines = [ + /// that drops the discovery probe left both Macs waiting with no hint); the wait goes on. The firewall lists the app + /// by its own name (`ClusterOnboardingCommand.app`), as Local Network does. + public static var otherMacNotFoundLines: [String] { [ "The other Mac isn't found yet. Check that:", "· the other Mac shows this screen too (run `darkbloom cluster` there);", - "· macOS's firewall lets Darkbloom in on both Macs (System Settings → Network → Firewall);", + "· macOS's firewall lets \(ClusterOnboardingCommand.app) in on both Macs (System Settings → Network → Firewall);", "· or pair directly: press q, run `darkbloom cluster pair --listen` on this Mac (it prints its cable address),", - " then `darkbloom cluster pair --connect ` on the other Mac, and `darkbloom cluster` on both again."] + " then `darkbloom cluster pair --connect ` on the other Mac, and `darkbloom cluster` on both again."] } /// The question after the code, and its two answers (a menu: arrows and enter, or 1 and 2). Each Mac answers for /// itself: a "yes" passed on from the other Mac could come from a Mac in between. diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift index cba527c1ae..d12c806896 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift @@ -1563,7 +1563,7 @@ final class OnboardingLive: @unchecked Sendable { } if let ready = once.ready { return .success(ready) } if let refused = Self.localNetworkRefusalLines(line: once.line, otherMac: Self.sentence(there), app: ClusterService.appName) { - return .failure(.init(refused + lastErrors(fallback: nil, own: ownPart(since: began)))) + return .failure(.init(refused + lastErrors(fallback: nil, own: ownPart(since: began), refusalSaid: true))) } // Each line once (a part that keeps restarting alternated two lines every 2 s); a part that ends the // same way again and again is said and the wait ends: both Macs keep trying by themselves. An end is @@ -1634,7 +1634,9 @@ final class OnboardingLive: @unchecked Sendable { /// The last error each Mac's part reported, one line per Mac, also for parts still running (shown on screen after a /// start that did not finish, instead of a log path). `own`: this Mac's part as the caller already read it. - func lastErrors(fallback: String?, own snapshot: (child: ClusterServiceStatus.Child?, worker: OwnWorker)? = nil) -> [String] { + /// `refusalSaid`: the ✗ already says a Local Network refusal and what to do (`errorLines`). + func lastErrors(fallback: String?, own snapshot: (child: ClusterServiceStatus.Child?, worker: OwnWorker)? = nil, + refusalSaid: Bool = false) -> [String] { let other: (child: ClusterServiceStatus.Child?, unreachable: String?) do { let status = try JSONDecoder().decode(ClusterServiceStatus.self, from: try command(.init(op: .status), seconds: 10)) @@ -1645,9 +1647,10 @@ final class OnboardingLive: @unchecked Sendable { // This start's: since its wait began (the ✗'s diagnostics file too), else no longer ago than a wait lasts. let own = snapshot ?? ownPart(since: lock.withLock { waitBegan } ?? Date().addingTimeInterval(-Self.readyWaitSeconds)) var lines = Self.errorLines(here: Self.sentence(here), there: Self.sentence(there), own: own.child, - other: other.child, otherUnreachable: other.unreachable, ownWorker: own.worker) + other: other.child, otherUnreachable: other.unreachable, ownWorker: own.worker, + refusalSaid: refusalSaid) if let fallback { lines.append("Last progress: \(fallback).") } - return lines.map { ClusterConsoleText.bounded(context.clean($0), maximum: 300) } + return lines.map { ClusterConsoleText.boundedAtWord(context.clean($0), maximum: 300) } } /// A part's last error when its link to the other Mac closed (`ClusterLinkControlChannel.closed`): its end follows @@ -1692,12 +1695,17 @@ final class OnboardingLive: @unchecked Sendable { return String(line[cut.upperBound...]) } - /// One line per Mac: the last error each Mac's part reported (`lastErrors`). + /// One line per Mac: the last error each Mac's part reported (`lastErrors`). `refusalSaid`: the Local Network ✗ already + /// says the refusal and what to do, so a part refused by it is said plainly instead of in its follower's own words + /// (the pair-2 re-test, R-4); any other ✗ keeps the part's reason (A-3). static func errorLines(here: String, there: String, own: ClusterServiceStatus.Child?, other: ClusterServiceStatus.Child?, - otherUnreachable: String?, ownWorker: OwnWorker = .notSeen) -> [String] { + otherUnreachable: String?, ownWorker: OwnWorker = .notSeen, refusalSaid: Bool = false) -> [String] { func line(_ mac: String, _ child: ClusterServiceStatus.Child?, unreachable: String? = nil) -> String { if let unreachable { return "\(mac): did not answer over the cable (\(unreachable))." } guard let child else { return "\(mac): no report." } + if refusalSaid, child.lastError?.hasPrefix(ClusterService.localNetworkReasonPrefix) == true { + return "\(mac): its part " + (child.running ? "is running and " : "") + "can't reach the local network." + } if let error = child.lastError { return "\(mac): \(error)" + (child.running ? " (its part is still running)." : ".") } if let end = child.lastEnd, !child.running { return "\(mac): its part ended (\(end))." } return "\(mac): " + (child.running ? "its part is running, no error reported." : "its part is not running.") @@ -1866,11 +1874,12 @@ final class OnboardingLive: @unchecked Sendable { } /// The ✗ when the other Mac can't reach this one over the cable for that reason: why, and what to do there. It can't - /// clear until someone turns the setting on, so the wait ends at once. - static func localNetworkRefusalLines(otherMac: String, app: String) -> [String] { + /// clear until someone turns the setting on, so the wait ends at once. `then`: the step once it's on (`cluster status` + /// names its command instead: `ClusterLocalNetworkAccess.statusWords`). + static func localNetworkRefusalLines(otherMac: String, app: String, then: String = "Then choose Retry here") -> [String] { ["The other Mac can't reach this Mac over the cable: macOS keeps \(app) there off the local network", "\(otherMac): System Settings → Privacy & Security → Local Network → turn on “\(app)” (on a Mac with no display, " - + "through Screen Sharing). Then choose Retry here."] + + "through Screen Sharing). \(then)."] } /// The live row's line once the other Mac's part reports that refusal (`readinessOnce`). diff --git a/provider-swift/Sources/ProviderCore/Service/Uninstall/ProviderUninstallPlan.swift b/provider-swift/Sources/ProviderCore/Service/Uninstall/ProviderUninstallPlan.swift index b593ab7fb4..81b8cfd5a0 100644 --- a/provider-swift/Sources/ProviderCore/Service/Uninstall/ProviderUninstallPlan.swift +++ b/provider-swift/Sources/ProviderCore/Service/Uninstall/ProviderUninstallPlan.swift @@ -1,3 +1,4 @@ +import DarkbloomClusterRemote import DarkbloomClusterSecurity import Darwin import Foundation @@ -7,6 +8,8 @@ import Foundation public struct ProviderUninstallPaths: Sendable, Equatable { /// The home directory with its own links resolved (`/var` → `/private/var`), so every root is canonical. public let home: URL + /// The install these paths are for. + public let environment: BuildEnvironment /// `~/.darkbloom`: the app, the `bin/` links, logs, pairing, cluster setup and service state. public let installDirectory: URL public let appBundleName: String @@ -33,6 +36,7 @@ public struct ProviderUninstallPaths: Sendable, Equatable { public init(home: URL, environment: BuildEnvironment = .current, commandLinkDirectory: URL = URL(fileURLWithPath: "/usr/local/bin")) { let home = URL(fileURLWithPath: Self.canonical(home.path), isDirectory: true) self.home = home + self.environment = environment installDirectory = environment.installDirectory(home: home) appBundleName = environment.appBundleName configDirectory = environment.configDirectory(home: home) @@ -289,6 +293,7 @@ extension ProviderUninstall { add("The `\(paths.commandLink.lastPathComponent)` command link", paths.commandLink, kind: .command) add(installFolderLabel(paths), paths.installDirectory, kind: .command) // Another install on this Mac reads the same pairing, cluster setup and cable port setup: they stay with it. + var ownIncidents: [ProviderUninstallItem] = [] if let other = paths.otherEnvironment { let files = paths.sharedClusterFiles var shared = ProviderUninstallItem(label: sharedClusterLabel, @@ -305,13 +310,35 @@ extension ProviderUninstall { shared.ownClusterAgentPlist = FileManager.default.fileExists(atPath: ownPlist.path) ? ownPlist.path : nil items.append(shared) protected += files.map { (ProviderUninstallPaths.canonical($0.path), "the cluster files \(installName(other)) uses") } + ownIncidents = ownIncidentLog(paths) } // What finishes the uninstall once the models are out: the settings that named the folder are gone by then. let again = "\(paths.installDirectory.path)/bin/\(paths.commandLink.lastPathComponent) uninstall" let advice = ". To finish, move the models you want to keep out of it, then run `\(again)` again, which deletes the rest of it" - return items.compactMap { around($0, protected, advice: advice) } + var listed = items.compactMap { around($0, protected, advice: advice) } + // Before the install folder, so the app still goes last. + listed.insert(contentsOf: ownIncidents, at: listed.firstIndex { $0.path == paths.installDirectory.path } ?? listed.endIndex) + return listed } + /// This install's own incident log in the shared cluster folder (`ClusterIncidentLog.forThisInstall`): its log, + /// lock and corrupt copy, which no other install reads, so they go while the folder stays. Production's log is the + /// folder's shared `incidents.json`, which a build of the other install from before installs had their own logs + /// still writes: it stays with the folder. + static func ownIncidentLog(_ paths: ProviderUninstallPaths) -> [ProviderUninstallItem] { + let install = paths.environment.rawValue + let file = ClusterIncidentLog.defaultFile(homeDirectory: paths.home, install: install) + guard file != ClusterIncidentLog.defaultFile(homeDirectory: paths.home) else { return [] } + let labels = [ownIncidentsLabel, "This install's incident log lock", "This install's incident log, set aside as corrupt"] + return zip(labels, ClusterIncidentLog(file: file, install: install).files).compactMap { label, url in + var info = stat() + guard lstat(url.path, &info) == 0 else { return nil } + return ProviderUninstallItem(label: label, path: url.path, bytes: measure(url).bytes, verdict: .remove, reason: nil) + } + } + + static let ownIncidentsLabel = "This install's incident log" + /// `item` with the protected folders inside it left out (and measured without them); nil when it lies inside one. private static func around(_ item: ProviderUninstallItem, _ protected: [(path: String, what: String)], advice: String) -> ProviderUninstallItem? { diff --git a/provider-swift/Sources/darkbloom/ClusterPairCommands.swift b/provider-swift/Sources/darkbloom/ClusterPairCommands.swift index 718405bf9f..baac62ace6 100644 --- a/provider-swift/Sources/darkbloom/ClusterPairCommands.swift +++ b/provider-swift/Sources/darkbloom/ClusterPairCommands.swift @@ -260,7 +260,7 @@ enum ClusterPairCommands { case .notServing: // A reason the Macs mend by themselves (an Apple verification retry, memory freeing, the coordinator // retrying) is waited through, as the setup screen does; a final one ends the wait. - if ClusterPairSummary.isFinalReason(summary.reason) { return summary } + if summary.localNetworkRefused != nil || ClusterPairSummary.isFinalReason(summary.reason) { return summary } status = summary.lines.first case .stopped: stoppedLooks += 1 diff --git a/provider-swift/Sources/darkbloom/ClusterPairSummary+Live.swift b/provider-swift/Sources/darkbloom/ClusterPairSummary+Live.swift index 61597a6b84..7395bfcce3 100644 --- a/provider-swift/Sources/darkbloom/ClusterPairSummary+Live.swift +++ b/provider-swift/Sources/darkbloom/ClusterPairSummary+Live.swift @@ -137,13 +137,24 @@ extension ClusterPairSummary { guard summary.paired, summary.role != nil, let operations = try? ClusterOnboardingOperations.live(.clusterService(config: config, worker: nil)) else { return summary } // A bounded wait that ran out: this Mac's own view stands (the other Mac's answer unknown). - guard let status = statusLines(leads: summary.leads, slow: slow, noticeAfter: noticeAfter, operations.status) else { - return summary + if let status = statusLines(leads: summary.leads, slow: slow, noticeAfter: noticeAfter, operations.status) { + summary.read(status: status, leaderMode: summary.leads ? ClusterService.publishedLive()?.control?.mode : nil) } - summary.read(status: status, leaderMode: summary.leads ? ClusterService.publishedLive()?.control?.mode : nil) + summary.read(localNetworkRefused: localNetworkRefusal(of: summary)) return summary } + /// Which Mac's follower macOS keeps off the local network, by the setup screens' rule: on the Mac that follows, its + /// own service's state, as `start` reads it; on the leading Mac, the other Mac's status, asked only while the pair has + /// been starting longer than one more dial takes (the ✗'s rule). + private static func localNetworkRefusal(of summary: ClusterPairSummary) -> ClusterLocalNetworkAccess.Refused? { + guard summary.started else { return nil } + guard summary.leads else { return ClusterLocalNetworkAccess.serviceState() == .blocked ? .thisMac : nil } + guard summary.state == .unknown || (summary.state == .loading && summary.lines.first?.hasPrefix("Starting ") == true) + else { return nil } + return ClusterLocalNetworkAccess.otherMacRefused() ? .otherMac : nil + } + /// This Mac's own view of the cluster, from its cluster service's last status (no other Mac is asked): stopped, the /// other Mac away, or what this Mac's part says (a coordinator-paired part's pair line, the leader's local session). static func ownState(started: Bool, own: ClusterServiceStatus?) -> (State, String?) { diff --git a/provider-swift/Sources/darkbloom/ClusterPairSummary.swift b/provider-swift/Sources/darkbloom/ClusterPairSummary.swift index c7a98546cb..8ad30900b0 100644 --- a/provider-swift/Sources/darkbloom/ClusterPairSummary.swift +++ b/provider-swift/Sources/darkbloom/ClusterPairSummary.swift @@ -48,6 +48,8 @@ struct ClusterPairSummary: Sendable, Equatable { var started: Bool = false var serviceRunning: Bool = false var startsAtLogin: Bool = false + /// Which Mac's link follower macOS keeps off the local network, when that keeps the pair from serving. + var localNetworkRefused: ClusterLocalNetworkAccess.Refused? var state: State = .unknown /// Why it does not serve, in the screens' words. var reason: String? @@ -340,10 +342,12 @@ extension ClusterPairSummary { || first.contains("registering both Macs with the coordinator") { return (.loading, nil) } + // A stopped pair reads stopped whatever the other Mac's presence: a stop it asked for before it left. if let leaderMode, otherMacAwayModes.contains(leaderMode) { + guard started else { return (.stopped, nil) } return (.otherMacAway, first.hasSuffix(".") ? String(first.dropLast()) : first) } - if saysOtherMacSilent(first) { return (.otherMacAway, nil) } + if saysOtherMacSilent(first) { return (started ? .otherMacAway : .stopped, nil) } return (started ? .unknown : .stopped, nil) } @@ -363,6 +367,7 @@ extension ClusterPairSummary { + "have been turned off with `\(Self.cli) cluster stop --service`, or that Mac is asleep, off, or waiting for " + "someone to log in. On that Mac, run `\(Self.cli) start` (or `\(Self.cli) cluster`)." case .notServing: + if let words = localNetworkWords { return words.next } let reason = reason ?? "" if ClusterOnboardingNotServing.isMissingLogin(reason) { return "Run `\(Self.cli) login` on each Mac named, then `\(Self.cli) cluster` on \(leadingMac). Or serve " @@ -387,16 +392,42 @@ extension ClusterPairSummary { mutating func read(status: [String], leaderMode: String?) { lines = status.filter { !$0.trimmingCharacters(in: .whitespaces).isEmpty } (state, reason) = Self.state(ofStatus: lines, started: started, leaderMode: leaderMode) + let away = leaderMode.map(Self.otherMacAwayModes.contains) == true || lines.first.map(Self.saysOtherMacSilent) == true + if state == .stopped, away { + // Stopped, then the other Mac's absence: not its countdown to serving alone, which a stopped pair never does. + lines = [stoppedLine, "\(ClusterOnboardingMacName.sentence(otherMac)) isn't answering over the cable."] + } if role == .member { // The lines came from the leading Mac unless they say it didn't answer (`saysOtherMacSilent`). - otherMacAnswers = state != .otherMacAway - } else if state == .otherMacAway { + otherMacAnswers = !away + } else if away { otherMacAnswers = false } else if let leaderMode, Self.otherMacPresentModes.contains(leaderMode) { otherMacAnswers = true } } + /// "Stopped; last model Qwen 3.8 27B.", as the leading Mac's status says a stopped pair. + var stoppedLine: String { "Stopped" + (model.map { "; last model " + $0 } ?? "") + "." } + + /// Reads a Local Network refusal over the status lines: a start that can't go on until someone turns the setting on + /// reads not serving, in the setup screens' words (`localNetworkWords`), instead of a load that never ends. A pair + /// that serves or stopped reads as it did. + mutating func read(localNetworkRefused refused: ClusterLocalNetworkAccess.Refused?) { + guard let refused, started, [.loading, .unknown, .otherMacAway].contains(state) else { return } + localNetworkRefused = refused + state = .notServing + reason = localNetworkWords?.reason + } + + /// The setup screens' words for `localNetworkRefused` (`ClusterLocalNetworkAccess.statusWords`). + var localNetworkWords: (reason: String, next: String)? { + localNetworkRefused.map { + ClusterLocalNetworkAccess.statusWords($0, otherMac: ClusterOnboardingMacName.sentence(otherMac), app: ClusterService.appName, + cli: Self.cli) + } + } + /// `darkbloom cluster status`: who leads, the model and its split, how it serves, whether it serves now (the /// screens' words) and what to do. var clusterStatusLines: [String] { @@ -437,7 +468,7 @@ extension ClusterPairSummary { case .notServing: return ["\(ClusterOnboardingDriver.failed) " + ClusterOnboardingNotServing.title(reason: reason ?? "no reason known")] + rest.filter { $0.trimmingCharacters(in: .whitespaces) != ClusterOnboardingNotServing.remedy(forReason: reason ?? "") } - case .stopped: return ["\u{25A0} " + (first ?? "Stopped" + (model.map { "; last model " + $0 } ?? "") + ".")] + rest + case .stopped: return ["\u{25A0} " + (first ?? stoppedLine)] + rest case .loading: return ["\u{2026} " + (first ?? "Loading")] + rest case .otherMacAway: return [ClusterOnboardingDriver.failed + " " + (first ?? "\(ClusterOnboardingMacName.sentence(otherMac)) isn't answering.")] + rest case .unknown, .notPaired, .pairingUnreadable: return lines diff --git a/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift b/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift index 7e08c033ae..74775d2235 100644 --- a/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift +++ b/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift @@ -143,6 +143,8 @@ import Darwin theServingMarkerFollowsOnlyASettledServingLine() theServingModelsTestNeverMarksAStart() pairingSaysWhatToCheckWhenTheOtherMacIsNotFound() + // R-3 (the pair-2 re-test, 2026-11-04): the hint's firewall line named production's app in the DevNet app. + pairingLinesNameTheApp() alreadyServingTestsAgainOrSaysWhyNot() aDeadPendingStartIsClearedOnlyWhileStillRecorded() modeChoiceOffersBothWithTheFastestMeasuredFirst() @@ -3246,6 +3248,24 @@ import Darwin expect(!quick.text.contains(P.otherMacNotFoundLines[0]), "found: no hint") } + /// R-3 (the pair-2 re-test): the hint's firewall line said "Darkbloom" in the DevNet app, whose firewall entry is its own + /// name. It, and the line that asks to pair again after a reinstall, name the app as the Local Network lines do. + static func pairingLinesNameTheApp() { + ClusterOnboardingCommand.useApp("Darkbloom Dev") + defer { ClusterOnboardingCommand.useApp("Darkbloom") } + let run = TerminalRun(operations(Recorder(), pairEvents: leaderEvents, pairResult: .paired(role: .leader, peerName: "Apple M3 Ultra, 256 GB"), + pairHintSeconds: 0.3, pairWait: 1.5)) + expect(run.waitFor(codeQuestion, seconds: 20), "app name: the pairing goes on"); run.type("y") + expect(run.waitFor(prompt(2), count: 2), "app name: the list"); run.type("\r") + expect(run.finish() == 0, "app name: served") + expect(run.text.contains(" · macOS's firewall lets Darkbloom Dev in on both Macs (System Settings → Network → Firewall);\n"), + "app name: the firewall line names the app: \(run.text)") + expect(!run.text.contains("lets Darkbloom in"), "app name: never production's app") + expect(ClusterOnboardingPairingProblem.keyChanged.line + .contains("(Darkbloom Dev was reinstalled, or this Mac moved between the Darkbloom and DevNet apps)"), + "app name: the line that asks to pair again names the app that was reinstalled") + } + /// Validator D's m1 meets m9: the list says "serving now" only beside a settled serving line, the one shown as ✓. A /// start still checking with Darkbloom (its line now, and an older leader's "Serving … (checking …)") and a /// published failed test read "last used", with no ✓. diff --git a/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift b/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift index f62af8aa55..7686ac3d69 100644 --- a/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift +++ b/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift @@ -1623,3 +1623,128 @@ struct ClusterBoundedWaitScopeTests { #expect(status.contains("live read: bounded") && !status.contains("live read: unbounded"), "\(status)") } } + +@Suite("Status truths: a Local Network refusal is said, and a stopped pair reads stopped") +struct ClusterStatusTruthTests { + private static let app = ClusterService.appName + private static let starting = ["Starting Qwen 3.8 27B."] + + @Test("R-1: the Mac macOS keeps off the local network reads not serving, in the joining screen's words") + func refusedFollowerIsNotServingOnTheMember() { + var member = pair(role: .member) + member.read(status: Self.starting, leaderMode: nil) + #expect(member.state == .loading) + member.read(localNetworkRefused: .thisMac) + let cli = ClusterPairSummary.cli + let blocked = ClusterOnboardingDriver.localNetworkBlockedLines(app: Self.app, + then: "then run `\(cli) start` here, or choose Retry in `\(cli) cluster` on the other Mac") + #expect(member.state == .notServing && member.exitCode == 3) + #expect(member.reason == "This Mac can't reach the other Mac over the cable: macOS keeps \(Self.app) off the local network") + #expect(member.reason.map { $0 + "." } == blocked[0]) + #expect(member.next == blocked[1]) + let json = member.json + #expect(json.state == "not_serving" && json.reason == member.reason && json.next == member.next && json.exitCode == 3) + } + + @Test("R-1: the leading Mac reads not serving once the other Mac's refusal counts, in the ✗'s words") + func refusedFollowerIsNotServingOnTheLeader() { + var leader = pair(role: .leader) + leader.read(status: Self.starting, leaderMode: "cluster") + leader.read(localNetworkRefused: .otherMac) + let cli = ClusterPairSummary.cli + #expect(leader.state == .notServing && leader.exitCode == 3) + #expect(leader.reason == "The other Mac can't reach this Mac over the cable: macOS keeps \(Self.app) there off the local network") + #expect(leader.next == "The other Mac (Apple M5 Max, 128 GB): System Settings → Privacy & Security → Local Network → " + + "turn on “\(Self.app)” (on a Mac with no display, through Screen Sharing). Then run `\(cli) start` here, or choose " + + "Retry in `\(cli) cluster`.") + #expect(leader.clusterStatusLines.contains("✗ Not serving: \(leader.reason ?? "")."), "\(leader.clusterStatusLines)") + // Never over a pair that serves, or one that stopped. + var serving = pair(role: .leader) + serving.read(status: ["Serving Qwen 3.8 27B through Darkbloom on both Macs (tensor parallel)."], leaderMode: "cluster") + serving.read(localNetworkRefused: .otherMac) + #expect(serving.state == .serving && serving.reason == nil) + var stopped = pair(role: .member, started: false) + stopped.read(status: ["Stopped; last model Qwen 3.8 27B."], leaderMode: nil) + stopped.read(localNetworkRefused: .thisMac) + #expect(stopped.state == .stopped && stopped.reason == nil) + } + + @Test("R-1: a script start on the leading Mac ends its wait on the other Mac's refusal, with its steps, and exits 3") + func leaderStartEndsItsWaitOnTheRefusal() async { + let result = await #expect(processExitsWith: .exitCode(3), observing: [\.standardOutputContent]) { + var refused = observed(Self.starting[0]) + refused.read(localNetworkRefused: .otherMac) + // A wait that went on would read the next look, which serves. + let looks = Looks([observed(Self.starting[0]), refused, + observed("Serving Qwen 3.8 27B through Darkbloom on both Macs (tensor parallel).")]) + try await exitWithPair(pair(), actions: pairActions()) { _ in + try await ClusterPairSummary.$readerForTesting.withValue({ live in live ? looks.next() : pair() }) { + try await ClusterPairCommands.$waitForTesting.withValue(.init(seconds: 60, interval: 0)) { + try await runCLICommand(Start.self, ["start"]) + } + } + } + } + let out = lines(result?.standardOutputContent) + let cli = ClusterPairSummary.cli + #expect(out.contains("✗ Not serving: The other Mac can't reach this Mac over the cable: macOS keeps \(Self.app) there off the " + + "local network."), "\(out)") + #expect(out.contains { $0.hasPrefix(" Next: The other Mac (Apple M5 Max, 128 GB): System Settings → ") + && $0.hasSuffix(" Then run `\(cli) start` here, or choose Retry in `\(cli) cluster`.") }, "\(out)") + #expect(!out.contains { $0.contains("Serving Qwen") }, "the wait ended at the refusal: \(out)") + } + + @Test("R-1: the other Mac's refusal counts by the ✗'s rule: its running part reports it, and this Mac's part has run 20 s") + func otherMacRefusalFollowsTheScreensRule() { + let now = Date().timeIntervalSince1970 + let refused = ClusterServiceStatus.Child(running: true, starts: 1, + lastError: ClusterService.localNetworkReasonPrefix + ": macOS refused the dial") + let own = ClusterServiceStatus.Child(running: true, starts: 1, startedAt: now - 25) + #expect(OnboardingLive.refusalIsCurrent(own: own, now: now)) + #expect(ClusterLocalNetworkAccess.otherMacRefused(member: refused, own: own, now: now)) + let young = ClusterServiceStatus.Child(running: true, starts: 1, startedAt: now - 5) + #expect(!OnboardingLive.refusalIsCurrent(own: young, now: now)) + #expect(!ClusterLocalNetworkAccess.otherMacRefused(member: refused, own: young, now: now), "before one more dial it may be stale") + var ended = refused + ended.running = false + #expect(!ClusterLocalNetworkAccess.otherMacRefused(member: ended, own: own, now: now), "an ended part's refusal is history") + } + + @Test("R-5: a stopped pair reads stopped whatever the other Mac's presence, and says it isn't answering") + func stoppedPairStaysStopped() { + var leader = pair(role: .leader, started: false) + leader.read(status: ["The other Mac (Apple M5 Max, 128 GB) is gone; this Mac cannot serve Qwen 3.8 27B alone, so nothing " + + "of it runs after 9 min 58 s unless it returns first."], leaderMode: "cannotServe") + #expect(leader.state == .stopped && leader.exitCode == 4) + #expect(leader.otherMacAnswers == false) + #expect(leader.lines == ["Stopped; last model Qwen 3.8 27B.", "The other Mac (Apple M5 Max, 128 GB) isn't answering over the cable."]) + var member = pair(role: .member, started: false) + member.read(status: ["The other Mac (Apple M5 Max, 128 GB) did not answer over the cable: timed out"], leaderMode: nil) + #expect(member.state == .stopped && member.exitCode == 4 && member.otherMacAnswers == false) + // A pair that was started and lost the other Mac still reads away. + var away = pair(role: .leader) + away.read(status: ["The other Mac (Apple M5 Max, 128 GB) is gone; this Mac serves alone."], leaderMode: "waiting") + #expect(away.state == .otherMacAway && away.exitCode == 5) + } + + @Test("R-1: the refusal's words name this build's app and command (a dev-identity build shows the DevNet wording)") + func refusalWordsNameThisBuild() async { + let result = await #expect(processExitsWith: .success, observing: [\.standardOutputContent]) { + ClusterOnboardingCommand.use(BuildEnvironment.current.cliName) + var member = pair(role: .member) + member.read(status: Self.starting, leaderMode: nil) + member.read(localNetworkRefused: .thisMac) + var leader = pair(role: .leader) + leader.read(status: Self.starting, leaderMode: "cluster") + leader.read(localNetworkRefused: .otherMac) + for line in [member.reason, member.next, leader.reason, leader.next] { print(line ?? "none") } + } + let out = lines(result?.standardOutputContent).filter { !$0.isEmpty } + for line in out { print("refusal words (\(BuildEnvironment.current.rawValue)): " + line) } + let app = BuildEnvironment.current.appDisplayName, cli = BuildEnvironment.current.cliName + #expect(out.count == 4, "\(out)") + #expect(out.allSatisfy { $0.contains(app) }, "\(out)") + #expect(out.count == 4 && out[1].contains("turn on “\(app)”") && out[1].contains("`\(cli) start`") && out[3].contains("`\(cli) cluster`"), + "\(out)") + } +} diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterServiceStopReasonTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterServiceStopReasonTests.swift index a7f02c702b..aeb8abee96 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterServiceStopReasonTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterServiceStopReasonTests.swift @@ -322,6 +322,8 @@ struct ClusterServiceStopReasonTests { let app = "Darkbloom Dev", leader = "The other Mac (Apple M5 Ultra, 256 GB)" let own = OnboardingLive.localNetworkRefusalLines(line: OnboardingLive.localNetworkLine(forwarded: false), otherMac: leader, app: app) #expect(own?.first == "The other Mac can't reach this Mac over the cable: macOS keeps Darkbloom Dev there off the local network") + #expect(own?.last == "\(leader): System Settings → Privacy & Security → Local Network → turn on “Darkbloom Dev” (on a Mac with no " + + "display, through Screen Sharing). Then choose Retry here.", "the screen's own step: \(String(describing: own))") let forwarded = OnboardingLive.localNetworkRefusalLines(line: OnboardingLive.localNetworkLine(forwarded: true), otherMac: leader, app: app) #expect(forwarded?.first == "This Mac can't reach the other Mac over the cable: macOS keeps Darkbloom Dev off the local network." @@ -330,6 +332,51 @@ struct ClusterServiceStopReasonTests { #expect(OnboardingLive.localNetworkRefusalLines(line: "starting", otherMac: leader, app: app) == nil) } + /// The pair-2 re-test (R-4): the leader's Local Network ✗ said the refusal three times, the last in the follower's own + /// words. That ✗'s own lines already say it plainly, so each Mac's line there only says that its part can't reach the + /// local network; any other ✗ keeps the part's own reason (A-3). + @Test func theLocalNetworkCrossSaysTheRefusalOnce() { + let reason = ClusterService.refusalReason(": macOS refused the dial before the cable was tried. Allow Darkbloom under System " + + "Settings > Privacy & Security > Local Network (once), or start the follower from a session that has that access.") + let refused = ClusterServiceStatus.Child(running: true, starts: 1, lastEnd: nil, restartInSeconds: nil, lastError: reason) + let running = ClusterServiceStatus.Child(running: true, starts: 1, lastEnd: nil, restartInSeconds: nil, lastError: nil) + let ended = ClusterServiceStatus.Child(running: false, starts: 1, lastEnd: "exit 0", restartInSeconds: nil, lastError: reason) + let there = "The other Mac (Apple M5 Max, 128 GB)" + let cross = OnboardingLive.errorLines(here: "This Mac", there: there, own: running, other: refused, otherUnreachable: nil, + refusalSaid: true) + #expect(cross == ["This Mac: its part is running, no error reported.", + "\(there): its part is running and can't reach the local network."], "\(cross)") + let forwarded = OnboardingLive.errorLines(here: "This Mac", there: there, own: ended, other: running, otherUnreachable: nil, + refusalSaid: true) + #expect(forwarded[0] == "This Mac: its part can't reach the local network.", "the joining Mac's own: \(forwarded)") + let other = OnboardingLive.errorLines(here: "This Mac", there: there, own: running, other: refused, otherUnreachable: nil) + #expect(other[1] == "\(there): \(reason) (its part is still running).", "any other ✗ keeps A-3's reason: \(other)") + } + + /// R-4: a line too long for the ✗ (300 characters) is cut at a word, never inside a parenthesis, and says it was cut. + @Test func aLongLineIsCutAtAWordOutsideAnyParenthesis() { + // The leader's fourth line on the re-test, 302 characters; it was cut at "(its part is still running". + let line = "The other Mac (Apple M5 Max, 128 GB): its part can't reach the local network: macOS refused the dial before the " + + "cable was tried. Allow Darkbloom Dev under System Settings > Privacy & Security > Local Network (once), or start the " + + "follower from a session that has that access (its part is still running)." + let cut = ClusterConsoleText.boundedAtWord(line, maximum: 300) + #expect(cut.count <= 300 && cut.hasSuffix(" from a session that has that access…"), "\(cut)") + #expect(cut.filter { $0 == "(" }.count == cut.filter { $0 == ")" }.count, "never inside a parenthesis: \(cut)") + #expect(ClusterConsoleText.boundedAtWord("one two three four", maximum: 12) == "one two…", "at a word") + #expect(ClusterConsoleText.boundedAtWord("This Mac: its part is running, no error reported.", maximum: 300) + == "This Mac: its part is running, no error reported.", "a short line is kept whole") + } + + /// R-3 (the pair-2 re-test): the pairing hint's firewall line and the line that asks to pair again after a reinstall + /// name this build's app, as macOS lists it (its firewall entry), not production's in the DevNet app. + @Test func thePairingLinesNameThisBuildsApp() { + let app = BuildEnvironment.current.appDisplayName + #expect(ClusterOnboardingPairing.otherMacNotFoundLines + .contains("· macOS's firewall lets \(app) in on both Macs (System Settings → Network → Firewall);")) + #expect(ClusterOnboardingPairingProblem.keyChanged.line + .contains("(\(app) was reinstalled, or this Mac moved between the Darkbloom and DevNet apps)")) + } + private static let refusedLines = "2026-11-04T07:32:14Z link-follower: link refused: connectFailed (unreachable)\n" + "2026-11-04T07:32:14Z link-follower: this process may not reach the local network: macOS refused the dial before the cable " + "was tried. Allow darkbloom under System Settings > Privacy & Security > Local Network (once), or start the follower from a " diff --git a/provider-swift/Tests/ProviderCoreTests/Service/ProviderUninstallTests.swift b/provider-swift/Tests/ProviderCoreTests/Service/ProviderUninstallTests.swift index fa843f5714..bf4593a310 100644 --- a/provider-swift/Tests/ProviderCoreTests/Service/ProviderUninstallTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Service/ProviderUninstallTests.swift @@ -1,3 +1,4 @@ +import DarkbloomClusterRemote import Foundation import Testing @testable import ProviderCore @@ -601,6 +602,42 @@ struct ProviderUninstallTests { "the pairing and cluster setup are in ~/.darkbloom, not in ~/.darkbloom-dev") } + @Test("R-6: beside the other install, this install's own incident log goes; the shared one and the other's stay") + func ownIncidentLogGoesBesideTheOtherInstall() async throws { + for (this, other) in [(BuildEnvironment.dev, BuildEnvironment.prod), (.prod, .dev)] { + let fixture = try Fixture.make() + defer { fixture.remove() } + let shared = try installBoth(fixture) + // Each install's incident log as the log itself names it (`ClusterIncidentLog.defaultFile`), with its lock + // and the copy a corrupt log is moved aside to. + func incidentFiles(_ install: BuildEnvironment) -> [URL] { + let log = ClusterIncidentLog.defaultFile(homeDirectory: fixture.home, install: install.rawValue) + let folder = log.deletingLastPathComponent() + return [log, folder.appendingPathComponent(log.lastPathComponent + ".lock"), + folder.appendingPathComponent(log.deletingPathExtension().lastPathComponent + ".corrupt.json")] + } + for file in incidentFiles(this) + incidentFiles(other) { try fixture.write(file) } + let paths = ProviderUninstallPaths(home: fixture.home, environment: this, + commandLinkDirectory: fixture.paths.commandLink.deletingLastPathComponent()) + let plan = ProviderUninstall.Plan(cli: this.cliName, services: [], items: ProviderUninstall.inventory(paths), + pairing: fixture.pairing) + let report = await fixture.run(.keepModels, items: plan.items, pairing: fixture.pairing) + let summary = ProviderUninstall.summary(report, plan: plan) + transcript("\(this.rawValue)-summary-beside-\(other.rawValue)-incidents", summary, fixture) + for file in shared { #expect(fixture.exists(file), "\(this): \(file.lastPathComponent) stays") } + for file in incidentFiles(other) { #expect(fixture.exists(file), "\(this): the other install's \(file.lastPathComponent) stays") } + #expect(!report.failed && !report.incomplete, "\(this): \(report.steps)") + if this == .prod { + // Production's own log is the shared folder's `incidents.json`, which an older build of the other install + // still writes: it stays with the shared folder. + for file in incidentFiles(this) { #expect(fixture.exists(file), "prod: \(file.lastPathComponent) stays") } + } else { + for file in incidentFiles(this) { #expect(!fixture.exists(file), "\(this): its own \(file.lastPathComponent) goes") } + #expect(summary.contains { $0.hasPrefix(" done Delete This install's incident log") }, "\(this): named") + } + } + } + @Test("B12 step 2: beside the other install, only this install's cluster agent goes; the pair and the other's agent stay") func stepTwoRemovesOnlyThisInstallsClusterAgent() async throws { for (this, other) in [(BuildEnvironment.dev, BuildEnvironment.prod), (.prod, .dev)] {