From 0fa4f19b0f34486dd1ae0dec2d82dc99f800138d Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:25:30 -0800 Subject: [PATCH 01/20] fix(cluster): a pair Mac follows the other Mac forward to a newer release at once The pair's coordinated update moved an older Mac only at the shared 30-minute slot, and only the rollback was followed between slots. A Mac whose partner updated alone (single-Mac updater, watchdog, manual update, asleep at the slot) stayed behind, and after R5-4 the newer member waits quietly for a leader setup the older leader never makes. The minute's follow check now also returns .otherMacNewer when the other Mac runs a strictly newer release that is not quarantined here; with automatic updates on the supervisor runs the pair's cycle at the next tick (once per release, then the slots), which finds the other Mac ready (ClusterPairUpdate.partnerState: running == target). With them off it logs the version and `darkbloom update`. Co-Authored-By: Claude Opus 5.5 --- ...ster-pair-version-split-follows-forward.md | 5 +++ .../Update/ClusterPairUpdateCycle.swift | 9 ++++ .../darkbloom/ClusterMemberSupervisor.swift | 25 ++++++++++- .../ClusterServiceUpdateTests.swift | 42 +++++++++++++++++++ .../Update/ClusterPairUpdateTests.swift | 28 +++++++++++++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 changelog.d/cluster-pair-version-split-follows-forward.md diff --git a/changelog.d/cluster-pair-version-split-follows-forward.md b/changelog.d/cluster-pair-version-split-follows-forward.md new file mode 100644 index 0000000000..4c1c2f9f9e --- /dev/null +++ b/changelog.d/cluster-pair-version-split-follows-forward.md @@ -0,0 +1,5 @@ +### A pair Mac left on an older release catches up with the other Mac within a minute + +- When one Mac of a `darkbloom cluster` pair already runs a newer release (it updated alone, through single-Mac serving, `darkbloom update`, or because this Mac was asleep at the pair's update slot), the other Mac's cluster service notices within a minute and updates right away, instead of waiting for the pair's next update slot. +- With automatic updates off, the cluster service log says which version the other Mac runs and to run `darkbloom update` on this Mac. +- Each newer release triggers one immediate update attempt. If that attempt fails, the Mac tries again at the pair's update slots as before. A release quarantined on this Mac is never installed this way. diff --git a/provider-swift/Sources/ProviderCore/Update/ClusterPairUpdateCycle.swift b/provider-swift/Sources/ProviderCore/Update/ClusterPairUpdateCycle.swift index 60eb364a91..038025e7c6 100644 --- a/provider-swift/Sources/ProviderCore/Update/ClusterPairUpdateCycle.swift +++ b/provider-swift/Sources/ProviderCore/Update/ClusterPairUpdateCycle.swift @@ -138,6 +138,9 @@ public final class ClusterPairUpdateCycle: @unchecked Sendable { case otherMacStillRuns(String) /// Another update or recovery holds the update lease; the next check tries again. case busy + /// The other Mac already runs this newer release (it updated alone). Nothing was changed: the supervisor runs + /// the pair's cycle at once instead of at the slot, and that cycle finds the other Mac ready. + case otherMacNewer(String) /// The cycle that followed it ended as an update cycle ends: `.restarted` once the earlier release is restored /// and the restart asked for. case followed(AutoUpdateController.Outcome) @@ -172,6 +175,12 @@ public final class ClusterPairUpdateCycle: @unchecked Sendable { Self.installed(recorded) != mine { return .otherMacStillRuns("the other Mac still runs v\(mine), which is quarantined on this Mac") } + // The other Mac updated alone and runs a newer release: this Mac follows it forward, never into one it quarantined. + if let running = SemanticVersion(Self.installed(recorded) ?? updater.currentVersion), + let theirs = SemanticVersion(progress.running), running < theirs, + recorded?.quarantine?.version != progress.running { + return .otherMacNewer(progress.running) + } // A Mac that runs the release it quarantined (installed again with `--override-quarantine`) rolled nothing back. guard let quarantined = progress.quarantined, progress.running != quarantined, Self.installed(recorded) == quarantined else { return .nothingToFollow } diff --git a/provider-swift/Sources/darkbloom/ClusterMemberSupervisor.swift b/provider-swift/Sources/darkbloom/ClusterMemberSupervisor.swift index cb77e15160..6cdf61128a 100644 --- a/provider-swift/Sources/darkbloom/ClusterMemberSupervisor.swift +++ b/provider-swift/Sources/darkbloom/ClusterMemberSupervisor.swift @@ -96,6 +96,10 @@ final class ClusterMemberSupervisor: @unchecked Sendable { private var followNotice: String? /// A deferred follow is tried again only at the pair's next update slot, as a deferred update is (under `lock`). private var followDeferredUntil: Double = 0 + /// The newer release the other Mac runs, which the next tick updates to without waiting for the slot, and the one + /// already tried that way (under `lock`): one immediate cycle per release, then the slots as usual. + private var forwardDue: String? + private var forwardTried: String? // The candidate this run's service is (main loop only), until it is promoted. private var candidate: String? private var updatedServiceServes = false @@ -488,9 +492,13 @@ final class ClusterMemberSupervisor: @unchecked Sendable { } else if !configuration.autoUpdate { restAsDisabled(pair, now: now) return startFollowCheckIfDue(pair, pid: pid, now: now) - } else if !slotDue { + } else if !slotDue, lock.withLock({ forwardDue }) == nil { return startFollowCheckIfDue(pair, pid: pid, now: now) } + lock.withLock { + if let due = forwardDue { forwardTried = due } + forwardDue = nil + } // A cycle at or after the slot is that slot's. if slotDue { pairSlot = pair.clusterID().map { ClusterMemberUpdateSlot.nextSlot(after: now, clusterID: $0) } } lock.withLock { pairCycleRunning = true } @@ -525,6 +533,7 @@ final class ClusterMemberSupervisor: @unchecked Sendable { switch outcome { case .cannotFollow(let reason): notice = "not following the other Mac's rollback: " + reason case .otherMacStillRuns(let reason): notice = reason + case .otherMacNewer(let version): notice = self.followForward(version) default: notice = nil } // From the deferral, not the check's start: a follow that ran past a slot waits for the next. @@ -545,6 +554,20 @@ final class ClusterMemberSupervisor: @unchecked Sendable { } } + /// The other Mac runs `version`, newer than this Mac's: with automatic updates on, the next tick runs the pair's cycle + /// at once (once per release; after that, the slots), which finds the other Mac ready. The line says what happens. + private func followForward(_ version: String) -> String { + let here = "the other Mac runs v\(version), newer than this Mac's v\(ProviderCore.version)" + guard configuration.autoUpdate else { + return here + ", and automatic updates are off on this Mac: run `\(BuildEnvironment.current.cliName) update` on this Mac" + } + return lock.withLock { + guard forwardTried != version else { return here + ": this Mac tries again at the pair's next update slot" } + forwardDue = version + return here + ": updating this Mac now, without waiting for the pair's update slot" + } + } + /// A rollback since the progress was written (a candidate's third failed start, while no cycle ran) reaches the /// other Mac with the next follow check: only the quarantine changes, the rest stays as the last cycle left it. private func publishQuarantine(_ pair: PairUpdate) { diff --git a/provider-swift/Tests/DarkbloomCLITests/ClusterServiceUpdateTests.swift b/provider-swift/Tests/DarkbloomCLITests/ClusterServiceUpdateTests.swift index 60c0fdf258..17675cdc83 100644 --- a/provider-swift/Tests/DarkbloomCLITests/ClusterServiceUpdateTests.swift +++ b/provider-swift/Tests/DarkbloomCLITests/ClusterServiceUpdateTests.swift @@ -144,6 +144,48 @@ struct ClusterServiceUpdateTests { #expect(follows.all == ["follow"], "the next check is a minute later") } + /// A cluster ID whose update slot is at least ten minutes away, so no slot fires during the test. + private func distantClusterID() -> String { + let now = Date().timeIntervalSince1970 + for index in 0..<100_000 { + let id = "slot-far-\(index)" + if ClusterMemberUpdateSlot.nextSlot(after: now, clusterID: id) - now > 600 { return id } + } + return "slot-far-none" + } + + /// The other Mac runs a newer release: with automatic updates on, the supervisor runs the pair's cycle at once, long + /// before its slot, so this Mac catches up within the follow check's minute. With them off it runs none. + @Test(arguments: [true, false]) + func supervisorFollowsAnOtherMacOnANewerReleaseAtOnce(autoUpdate: Bool) async throws { + let directory = try temporaryDirectory("cluster-follow-forward") + defer { try? FileManager.default.removeItem(at: directory) } + let calls = Recorder(), follows = Recorder(), reexecs = Recorder() + let supervisor = ClusterMemberSupervisor(configuration: configuration(directory: directory, script: "exec sleep 60", + autoUpdate: autoUpdate, clusterID: distantClusterID(), reexecs: reexecs, + follow: { _, _ in + follows.add("follow") + return .otherMacNewer("2.0.0") + }) { request, log, restart in + calls.add(request ?? "cycle") + log("cluster update: test cycle") + try? await restart("2.0.0") + return .restarted(from: "1.0.0", to: "2.0.0", drained: true) + }) + let run = Task { await supervisor.run() } + #expect(await waitUntil(seconds: 5) { !follows.all.isEmpty }) + if autoUpdate { + #expect(await waitUntil(seconds: 15) { !reexecs.all.isEmpty }, "the cycle ran before the slot and restarted the service") + #expect(calls.all == ["cycle"]) + #expect(state(directory)?.lastRun?.end == "stopped to restart into v2.0.0") + } else { + try await Task.sleep(nanoseconds: 3_000_000_000) + #expect(calls.all.isEmpty && reexecs.all.isEmpty, "automatic updates are off: `darkbloom update` is the operator's") + } + supervisor.requestStop() + #expect(await run.value == 0) + } + // MARK: - The slot /// At the pair's slot the cycle runs beside the serving service; its restart stops the service and the supervisor diff --git a/provider-swift/Tests/ProviderCoreTests/Update/ClusterPairUpdateTests.swift b/provider-swift/Tests/ProviderCoreTests/Update/ClusterPairUpdateTests.swift index c7325b4d05..f0b9a87d6d 100644 --- a/provider-swift/Tests/ProviderCoreTests/Update/ClusterPairUpdateTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Update/ClusterPairUpdateTests.swift @@ -558,6 +558,34 @@ struct ClusterPairUpdateTests { try peer.fixture.updater(baseURL: peer.baseURL).beginUpdateSession(operation: "lease-check").release() } + /// The other Mac already runs a newer release (it updated alone: its single-Mac updater, `darkbloom update` there, + /// or this Mac was asleep at the slot). The follow check says so, and the cycle the supervisor then runs at once + /// finds the other Mac ready and updates this Mac. The same or an older release on the other Mac is nothing to follow. + @Test func partnerOnANewerReleaseIsFollowedForwardAtOnce() async throws { + let behind = try await PairMac.make(part: false), ahead = try await PairMac.make(part: false) + defer { Task { await behind.cleanUp(); await ahead.cleanUp() } } + try await ahead.installCandidate() + try ahead.promote() + func publish(_ running: String) { + ClusterPairUpdate.writeProgress(.init(phase: .idle, running: running, writtenAt: Date().timeIntervalSince1970), + to: ahead.progressPath) + } + let log = Lines(), restarts = Restarts() + for running in ["1.0.0", "0.9.0"] { + publish(running) + let outcome = await behind.cycle(partner: ahead, log: log).followRollback { restarts.record("behind", $0) } + #expect(outcome == .nothingToFollow, "the other Mac on v\(running)") + } + publish("2.0.0") + let outcome = await behind.cycle(partner: ahead, log: log).followRollback { restarts.record("behind", $0) } + #expect(outcome == .otherMacNewer("2.0.0")) + #expect(restarts.all.isEmpty, "the follow check itself installs nothing") + + let cycle = await behind.cycle(partner: ahead, log: log).run { restarts.record("behind", $0) } + #expect(cycle == .restarted(from: "1.0.0", to: "2.0.0", drained: true), "\(log.all)") + #expect(restarts.all == ["behind:2.0.0"]) + } + /// Both Macs keep v2 quarantined: neither's next check installs it again, each one's progress says so, and the Mac /// that rolled back first finds nothing to follow in its peer's rollback (no loop). A peer that keeps another /// release for rollback cannot follow and changes nothing. From 99181ed70df9ba840c9cafe9c36bb8c7179c60cd Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:27:56 -0800 Subject: [PATCH 02/20] =?UTF-8?q?fix(cluster):=20the=20start's=20=E2=9C=97?= =?UTF-8?q?=20names=20a=20version=20split,=20the=20Mac=20behind=20and=20`d?= =?UTF-8?q?arkbloom=20update`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The start-wait ✗ read the other Mac's whole service status but never compared its version (pairUpdate.running, published by supervisors from 0.10.7 on) with this Mac's, so a pair split across releases looped on 'its service reports its part running and no error…'. errorLines now leads with both versions and the command on the Mac that's behind, in either direction; one version or an unknown one keeps the lines as before. Co-Authored-By: Claude Opus 5.5 --- ...ster-pair-version-split-follows-forward.md | 1 + .../Onboarding/ClusterOnboardingLive.swift | 19 +++++++++++---- .../ClusterServiceStopReasonTests.swift | 24 +++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/changelog.d/cluster-pair-version-split-follows-forward.md b/changelog.d/cluster-pair-version-split-follows-forward.md index 4c1c2f9f9e..87276f2b33 100644 --- a/changelog.d/cluster-pair-version-split-follows-forward.md +++ b/changelog.d/cluster-pair-version-split-follows-forward.md @@ -3,3 +3,4 @@ - When one Mac of a `darkbloom cluster` pair already runs a newer release (it updated alone, through single-Mac serving, `darkbloom update`, or because this Mac was asleep at the pair's update slot), the other Mac's cluster service notices within a minute and updates right away, instead of waiting for the pair's next update slot. - With automatic updates off, the cluster service log says which version the other Mac runs and to run `darkbloom update` on this Mac. - Each newer release triggers one immediate update attempt. If that attempt fails, the Mac tries again at the pair's update slots as before. A release quarantined on this Mac is never installed this way. +- When a pair's start fails because the two Macs run different Darkbloom versions, the error now says so first: "The two Macs run different Darkbloom versions: the other Mac (…) runs 0.10.7, this Mac runs 0.10.8." It then names the Mac to run `darkbloom update` on, instead of guessing at the link. This works with an other Mac on 0.10.7 or later whose cluster service publishes its version. diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift index a0dade7954..c2fc30dd65 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift @@ -1827,18 +1827,18 @@ final class OnboardingLive: @unchecked Sendable { /// `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?) + let other: (child: ClusterServiceStatus.Child?, unreachable: String?, version: String?) do { let status = try JSONDecoder().decode(ClusterServiceStatus.self, from: try command(.init(op: .status), seconds: 10)) - other = (status.child, nil) + other = (status.child, nil, status.pairUpdate?.running) } catch { - other = (nil, (error as? ClusterSetupFailure)?.text ?? "\(error)") + other = (nil, (error as? ClusterSetupFailure)?.text ?? "\(error)", nil) } // 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, - refusalSaid: refusalSaid) + refusalSaid: refusalSaid, thisVersion: ProviderCore.version, otherVersion: other.version) if let fallback { lines.append("Last progress: \(fallback).") } return lines.map { ClusterConsoleText.boundedAtWord(context.clean($0), maximum: 300) } } @@ -1889,7 +1889,16 @@ final class OnboardingLive: @unchecked Sendable { /// 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, refusalSaid: Bool = false) -> [String] { + otherUnreachable: String?, ownWorker: OwnWorker = .notSeen, refusalSaid: Bool = false, + thisVersion: String? = nil, otherVersion: String? = nil) -> [String] { + // The Macs run different versions (one updated alone): that is the cause, with the Mac and the command, and no + // guess at the link. `otherVersion` is what the other Mac's supervisor publishes (`pairUpdate.running`). + if let thisVersion, let otherVersion, thisVersion != otherVersion, + let behindHere = ClusterOnboardingLeaderStep.isOlder(thisVersion, than: otherVersion) { + let older = behindHere ? "this Mac" : there.prefix(1).lowercased() + there.dropFirst() + return ["The two Macs run different Darkbloom versions: \(there) runs \(otherVersion), this Mac runs \(thisVersion).", + "On \(older), run `darkbloom update`; the pair starts once both Macs run \(behindHere ? otherVersion : thisVersion)."] + } 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." } diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterServiceStopReasonTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterServiceStopReasonTests.swift index 2afa6c127f..bc9694af33 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterServiceStopReasonTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterServiceStopReasonTests.swift @@ -67,6 +67,30 @@ struct ClusterServiceStopReasonTests { "what each Mac can and can't say: \(lines)") } + /// The two Macs run different versions (one updated alone, account 668cf2b3 on 11-04): the ✗ says so first, with + /// both versions and the command on the Mac that's behind, in each direction, instead of guessing at the link. + @Test func aVersionSplitIsNamedFirstWithTheMacAndTheCommand() { + let own = ClusterServiceStatus.Child(running: false, starts: 13, lastEnd: "exit 1", restartInSeconds: 30, lastError: "closed") + let other = ClusterServiceStatus.Child(running: true, starts: 1, lastEnd: nil, restartInSeconds: nil, lastError: nil) + let there = "The other Mac (Apple M4 Max, 128 GB)" + let behindThere = OnboardingLive.errorLines(here: "This Mac", there: there, own: own, other: other, otherUnreachable: nil, + thisVersion: "0.10.8", otherVersion: "0.10.7") + #expect(behindThere.first == "The two Macs run different Darkbloom versions: The other Mac (Apple M4 Max, 128 GB) runs 0.10.7, this Mac runs 0.10.8.") + #expect(behindThere.dropFirst().first == "On the other Mac (Apple M4 Max, 128 GB), run `darkbloom update`; the pair starts once both Macs run 0.10.8.") + #expect(!behindThere.contains { $0.contains("doesn't report its worker restarting") }, "no guess at the cause: \(behindThere)") + + let behindHere = OnboardingLive.errorLines(here: "This Mac", there: there, own: own, other: other, otherUnreachable: nil, + thisVersion: "0.10.8", otherVersion: "0.10.9") + #expect(behindHere.dropFirst().first == "On this Mac, run `darkbloom update`; the pair starts once both Macs run 0.10.9.") + + let same = OnboardingLive.errorLines(here: "This Mac", there: there, own: own, other: other, otherUnreachable: nil, + thisVersion: "0.10.9", otherVersion: "0.10.9") + let unknown = OnboardingLive.errorLines(here: "This Mac", there: there, own: own, other: other, otherUnreachable: nil, + thisVersion: "0.10.9", otherVersion: nil) + let before = OnboardingLive.errorLines(here: "This Mac", there: there, own: own, other: other, otherUnreachable: nil) + #expect(same == before && unknown == before, "one version, or the other Mac's unknown: the lines as before") + } + /// A part that ends by itself keeps its own reason, without the live row's progress word. @Test func aPartThatEndsByItselfKeepsItsReason() { let line = "starting; this Mac's part ended (exit 1: Tensor-parallel shard load needs 49.08 GiB) and starts again by itself" From 8cc1fa3350ec0ef7654a570e330aadb8c2953d04 Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:42:52 -0800 Subject: [PATCH 03/20] fix(cluster): single-Mac serving blocking the pair is said on both screens, and nothing loops on it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 0.10.9 DevNet, pair-2 (f1): with single-Mac serving (process 68099) on the joining MacBook, the leader showed the block, but the joining Mac said "registering with the coordinator" for minutes; `cluster status` said "Both Macs keep trying by themselves"; and the leader's part ended and restarted every 38 s. - The joining Mac's window reads single-Mac serving on both Macs before each look of the leader and shows the same ✗, naming its own provider, `darkbloom stop --solo`, and that the leading Mac offers the stop. The leader's block line is the block (`followed` .soloBlocked), never an offered pair to wait on. It follows the start by itself once single-Mac serving stops. - Each Mac's status reports single-Mac serving whenever no part of its own holds the lock, not only once a part is wanted, so the leader sees it before starting; it also publishes `heldBack`, why its part can't start. - The leader's service reads the member's held-back reason at each sync and doesn't start its part while the other Mac reports one (`ClusterControlPartChoice. waitsForOtherMac`): no 38-second start-and-end loop. Serving alone never waits. - `next` says what to run on both Macs; a scripted `darkbloom start` ends its wait at once for this reason (`isFinalReason`). Co-Authored-By: Claude Opus 5.5 --- .../cluster-solo-block-both-screens.md | 6 ++ docs/provider/agent-setup.md | 2 +- docs/provider/two-mac-cluster.md | 12 +++- .../Installed/ClusterServiceWire.swift | 3 + .../Onboarding/ClusterControlLeadership.swift | 8 +++ .../Onboarding/ClusterOnboardingFollow.swift | 35 +++++++++- .../ClusterOnboardingSoloServing.swift | 24 +++++++ .../Onboarding/ClusterService.swift | 36 ++++++++++- .../darkbloom/ClusterPairSummary.swift | 8 ++- .../ClusterControlChecks/ControlChecks.swift | 6 ++ .../OnboardingChecks.swift | 64 +++++++++++++++++++ .../ClusterPairCommandsTests.swift | 18 ++++++ .../Distributed/SoloBlockPeerTests.swift | 34 ++++++++++ 13 files changed, 247 insertions(+), 9 deletions(-) create mode 100644 changelog.d/cluster-solo-block-both-screens.md create mode 100644 provider-swift/Tests/ProviderCoreTests/Inference/Distributed/SoloBlockPeerTests.swift diff --git a/changelog.d/cluster-solo-block-both-screens.md b/changelog.d/cluster-solo-block-both-screens.md new file mode 100644 index 0000000000..9b2c0f9a3b --- /dev/null +++ b/changelog.d/cluster-solo-block-both-screens.md @@ -0,0 +1,6 @@ +### Both Macs say when single-Mac serving blocks the pair + +- The Mac that joined now shows the same ✗ as the leading Mac when single-Mac serving blocks the pair. The ✗ names its own single-Mac provider and process, and gives `darkbloom stop --solo`. It also says that the leading Mac's screen offers to stop it and start the pair. Before, that window said "registering with the coordinator" for minutes. Once single-Mac serving stops, it follows the start by itself. +- Each Mac reports single-Mac serving as soon as it runs, not only once the pair wants to start. So the leading Mac sees it before anything starts. +- The leading Mac's part no longer starts and ends every 38 seconds while the other Mac reports single-Mac serving. It waits until that changes. The same rule covers any reason the other Mac reports that its part can't start. +- In `darkbloom cluster status`, `Next:` now says what to run on both Macs instead of "Both Macs keep trying by themselves". A `darkbloom start` run from a script ends its wait at once for this reason. diff --git a/docs/provider/agent-setup.md b/docs/provider/agent-setup.md index a2186441eb..ba7acc1e70 100644 --- a/docs/provider/agent-setup.md +++ b/docs/provider/agent-setup.md @@ -781,7 +781,7 @@ yet"](troubleshooting.md#a-two-mac-cluster-says-not-serving-yet) and | Signal | Cause | Do | |---|---|---| | The human stopped clustering, and the Mac is online but gets no requests; `darkbloom status` says ``The other Mac (…) hasn't answered for 15 min; this Mac's part stopped.`` or ``The pair hasn't served for … min``; on 0.10.8 `darkbloom start --solo` says ``This Mac's part of the pair holds its serving lock`` | The Mac kept the pair's saved start, so its cluster service ran its part of a pair that no longer forms. That part registers only as a pair member, which gets no ordinary requests | With the human's go, run `darkbloom start` on that Mac (0.10.9 or later): it stops the leftover part and serves this Mac alone. On 0.10.8: `darkbloom cluster pair --status`, then `darkbloom cluster pair --forget `, then `darkbloom start`. Never plain `darkbloom stop` on 0.10.8 for this: it acts on the pair | -| ``✗ The pair can't start: a single-Mac Darkbloom provider (process ) is serving on , …``; a cluster status or log line ``a single-Mac Darkbloom provider (process ) is serving on this Mac, so this Mac's part can't start``; an incident `local_provider_running`. In 0.10.8 the same cause read ``another update operation owns the lock (pid , provider-instance)`` and looped ``this Mac's part ended … and starts again by itself`` | Single-Mac serving runs on that Mac and holds its one serving lock, so the pair's part can't start there. It doesn't end by itself | **STOP**: ask the human whether to stop single-Mac serving on each Mac named. With their go, run `darkbloom stop --solo` on that Mac, then `darkbloom start` (on DevNet, `darkbloom-dev`). In `darkbloom cluster`, **Stop single-Mac serving on both Macs and start the pair** does both. Never plain `darkbloom stop` for this: on a paired Mac it stops the pair and leaves single-Mac serving running | +| ``✗ The pair can't start: a single-Mac Darkbloom provider (process ) is serving on , …``; a cluster status or log line ``a single-Mac Darkbloom provider (process ) is serving on this Mac, so this Mac's part can't start``; an incident `local_provider_running`. In 0.10.8 the same cause read ``another update operation owns the lock (pid , provider-instance)`` and looped ``this Mac's part ended … and starts again by itself`` | Single-Mac serving runs on that Mac and holds its one serving lock, so the pair's part can't start there. It doesn't end by itself | **STOP**: ask the human whether to stop single-Mac serving on each Mac named. With their go, run `darkbloom stop --solo` on that Mac, then `darkbloom start` (on DevNet, `darkbloom-dev`). In `darkbloom cluster`, **Stop single-Mac serving on both Macs and start the pair** does both. Both Macs' `darkbloom cluster status` say the block, with `next` ``Single-Mac serving doesn't stop by itself: …`` (`state` `not_serving`, exit status 3), and the joining Mac's window shows the same ✗. Neither Mac keeps restarting its part meanwhile; don't wait for it to clear by itself Never plain `darkbloom stop` for this: on a paired Mac it stops the pair and leaves single-Mac serving running | | 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”; if it isn't listed, click Allow when macOS asks on that Mac's screen, the next time Darkbloom dials over the cable (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, and add that macOS lists Darkbloom Dev as “Darkbloom”). `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 from about 20 seconds into its part, steadily after that while that Mac stays refused | 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” (the DevNet app is listed under that name too), or, with no such row, clicks **Allow** when macOS asks on that screen. 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 | diff --git a/docs/provider/two-mac-cluster.md b/docs/provider/two-mac-cluster.md index 38226391fc..e126d26cee 100644 --- a/docs/provider/two-mac-cluster.md +++ b/docs/provider/two-mac-cluster.md @@ -1293,7 +1293,17 @@ serving on both Macs and start the pair** (or on the one Mac named) and **Leave**. It stops nothing unless you choose to, and it never retries by itself. Each Mac's cluster service doesn't start its part while single-Mac serving runs there. Its status names that provider, so the other Mac's screen says the -same thing instead of "no error reported". Plain `darkbloom stop` on a paired +same thing instead of "no error reported". The Mac that joined shows the same +✗ in its own window, naming its own provider ("… is serving on this Mac"), +with `darkbloom stop --solo` and that the leading Mac's screen offers the stop. +It never says it is registering with the coordinator meanwhile, and it follows +the start by itself once single-Mac serving stops. The leading Mac's part +waits too: it doesn't start, and end again every half minute, while the other +Mac reports single-Mac serving. `darkbloom cluster status` says the block on +both Macs, with `Next:` ``Single-Mac serving doesn't stop by itself: run +`darkbloom stop --solo` on each Mac named, then `darkbloom start` on either +Mac. …``, and a scripted `darkbloom start` ends its wait at once with that +reason (exit status 3). Plain `darkbloom stop` on a paired Mac stops the pair, not single-Mac serving. If the leading Mac doesn't answer, `darkbloom stop` says so and that `darkbloom cluster stop --local-only` stops this Mac alone. diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Installed/ClusterServiceWire.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Installed/ClusterServiceWire.swift index 1d61138e53..f1c5b51d08 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Installed/ClusterServiceWire.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Installed/ClusterServiceWire.swift @@ -100,6 +100,9 @@ public struct ClusterServiceStatus: Codable, Sendable, Equatable { /// never ends by itself, so this Mac's part doesn't start beside it and the other Mac's start names it. Nil when /// none, and from an older build. public var soloServing: SoloServing? = nil + /// Why this Mac's part can't start now, for a reason that doesn't clear by itself (single-Mac serving here): the + /// leading Mac's part waits for it to change instead of starting and ending again. Nil when none, and from an older build. + public var heldBack: String? = nil /// Whether the pair actually runs on this Mac (`ClusterPairWatch`): `serving` is only the saved intent, which stays /// on for a Mac whose other Mac stopped taking part. Nil from an older build (read the intent then). public var pairRunning: Bool? = nil diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterControlLeadership.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterControlLeadership.swift index 57332c8fd8..556371be58 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterControlLeadership.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterControlLeadership.swift @@ -585,6 +585,14 @@ public enum ClusterControlPartChoice: Sendable, Equatable { backoffElapsed || key != endedKey } + /// Why this Mac's part of the pair (`key` "cluster:…") waits instead of starting: the other Mac reports its own part + /// can't start for a reason that doesn't clear by itself (`otherMacHeldBack`; single-Mac serving there). A part started + /// anyway only waits for its missing follower and ends again (every 38 s on pair-2). Never for serving alone ("solo:"). + public static func waitsForOtherMac(key: String, otherMacHeldBack: String?) -> String? { + guard key.hasPrefix("cluster:"), let reason = otherMacHeldBack, !reason.isEmpty else { return nil } + return reason + } + /// Whether the leader's lease tells its members that the cluster runs (they run their parts only then): while it /// runs as planned, and while it waits inside the absence grace for a member to return. public static func leaseSaysRunning(mode: ClusterControlNode.Mode, serving: Bool) -> Bool { diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift index 7eee3459fa..ff2db1bc45 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift @@ -124,12 +124,16 @@ extension ClusterOnboardingDriver { /// Set to serve through Darkbloom, but not offered (`ClusterOnboardingReady.notOfferedReason`): the start's outcome, /// never a wait for a coordinator that doesn't have the pair. case notOffered + /// Single-Mac serving blocks the pair (`ClusterOnboardingSoloServing`): never a wait for the coordinator (0.10.9 + /// DevNet, pair-2: this window said "registering with the coordinator" for minutes while its own part waited). + case soloBlocked } static func followed(_ status: [String]) -> FollowedStart { guard let first = status.first else { return .notStarted } if first.hasPrefix("Serving ") { return first.contains(ClusterOnboardingReady.offerPendingWords) ? .starting : .serving } if let reason = ClusterOnboardingNotServing.reason(inStatusLine: first) { + if ClusterOnboardingSoloServing.isBlock(reason) { return .soloBlocked } if status.dropFirst().contains(where: ClusterOnboardingReady.isTestFailedNote) { return .testFailed } return ClusterOnboardingReady.isNotOffered(reason) ? .notOffered : .offered } @@ -158,6 +162,10 @@ extension ClusterOnboardingDriver { let timing = operations.followTiming console.say(" " + waitingForStartLine(leader)) let looks = ClusterOnboardingMailbox() + // Single-Mac serving on either Mac, read before each look of the leading Mac: this Mac's own block wins over the + // leader's progress or step, and is said here as on the leading Mac's screen. + let solos = ClusterOnboardingMailbox<[ClusterOnboardingSoloServing]>() + var soloShown: [ClusterOnboardingSoloServing]? var asking = false, asked = Date.distantPast var begun = Date() var started: Date?, latest: String?, stage = 0, step: ClusterOnboardingLeaderStep?, lastStatus: String? @@ -178,8 +186,25 @@ extension ClusterOnboardingDriver { if !asking, Date().timeIntervalSince(asked) >= timing.pollSeconds { asking = true asked = Date() - Thread.detachNewThread { looks.post(operations.leaderStatus?() ?? .init(lines: operations.status(), step: nil)) } + Thread.detachNewThread { + solos.post(operations.soloServing()) + looks.post(operations.leaderStatus?() ?? .init(lines: operations.status(), step: nil)) + } + } + if let solo = solos.take().last { + if !solo.isEmpty, solo != soloShown { + soloShown = solo + console.settle() + console.result(false, ClusterOnboardingSoloServing.title(solo) + ".", + ClusterOnboardingSoloServing.remedies(solo) + [ClusterOnboardingSoloServing.leaderOffersLine(leader)]) + } else if solo.isEmpty, soloShown != nil { + soloShown = nil + console.settle() + console.say(" " + ClusterOnboardingSoloServing.followClearedLine) + } } + // Nothing starts while it runs, so no bound runs out meanwhile: each bound starts again once it stopped. + if soloShown != nil { begun = Date(); if started != nil { started = Date() } } if let look = looks.take().last { asking = false let status = look.lines @@ -229,7 +254,9 @@ extension ClusterOnboardingDriver { sayOnce(" The other Mac: " + latest + ".") if !saidRetry, latest.contains("part ended") { saidRetry = true; console.say(retryOnLeaderLine(leader)) } } - switch seen { + switch soloShown == nil ? seen : .soloBlocked { + case .soloBlocked: + break case .serving: console.settle() return followServed(status, leader: leader, operations, console) @@ -263,7 +290,9 @@ extension ClusterOnboardingDriver { console.say(notStartedAfterLine) return 1 } - if let start, let width = console.liveWidth { + if soloShown != nil { + console.progress({ _ in ClusterOnboardingSoloServing.followWaitingLine }, logged: false) + } else if let start, let width = console.liveWidth { console.workingRows(ClusterOnboardingStartWords.liveRows(start, viewerLeads: false, viewerRank: operations.thisRank(), darkbloom: darkbloom, elapsed: Date().timeIntervalSince(stepSeen), width: width)) } else if let started, let latest { diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingSoloServing.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingSoloServing.swift index c38e28e95d..5efa598273 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingSoloServing.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingSoloServing.swift @@ -30,6 +30,30 @@ public struct ClusterOnboardingSoloServing: Sendable, Equatable, Codable { + ["Then run `darkbloom start` to start the pair. It won't start by itself while single-Mac serving runs."] } + /// How every block's title begins (`title`): a status line's reason that starts so is this block, whichever Mac says it. + public static let titlePrefix = "The pair can't start: a single-Mac Darkbloom provider" + + /// Whether a not-serving reason (`ClusterOnboardingNotServing.reason(inStatusLine:)`) is this block. + public static func isBlock(_ reason: String) -> Bool { reason.hasPrefix(titlePrefix) } + + /// On the Mac that joined: the leading Mac's screen offers the stop too (`stopAndStartItem`). + public static func leaderOffersLine(_ leader: String?) -> String { + "Or choose \"Stop single-Mac serving … and start the pair\" on \(ClusterOnboardingMacName.other(named: leader)): it stops it " + + "here and starts both Macs." + } + + /// While a block is shown on the Mac that joined: what this window does meanwhile. + public static let followWaitingLine = "Waiting until single-Mac serving stops; this window then follows the start (q leaves)" + + /// Said once single-Mac serving stopped on the Mac that joined (the block cleared): the start is followed again. + public static let followClearedLine = "Single-Mac serving stopped: following the start." + + /// `darkbloom cluster status`'s `next` for this block: what to run, since the pair never starts by itself meanwhile. + public static func next(cli: String, leadingMac: String) -> String { + "Single-Mac serving doesn't stop by itself: run `\(cli) stop --solo` on each Mac named, then `\(cli) start` on either " + + "Mac. Or `\(cli) cluster` on \(leadingMac) offers to stop it and start the pair." + } + /// The choice that stops single-Mac serving (on each Mac named) and starts the pair, with the person's consent. public static func stopAndStartItem(_ serving: [ClusterOnboardingSoloServing]) -> String { Set(serving.map(\.mac)).count > 1 ? "Stop single-Mac serving on both Macs and start the pair" diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift index 7fcf2d6d06..693d6a7be0 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift @@ -104,6 +104,10 @@ public final class ClusterService: @unchecked Sendable { var responder: ClusterSetupLinkExchange.Responder? var stopping = false private var syncing = false + /// On the leader: why the other Mac's part can't start now, as its status last said (`ClusterService.heldBack(of:)`); + /// this Mac's part waits for it instead of starting and ending again. Nil when it says none or didn't answer. + private var peerHeldBack: String? + private var peerHeldBackSaid: String? private var nextSync = Date.distantPast // Setting the cluster up again after a Darkbloom update (`checkForUpdate`). private var updateInFlight = false @@ -677,6 +681,8 @@ public final class ClusterService: @unchecked Sendable { return try? JSONDecoder().decode(ClusterServiceStatus.self, from: reply) } let member = send(.init(op: .status), seconds: 10) + // A Mac that doesn't answer holds nothing back: the control leadership handles its absence. + self?.lock.withLock { self?.peerHeldBack = member.flatMap(ClusterService.heldBack(of:)) } // The leader's cache choices first, so a member it starts runs with them. if let member, let cache = ClusterMemberCacheControl.settingsToSend( leader: ClusterCacheSettingsSync.leaderChoices(cacheSettings: (try? ClusterPrefixCacheSettings.savedCacheSettings( @@ -1009,6 +1015,12 @@ public final class ClusterService: @unchecked Sendable { ranks: max(live.members.count, configuration?.peers.count ?? 2), port: live.port, detail: live.detail ?? live.sessionPhase, readyRankList: live.members.filter(\.ready).map(\.rank)) } + // Single-Mac serving on this Mac, read now whether or not a part is wanted yet: the other Mac's start reads it before + // it starts anything (0.10.9 DevNet f1: it was reported only once this Mac wanted to start its part, so the leading + // Mac started first and its part kept ending). Never while this Mac's own part holds the lock. + let ownPartRuns = lock.withLock { child?.isRunning == true } || oldPart != nil + let soloNow = ownPartRuns ? nil + : ProviderInstanceHolder.current(lockFile: providerInstanceLock).flatMap { $0.kind == .singleMac ? $0 : nil } return lock.withLock { let reference = try? saved.reference.get() let wait = nextStart.timeIntervalSinceNow @@ -1018,7 +1030,7 @@ public final class ClusterService: @unchecked Sendable { child: .init(running: child?.isRunning == true || oldPart != nil, starts: starts, lastEnd: lastEnd, restartInSeconds: child == nil && oldPart == nil && wait > 0 ? Int(wait.rounded(.up)) : nil, // A running part says only a refusal its follower got (it keeps retrying, P2-1); an ended one its error. - lastError: child?.isRunning != true && soloServing != nil ? Self.soloServingError(soloServing!) + lastError: soloNow != nil ? Self.soloServingError(soloNow!) : child?.isRunning == true ? Self.runningPartRefusal(linkFollower: childIsLinkFollower, in: serviceFiles.rankLog, from: childLogOffset, remembered: &followerRefusalRead) @@ -1047,7 +1059,8 @@ public final class ClusterService: @unchecked Sendable { value.child.appAttest = Self.memberAppAttest(pid: child?.processIdentifier, state: state) value.child.appAttestRetryAt = Self.memberAppAttestRetryAt(pid: child?.processIdentifier, state: state) } - value.soloServing = soloServing.map { .init(pid: $0.pid) } + value.soloServing = soloNow.map { .init(pid: $0.pid) } + value.heldBack = soloNow.map(Self.soloServingError) value.pairRunning = value.serving && pairVerdict.running value.pairNotRunning = value.serving ? ClusterPairWatch.line(pairVerdict, otherMac: otherMacNameLocked(), cli: BuildEnvironment.current.cliName) : nil @@ -1577,6 +1590,14 @@ public final class ClusterService: @unchecked Sendable { return .success(()) } + /// Why the other Mac's part can't start now, from its status: its own held-back reason (`heldBack`, from 0.10.9), or the + /// single-Mac provider it reports. Nil when it reports none. + static func heldBack(of status: ClusterServiceStatus) -> String? { + status.heldBack ?? status.soloServing.map { solo in + "a single-Mac Darkbloom provider (" + (solo.pid.map { "process \($0)" } ?? "a process it doesn't name") + ") is serving there" + } + } + /// This Mac's part's error while single-Mac serving holds it back, in the words the other Mac's screen shows too. static func soloServingError(_ holder: ProviderInstanceHolder.Holder) -> String { ProviderInstanceHolder.clause(holder) + ", so this Mac's part can't start: `\(BuildEnvironment.current.cliName) stop --solo` stops it" @@ -1748,6 +1769,17 @@ public final class ClusterService: @unchecked Sendable { // in a loop on both Macs). Nothing starts until it stops; the status names it meanwhile. if running == nil, key != nil, holdsBackForSoloServing(say: say) { return } if key == nil { lock.withLock { soloServing = nil } } + // The other Mac said its part can't start for a reason that doesn't clear by itself: this Mac's part waits for that + // to change instead of starting, waiting for its missing follower and ending every 38 s (0.10.9 DevNet f1). + if running == nil, let key { + let reason = ClusterControlPartChoice.waitsForOtherMac(key: key, otherMacHeldBack: lock.withLock { peerHeldBack }) + let before = lock.withLock { () -> String? in defer { peerHeldBackSaid = reason }; return peerHeldBackSaid } + if let reason { + if before != reason { say("the other Mac's part can't start (\(reason)): this Mac's part waits for that to change") } + return + } + if before != nil { say("the other Mac's part can start again: starting this Mac's part") } + } // The restart backoff holds back only the part that ended: serving alone after the grace starts at once. guard running == nil, let key, lock.withLock({ !stopping && ClusterControlPartChoice.mayStart(key: key, endedKey: endedKey, backoffElapsed: Date() >= nextStart) }) diff --git a/provider-swift/Sources/darkbloom/ClusterPairSummary.swift b/provider-swift/Sources/darkbloom/ClusterPairSummary.swift index 4d16ae857a..6cd59ec596 100644 --- a/provider-swift/Sources/darkbloom/ClusterPairSummary.swift +++ b/provider-swift/Sources/darkbloom/ClusterPairSummary.swift @@ -400,14 +400,14 @@ extension ClusterPairSummary { static let pairingProgress: Set = ["the coordinator paired both Macs", "waiting for the coordinator to pair both Macs"] /// A reason that ends a start's wait: one that needs a person (a login, the clock, a coordinator rule, matching - /// builds, a pair not offered to Darkbloom, which only a new plan or approval changes). Others (Apple verification + /// builds, a pair not offered to Darkbloom, which only a new plan or approval changes, single-Mac serving on a Mac). Others (Apple verification /// retrying, memory freeing, a busy or reconnecting Mac, the coordinator retrying) are waited through, as the setup /// screen does, within the bounded wait. static func isFinalReason(_ reason: String?) -> Bool { guard let reason else { return true } return ClusterOnboardingNotServing.isMissingLogin(reason) || reason.contains("The clock of") || reason.contains("doesn't let") || reason.contains("run different Darkbloom builds") - || ClusterOnboardingReady.isNotOffered(reason) + || ClusterOnboardingReady.isNotOffered(reason) || ClusterOnboardingSoloServing.isBlock(reason) } /// The state the status lines of `darkbloom cluster` say, read as the other Mac's window reads them @@ -465,6 +465,10 @@ extension ClusterPairSummary { return "Quit apps on that Mac; the cluster starts again by itself. Or choose a smaller model: " + "`\(Self.cli) cluster` on \(leadingMac)." } + // Single-Mac serving never stops by itself: what to run, never "keep trying" (0.10.9 DevNet f1). + if ClusterOnboardingSoloServing.isBlock(reason) { + return ClusterOnboardingSoloServing.next(cli: Self.cli, leadingMac: leadingMac) + } if ClusterOnboardingReady.isNotOffered(reason) { return "To offer it to Darkbloom: `\(Self.cli) cluster` on \(leadingMac), then choose the model again (it is " + "planned for Darkbloom). Or serve locally only: `\(Self.cli) cluster local` on \(leadingMac)." diff --git a/provider-swift/Tests/ClusterControlChecks/ControlChecks.swift b/provider-swift/Tests/ClusterControlChecks/ControlChecks.swift index b36bbfd1a6..020cd41972 100644 --- a/provider-swift/Tests/ClusterControlChecks/ControlChecks.swift +++ b/provider-swift/Tests/ClusterControlChecks/ControlChecks.swift @@ -782,6 +782,12 @@ import Darwin expect(P.mayStart(key: "solo:m", endedKey: "cluster:abc", backoffElapsed: false), "another part: at once") expect(!P.mayStart(key: "cluster:abc", endedKey: "cluster:abc", backoffElapsed: false), "the part that ended: after its backoff") expect(P.mayStart(key: "cluster:abc", endedKey: "cluster:abc", backoffElapsed: true), "backoff elapsed") + // 0.10.9 DevNet f1: the leader's part ended every 38 s while the other Mac's single-Mac provider held its part back. + let held = "a single-Mac Darkbloom provider (process 68099) is serving there" + expect(P.waitsForOtherMac(key: "cluster:abc", otherMacHeldBack: held) == held, "held back there: this Mac's part waits") + expect(P.waitsForOtherMac(key: "cluster:abc:local-only@127.0.0.1", otherMacHeldBack: held) == held, "local only: waits too") + expect(P.waitsForOtherMac(key: "solo:m", otherMacHeldBack: held) == nil, "serving alone never waits for the other Mac") + expect(P.waitsForOtherMac(key: "cluster:abc", otherMacHeldBack: nil) == nil, "nothing held back: it starts") expect(!P.mayStart(key: "solo:m", endedKey: "solo:m", backoffElapsed: false), "a crashing solo server backs off too") expect(P.mayStart(key: "cluster:abc", endedKey: nil, backoffElapsed: false), "nothing ended: at once") } diff --git a/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift b/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift index 346888091a..664b069047 100644 --- a/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift +++ b/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift @@ -206,6 +206,10 @@ import Darwin soloServingIsLeftWithNothingStarted() soloServingFoundWhileWaitingIsNeverRetried() soloServingNamesTheDevNetCommand() + // 0.10.9 DevNet, pair-2 (f1): the leader showed the block, the joining Mac said "registering with the coordinator" + // for minutes while its own part waited for its single-Mac provider (process 68099). + soloServingOnTheJoiningMacIsSaidOnBothScreens() + theJoiningMacFollowsTheStartOnceSingleMacServingStops() print("onboarding checks: \(passed) passed, \(failures.count) failed") for failure in failures { print("FAIL " + failure) } exit(failures.isEmpty ? 0 : 1) @@ -2943,6 +2947,66 @@ import Darwin return made } + static let p2Max = ClusterOnboardingSoloServing(mac: "the other Mac (Apple M5 Max, 128 GB)", pid: 68099) + /// The leading Mac's status line while the joining Mac's single-Mac provider blocks the pair (its `localStatus`). + static let leaderBlockedStatus = [ClusterOnboardingNotServing.statusLine(model: "Qwen 3.8 27B", reason: ClusterOnboardingSoloServing.title([p2Max]))] + + ClusterOnboardingSoloServing.remedies([p2Max]) + static let joiningBlockTitle = "\u{2717} The pair can't start: a single-Mac Darkbloom provider (process 68099) is serving on this Mac, " + + "and the pair can't share a Mac with it." + + /// The joining Mac, its single-Mac provider seen by its own probe for `blockedLooks` looks (all of them when nil). + static func joiningSolo(_ recorder: Recorder, statusSequence: [[String]], blockedLooks: Int? = nil) -> TerminalRun { + var made = operations(recorder, pairEvents: memberEvents, pairResult: .paired(role: .member, peerName: leaderName), + pairServingResults: [.failure(.init("Waiting for the coordinator to pair both Macs."))], + statusSequence: statusSequence, followSeconds: 900) + let looks = Recorder() + made.soloServing = { + looks.note("look") + let seen = looks.all.count + return blockedLooks.map { seen > $0 } == true ? [] : [.init(mac: "this Mac", pid: 68099)] + } + return TerminalRun(made) + } + + static func soloServingOnTheJoiningMacIsSaidOnBothScreens() { + // The leading Mac: the block, named for the other Mac, with the stop offered. + let leading = TerminalRun(soloOperations(Recorder(), serving: [p2Max])) + expect(leading.waitFor(prompt(2)), "f1 leader: choice"); leading.type("\r") + expect(leading.waitFor(" 2) Leave\n"), "f1 leader: the offer: \(leading.text)"); leading.type("2") + expect(leading.finish() == 1, "f1 leader: exit 1") + expect(leading.text.contains("\u{2717} The pair can't start: a single-Mac Darkbloom provider (process 68099) is serving on the other " + + "Mac (Apple M5 Max, 128 GB), and the pair can't share a Mac with it.\n"), "f1 leader: the ✗: \(leading.text)") + // The joining Mac: the same ✗, naming its own provider, never a wait for the coordinator. + let recorder = Recorder() + let run = joiningSolo(recorder, statusSequence: [["Stopped."], ["Starting Qwen 3.8 27B."], leaderBlockedStatus]) + expect(run.waitFor(codeQuestion), "f1 joining: the code"); run.type("y") + expect(run.waitFor(ClusterOnboardingSoloServing.leaderOffersLine(leaderName)), "f1 joining: the block: \(run.text)") + usleep(400_000) + run.type("q") + expect(run.finish(seconds: 20) == 0, "f1 joining: q leaves") + let text = run.text + expect(text.contains(joiningBlockTitle + "\n"), "f1 joining: the ✗ names this Mac's provider: \(text)") + expect(text.contains("On this Mac: run `darkbloom stop --solo` to stop single-Mac serving there."), "f1 joining: the command") + expect(text.contains("Or choose \"Stop single-Mac serving … and start the pair\" on the other Mac (Apple M5 Ultra, 256 GB)"), + "f1 joining: the leader offers the stop") + expect(!text.contains("Offered to Darkbloom") && !text.contains("registering with the coordinator") + && !recorder.all.contains("pairServing"), "f1 joining: never a wait for the coordinator: \(recorder.all)") + expect(text.components(separatedBy: joiningBlockTitle).count == 2, "f1 joining: said once") + expect(ClusterOnboardingDriver.followed(leaderBlockedStatus) == .soloBlocked, "f1: the leader's block line is the block, not an offer") + transcript("member-solo-block", text, keys: run.keys) + } + + static func theJoiningMacFollowsTheStartOnceSingleMacServingStops() { + let recorder = Recorder() + let run = joiningSolo(recorder, statusSequence: [["Stopped."]] + Array(repeating: leaderBlockedStatus, count: 3) + + [["Loading Qwen 3.8 27B: 1 of 2 parts ready."], [localServingLine, leadersTestLine]], blockedLooks: 3) + expect(run.waitFor(codeQuestion), "f1 cleared: the code"); run.type("y") + expect(run.finish(seconds: 30) == 0, "f1 cleared: served once it stopped: \(run.text)") + let text = run.text + expect(text.contains(joiningBlockTitle) && text.contains(" " + ClusterOnboardingSoloServing.followClearedLine + "\n") + && text.contains("\u{2713} Serving Qwen 3.8 27B"), "f1 cleared: the block, then the start, then ✓: \(text)") + } + static func soloServingOnBothMacsIsSaidBeforeAnythingStarts() { let recorder = Recorder() let run = TerminalRun(soloOperations(recorder, serving: soloBoth)) diff --git a/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift b/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift index 6510cf537a..18e22657b4 100644 --- a/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift +++ b/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift @@ -259,6 +259,24 @@ struct ClusterStatusPlainTests { } } + /// 0.10.9 DevNet f1: `Next:` said "Both Macs keep trying by themselves" beside a block that said the pair won't start by + /// itself while single-Mac serving runs. + @Test("single-Mac serving blocking the pair: `next` says what to run, on both Macs, and a scripted start stops waiting") + func soloBlockNext() { + let cli = BuildEnvironment.current.cliName + for (role, leading) in [(ClusterPairSummary.Role.leader, "this Mac"), (.member, otherMac)] { + var blocked = pair(role: role) + blocked.state = .notServing + blocked.reason = "The pair can't start: a single-Mac Darkbloom provider (process 68099) is serving on this Mac, and the pair " + + "can't share a Mac with it" + let next = blocked.next ?? "" + #expect(!next.contains("keep trying by themselves"), "\(role): \(next)") + #expect(next == "Single-Mac serving doesn't stop by itself: run `\(cli) stop --solo` on each Mac named, then `\(cli) start` " + + "on either Mac. Or `\(cli) cluster` on \(leading) offers to stop it and start the pair.", "\(role): \(next)") + #expect(ClusterPairSummary.isFinalReason(blocked.reason), "\(role): a scripted `start` doesn't wait 10 minutes for it") + } + } + @Test("plain output: who leads, the model and its split, how it serves, the state in the screens' words, what to do") func plainLines() { var serving = pair() diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/SoloBlockPeerTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/SoloBlockPeerTests.swift new file mode 100644 index 0000000000..10248b0bbd --- /dev/null +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/SoloBlockPeerTests.swift @@ -0,0 +1,34 @@ +import Foundation +import Testing +@testable import ProviderCore + +/// 0.10.9 DevNet f1: the leader's part started and ended every 38 s while the other Mac's single-Mac provider held that +/// Mac's part back. The leader reads why from the other Mac's status and waits. +@Suite("The leader waits while the other Mac's part is held back") +struct SoloBlockPeerTests { + private func status(_ json: String) throws -> ClusterServiceStatus { + try JSONDecoder().decode(ClusterServiceStatus.self, from: Data(json.utf8)) + } + + @Test("the other Mac's single-Mac serving is a reason to wait; none, or an older build, is not") + func heldBackFromStatus() throws { + let base = #""serving":true,"sessionLeader":false,"child":{"running":false,"starts":0}"# + let older = try status("{\(base)}") + #expect(ClusterService.heldBack(of: older) == nil) + let solo = try status("{\(base),\"soloServing\":{\"pid\":68099}}") + #expect(ClusterService.heldBack(of: solo) == "a single-Mac Darkbloom provider (process 68099) is serving there") + let said = try status("{\(base),\"soloServing\":{\"pid\":68099},\"heldBack\":\"its own words\"}") + #expect(ClusterService.heldBack(of: said) == "its own words") + } + + @Test("the leader's part waits for it, and starts again once it clears; serving alone never waits") + func leaderPartWaits() throws { + let base = #""serving":true,"sessionLeader":false,"child":{"running":false,"starts":0}"# + let member = try status("{\(base),\"soloServing\":{\"pid\":68099}}") + let held = ClusterService.heldBack(of: member) + #expect(ClusterControlPartChoice.waitsForOtherMac(key: "cluster:84377e741989", otherMacHeldBack: held) != nil) + #expect(ClusterControlPartChoice.waitsForOtherMac(key: "cluster:84377e741989", + otherMacHeldBack: ClusterService.heldBack(of: try status("{\(base)}"))) == nil) + #expect(ClusterControlPartChoice.waitsForOtherMac(key: "solo:EigenLabs/Qwen3.8-27B-4bit-mtp", otherMacHeldBack: held) == nil) + } +} From ef536698dcad30975b70ee769f2691ab23e3ed56 Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:42:52 -0800 Subject: [PATCH 04/20] fix(provider): the usage history's warning goes to the running identity's log subsystem It named production's `dev.darkbloom.provider` in every build, so a DevNet app's `darkbloom-dev logs` never showed it. Co-Authored-By: Claude Opus 5.5 --- .../Sources/ProviderCore/Service/ProviderUsageHistory.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider-swift/Sources/ProviderCore/Service/ProviderUsageHistory.swift b/provider-swift/Sources/ProviderCore/Service/ProviderUsageHistory.swift index a252dcc9d3..d0f0b6eecd 100644 --- a/provider-swift/Sources/ProviderCore/Service/ProviderUsageHistory.swift +++ b/provider-swift/Sources/ProviderCore/Service/ProviderUsageHistory.swift @@ -51,7 +51,7 @@ public final class ProviderUsageHistory: @unchecked Sendable { public func enqueue(_ record: ProviderUsageRecord) { queue.async { [self] in do { try self.record(record) } - catch { ProviderLogger(subsystem: "dev.darkbloom.provider", category: "usage").warning("Local usage history could not be saved") } + catch { ProviderLogger(subsystem: BuildEnvironment.current.serviceLogSubsystem, category: "usage").warning("Local usage history could not be saved") } } } @discardableResult public func record(_ record: ProviderUsageRecord) throws -> Bool { From 0dca190f52dadf2c1b9a68c499136c1b7e3de166 Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:51:47 -0800 Subject: [PATCH 05/20] cluster: the joining Mac ends with the leading Mac's outcome, never its own verdict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 0.10.9 DevNet, pair-2 (f2, 00:23:20Z): 6 s after its part registered with the coordinator, the joining Mac's window ended with "✗ Not serving: This Mac isn't verified by Apple yet …" and "Choose Retry on the other Mac". The leading Mac kept waiting and showed "✓ Serving Qwen 3.8 27B through Darkbloom on both Macs" 41 s later. On an offered status the joining Mac had run its own pairServing wait and ended on its own App Attest state. - A state that clears by itself keeps the joining Mac waiting: Apple's verification, the coordinator's pairing, registering, the leader still deciding. The live row reads "Waiting for Apple to verify this Mac (Darkbloom retries by itself) · n of 15 min"; plain output says it once. Offered is its own stage with the whole bound, as the leader's wait. followPair is gone and the joining Mac never calls pairServing. - Its final ✓/✗ is the leader's. ✓ comes from the leader's status. The leader's screen ✗ is published as ClusterOnboardingStartProgress.failed (title, lines, retry) in ClusterControlReply.start, each Mac's name kept as a token, so the joining Mac shows the same ✗ named from its side. It counts for 30 minutes after the leader's screen ends; a new step published by a leader screen clears it. A later phase reads as unknown on an older Mac. - "Choose Retry on the other Mac" appears only under that ✗, when the leader's screen shows Retry: no longer mid-start, nor in the joining Mac's timeout. - An older leader publishes no outcome: the joining Mac waits until the stage's bound, then "✗ Not serving: The other Mac (…) didn't say how its start ended within 15 minutes.", the last state, and where to look. - The joining Mac's own blocking reasons (a different build) still end it at once; the single-Mac serving path is untouched (fix/solo-block-both-screens). Onboarding checks: 1540 passed, 0 failed. FollowFinalChecks failed 20 on the base with only the data interface present (the f2 run printed the field's exact ✗); seven older checks that encoded the old verdict were rewritten to these rules. Filtered swift test (ClusterOnboarding), sandboxed away from ~/.darkbloom*: prod 28 tests in 2 suites + 1, dev the same. docs-check and changelog-check OK. Co-Authored-By: Claude Opus 5.5 --- changelog.d/cluster-follow-final-outcome.md | 14 ++ docs/provider/two-mac-cluster.md | 26 +++- .../Onboarding/ClusterOnboardingFlow.swift | 17 ++- .../Onboarding/ClusterOnboardingFollow.swift | 89 ++++++++----- .../Onboarding/ClusterOnboardingLive.swift | 6 +- .../ClusterOnboardingStartProgress.swift | 62 ++++++++- .../FollowFinalChecks.swift | 126 ++++++++++++++++++ .../OnboardingChecks.swift | 45 ++++--- .../Tests/ClusterOnboardingChecks/run.sh | 3 +- ...sterOnboardingStartProgressWireTests.swift | 19 +++ 10 files changed, 339 insertions(+), 68 deletions(-) create mode 100644 changelog.d/cluster-follow-final-outcome.md create mode 100644 provider-swift/Tests/ClusterOnboardingChecks/FollowFinalChecks.swift diff --git a/changelog.d/cluster-follow-final-outcome.md b/changelog.d/cluster-follow-final-outcome.md new file mode 100644 index 0000000000..57a69f5c0e --- /dev/null +++ b/changelog.d/cluster-follow-final-outcome.md @@ -0,0 +1,14 @@ +### The joining Mac ends with the leading Mac's outcome + +- While the pair is offered to Darkbloom and waits for Apple's verification or for the coordinator, the joining Mac now + keeps waiting. It shows a live row such as "Waiting for Apple to verify this Mac (Darkbloom retries by itself) · 2 of + 15 min". Before, it judged the pair by its own wait: on a real pair it ended with "✗ Not serving: This Mac isn't + verified by Apple yet …" while the leading Mac showed "✓ Serving … through Darkbloom on both Macs" 41 s later. +- Its last word is the leading Mac's: the same ✓, or the same ✗ with its next step. When the leading Mac's start + ends with ✗ on its screen, it publishes that ✗ in its status, and the joining Mac shows it named from its own side + ("This Mac isn't logged in to Darkbloom …"). +- "Choose Retry on the other Mac" appears only under that ✗, since the leading Mac's screen then shows Retry. It is no + longer said while a part restarts by itself. +- With a leading Mac on an earlier release, which publishes no outcome, the joining Mac waits until the stage's + 15 minutes run out. It then ends with "✗ Not serving: The other Mac (…) didn't say how its start ended within + 15 minutes.", the last state it saw, and where to look. diff --git a/docs/provider/two-mac-cluster.md b/docs/provider/two-mac-cluster.md index 38226391fc..3675c30ad1 100644 --- a/docs/provider/two-mac-cluster.md +++ b/docs/provider/two-mac-cluster.md @@ -1,6 +1,6 @@ # Two Macs as one provider (guided setup) -> Last updated: 2026-11-04 +> Last updated: 2026-11-05 Two Apple Silicon Macs joined by one Thunderbolt 5 cable serve a model together: each Mac holds part of its layers, and the pair serves as one provider. Setting @@ -156,16 +156,28 @@ follows the start from the cluster's status the two Macs exchange over the cable leading Mac failed." under the not-serving line. Switching between local only and serving through Darkbloom, the next start or serve, and a stop clear it. -3. It ends with the same ✓ or ✗ block as the leader's screen. After ✓: "You can - close this window." After ✗: the reason, then "Choose Retry on the other Mac - (…): its screen shows the choices."; after a failed test, "To test again, run - `darkbloom cluster` on the other Mac (…) and choose the model it serves." +3. Offered to Darkbloom and not serving yet, it waits for the leading Mac's + outcome and never judges the pair by a wait of its own. A reason that clears + by itself keeps it waiting, with a live row and the time of the bound, e.g. + "Waiting for Apple to verify this Mac (Darkbloom retries by itself) · 2 of + 15 min" or "Waiting for Darkbloom to pair both Macs". +4. It ends with the leading Mac's outcome. After ✓, the same ✓ block, then "You + can close this window." After the leading Mac's ✗ (`ClusterControlReply.start` + with phase `failed`, named from this Mac's side), the same ✗ and next step, + then "Choose Retry on the other Mac (…): its screen shows the choices." That + line appears only in that ✗, since the leading Mac's screen shows Retry then. + After a failed test: "To test again, run `darkbloom cluster` on the other Mac + (…) and choose the model it serves." It ends early only for a reason of its + own, such as a different Darkbloom build. q leaves at any time: "The pair keeps going; run `darkbloom cluster` here to see it." The follow is bounded like the leader's start: 15 minutes for the start to begin, then 15 minutes for each of its stages (loading; the test and the check -with Darkbloom; the registration's restart), then the pair's own wait once it is -offered. Its end always says why. A signed +with Darkbloom; the registration's restart; the wait once it is offered). A +leading Mac that says no outcome within a stage's bound (an earlier release +publishes none) ends it with "✗ Not serving: The other Mac (…) didn't say how +its start ended within 15 minutes.", the last state, and "Its screen shows how +the start ended and what to do next." Its end always says why. A signed Darkbloom.app's login agent keeps serving; without one, as for a development build, the screen ends "Keep this window open." and the Mac serves only while the window stays open. The Start step opens with "Loading diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFlow.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFlow.swift index 2d9a584d7b..69e17863f7 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFlow.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFlow.swift @@ -2636,6 +2636,9 @@ public enum ClusterOnboardingDriver { } continue case .notServing(let lines): + // The start's outcome, published so the Mac that joined ends with the same ✗ and points to Retry here. + let block = notServingBlock(lines) + operations.publishStart(.failed(title: block.title, lines: block.lines, retry: true)) switch notServing(lines, operations, console) { case .retry: // A pair stopped meanwhile (`cluster stop --service` on a Mac): Retry starts it again and says so, instead @@ -2761,15 +2764,21 @@ public enum ClusterOnboardingDriver { /// Why the pair does not serve in one plain line (details under it), what to do, then the choices. Diagnostics /// saves the file and asks again; q leaves. - static func notServing(_ lines: [String], _ operations: ClusterOnboardingOperations, - _ console: ClusterOnboardingConsole) -> NotServingChoice { + /// The ✗ block for a start that does not serve: why, in one plain line, then the details and what to do. + static func notServingBlock(_ lines: [String]) -> (title: String, lines: [String]) { let said = lines.first ?? "the cluster did not report ready" // A line that is already the title ("Not serving: …", a test's failure from the leading Mac) is said once. let prefix = String(ClusterOnboardingNotServing.title(reason: "").dropLast()) let first = said.hasPrefix(prefix) ? String(said.dropFirst(prefix.count)) : said let reason = first.hasSuffix(".") ? String(first.dropLast()) : first - console.result(false, ClusterOnboardingNotServing.title(reason: reason), - Array(lines.dropFirst()) + (ClusterOnboardingNotServing.remedy(forReason: reason).map { [$0] } ?? [])) + return (ClusterOnboardingNotServing.title(reason: reason), + Array(lines.dropFirst()) + (ClusterOnboardingNotServing.remedy(forReason: reason).map { [$0] } ?? [])) + } + + static func notServing(_ lines: [String], _ operations: ClusterOnboardingOperations, + _ console: ClusterOnboardingConsole) -> NotServingChoice { + let block = notServingBlock(lines) + console.result(false, block.title, block.lines) while true { switch console.choose(notServingItems, selected: 0) { case 0: return .retry diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift index 7eee3459fa..20b5a7cdde 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift @@ -138,10 +138,12 @@ extension ClusterOnboardingDriver { } /// The stage of the leader's start that `status` shows, after `stage`: 1 loading or starting, 2 its test and check - /// with Darkbloom, 3 anything after that check (the registration's stop and restart). Never back, so a status that + /// with Darkbloom, 3 anything after that check (the registration's stop and restart), 4 offered and waiting to serve. Never back, so a status that /// goes back and forth inside one stage never starts its bound again. static func followStage(_ status: [String], after stage: Int) -> Int { guard let first = status.first else { return stage } + // Offered and not serving yet: the pair's own wait, with the whole bound as on the leading Mac (`pairServing`). + if followed(status) == .offered { return max(stage, 4) } if first.contains(ClusterOnboardingReady.offerPendingWords) { return max(stage, 2) } if stage >= 2 { return 3 } return followed(status) == .starting ? max(stage, 1) : stage @@ -162,7 +164,10 @@ extension ClusterOnboardingDriver { var begun = Date() var started: Date?, latest: String?, stage = 0, step: ClusterOnboardingLeaderStep?, lastStatus: String? // Each line once: a status that goes back and forth between two lines never repeats them. - var said = Set(), saidRetry = false, saidBlocked = false + var said = Set(), saidBlocked = false + // Offered to Darkbloom and not serving yet: why, as the leading Mac's status says it. Every such reason may clear + // by itself (Apple's verification, the coordinator's pairing), so this Mac waits for the leading Mac's outcome. + var offeredWait: String?, saidOffered = false // The start's progress as the leading Mac publishes it (`ClusterOnboardingStartProgress`): its own heading, then // its step, a bar of the real bytes and each Mac's part as the live rows; each step done said once. Its time // counts from when this Mac first saw the step (the two Macs' clocks may differ). @@ -200,6 +205,11 @@ extension ClusterOnboardingDriver { } } if let first = status.first { lastStatus = first.hasSuffix(".") ? String(first.dropLast()) : first } + // The leading Mac's start ended with ✗ on its screen: the same ✗, in its words, and where its choices are. + if let ended = look.start, ended.phase == .failed { + console.settle() + return followFailed(ended.viewed(leader: leader), leader: leader, console) + } // The leading Mac refused every model and its window ended: nothing will start, so the same ✗ now. if let refused = step, refused.kind == .refused { console.settle() @@ -227,15 +237,20 @@ extension ClusterOnboardingDriver { // The start's own rows say it where the leading Mac publishes them. if let latest, seen == .starting, start == nil || console.liveWidth == nil { sayOnce(" The other Mac: " + latest + ".") - if !saidRetry, latest.contains("part ended") { saidRetry = true; console.say(retryOnLeaderLine(leader)) } } switch seen { case .serving: console.settle() return followServed(status, leader: leader, operations, console) case .offered: - console.settle() - return followPair(status, leader: leader, operations, console) + if !saidOffered, let first = status.first { + saidOffered = true + let model = first.components(separatedBy: ClusterOnboardingNotServing.statusMarker).first ?? "the model" + console.settle() + console.say(" " + ClusterOnboardingReady.offeredLine(model: model)) + } + offeredWait = status.first.flatMap(ClusterOnboardingNotServing.reason(inStatusLine:)).map(offeredWaitingWords) + if let offeredWait, console.liveWidth == nil { sayOnce(" " + offeredWait + ".") } case .testFailed: console.settle() return followTestFailed(status, leader: leader, console) @@ -246,14 +261,13 @@ extension ClusterOnboardingDriver { console.say(retryOnLeaderLine(leader)) return 1 case .starting, .notStarted: - break + offeredWait = nil } } if let started, Date().timeIntervalSince(started) >= timing.seconds { console.settle() - console.result(false, ClusterOnboardingNotServing.title(reason: "The pair didn't report serving within \(minutes(timing.seconds)) minutes"), - latest.map { ["Last: " + $0 + "."] } ?? []) - console.say(retryOnLeaderLine(leader)) + console.result(false, ClusterOnboardingNotServing.title(reason: noOutcomeReason(leader, seconds: timing.seconds)), + (latest.map { ["Last: " + $0 + "."] } ?? []) + [noOutcomeLine]) return 1 } if started == nil, Date().timeIntervalSince(begun) >= timing.seconds { @@ -263,7 +277,12 @@ extension ClusterOnboardingDriver { console.say(notStartedAfterLine) return 1 } - if let start, let width = console.liveWidth { + if let offeredWait, let started { + let waited = Date().timeIntervalSince(started) + console.progress({ width in fitted([offeredWait + " \u{00B7} " + waitedWords(waited, of: timing.seconds) + " (q leaves)", + offeredWait + " \u{00B7} " + waitedWords(waited, of: timing.seconds)], width: width) }, + logged: false) + } else if let start, let width = console.liveWidth { console.workingRows(ClusterOnboardingStartWords.liveRows(start, viewerLeads: false, viewerRank: operations.thisRank(), darkbloom: darkbloom, elapsed: Date().timeIntervalSince(stepSeen), width: width)) } else if let started, let latest { @@ -336,35 +355,35 @@ extension ClusterOnboardingDriver { return 1 } - /// Offered to Darkbloom: the pair's own wait, as the leading Mac's (`pairServing`: the coordinator pairs both Macs, - /// both load their share, the pair answers its first request), with its rows per Mac; q leaves it. - static func followPair(_ status: [String], leader: String?, _ operations: ClusterOnboardingOperations, - _ console: ClusterOnboardingConsole) -> Int32 { - let model = status.first?.components(separatedBy: ClusterOnboardingNotServing.statusMarker).first ?? "the model" - console.say(" " + ClusterOnboardingReady.offeredLine(model: model)) - guard let result = waitWithRows("Serving \(model) through Darkbloom", console, leaving: leaves, operations.pairServing) else { - return leftFollow(operations, console) + /// The leading Mac's start ended with ✗ (`ClusterOnboardingStartProgress.failed`, named from this Mac): its title and + /// lines, then where its choices are when its screen offers Retry. + static func followFailed(_ ended: ClusterOnboardingStartProgress, leader: String?, _ console: ClusterOnboardingConsole) -> Int32 { + console.result(false, ended.title ?? ClusterOnboardingNotServing.title(reason: "the start ended"), ended.lines ?? []) + if ended.retry == true { console.say(retryOnLeaderLine(leader)) } + return 1 + } + + /// What this Mac waits for while the pair is offered to Darkbloom and not serving yet: a reason the leading Mac's + /// status gives, which clears by itself or ends in the leading Mac's ✗. + static func offeredWaitingWords(_ reason: String) -> String { + if let mac = reason.components(separatedBy: " isn't verified by Apple yet").first, mac != reason { + return "Waiting for Apple to verify \(mac.prefix(1).lowercased() + mac.dropFirst()) (Darkbloom retries by itself)" } - switch result { - case .success(let lines): - let tested = "Test response" + (lines.first.flatMap { $0.isEmpty ? nil : " " + $0 } ?? "") - let now = operations.status() - if case .serving = followed(now), let first = now.first { - _ = showOutcome([first] + now.dropFirst() + [ClusterOnboardingReady.offeredAPILine, tested], console) - } else { - console.result(true, "Serving \(model)" + pairServedMarker, [ClusterOnboardingReady.offeredAPILine, tested]) - } - return followServedEnd(operations, console) - case .failure(let failure): - let first = failure.lines.first ?? "The pair did not report serving" - let reason = first.hasSuffix(".") ? String(first.dropLast()) : first - console.result(false, ClusterOnboardingNotServing.title(reason: reason), - Array(failure.lines.dropFirst()) + (ClusterOnboardingNotServing.remedy(forReason: reason).map { [$0] } ?? [])) - console.say(retryOnLeaderLine(leader)) - return 1 + if reason.lowercased().contains("coordinator") || reason.lowercased().contains("registering") { + return "Waiting for Darkbloom to pair both Macs" } + return "Waiting for the other Mac's start: " + reason } + /// The ✗ when the leading Mac said no outcome within the bound (an older leader publishes none): what is known. + static func noOutcomeReason(_ leader: String?, seconds: Double) -> String { + "\(ClusterOnboardingMacName.sentence(ClusterOnboardingMacName.other(named: leader))) didn't say how its start ended within " + + "\(minutes(seconds)) minutes" + } + + /// Under that ✗: where the outcome is. + public static let noOutcomeLine = "Its screen shows how the start ended and what to do next." + /// After ✓: what happens after a restart, and whether this window may close. static func followServedEnd(_ operations: ClusterOnboardingOperations, _ console: ClusterOnboardingConsole) -> Int32 { if let restart = operations.afterRestart() { console.say(restart) } diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift index a0dade7954..222724e307 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift @@ -2313,7 +2313,11 @@ final class OnboardingLive: @unchecked Sendable { step.version = step.version ?? ProviderCore.version return .init(step: step, pid: pid, started: started, at: Date().timeIntervalSince1970) } - try? store.updateRecord { $0.onboardingStep = mark } + try? store.updateRecord { record in + record.onboardingStep = mark + // A screen that moved on (a new start, another model) ends an earlier start's ✗ as the outcome to follow. + if step != nil, record.startProgress?.progress.phase == .failed { record.startProgress = nil } + } } /// The setup step the status publishes, while it counts. diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingStartProgress.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingStartProgress.swift index 48933d42e2..a272cf6b98 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingStartProgress.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingStartProgress.swift @@ -22,6 +22,9 @@ public struct ClusterOnboardingStartProgress: Codable, Sendable, Equatable { case testing /// The pair registers with Darkbloom's coordinator. case registering + /// The start ended with ✗ on the leading Mac's screen (`title`, `lines`; `retry`: its screen offers Retry). The + /// Mac that joined ends with the same ✗; it never judges the pair by a wait of its own. + case failed /// A phase a later build adds. case unknown @@ -62,12 +65,61 @@ public struct ClusterOnboardingStartProgress: Codable, Sendable, Equatable { public var parts: [Part]? /// When this phase began (seconds since 1970), so both screens count from the same moment. public var since: Double? + /// `failed`: the leading Mac's ✗ title and the lines under it, each Mac named by its part (`failed(title:lines:retry:)`), + /// and whether its screen offers Retry. + public var title: String? + public var lines: [String]? + public var retry: Bool? public init(_ phase: Phase, done: Int64? = nil, total: Int64? = nil, toLeader: Bool? = nil, parts: [Part]? = nil, since: Double? = nil) { self.phase = phase; self.done = done; self.total = total; self.toLeader = toLeader; self.parts = parts; self.since = since } + /// The leading Mac's final ✗, from its screen's words: "this Mac" (the leading Mac) and "the other Mac (…)" (the Mac + /// that joined) are kept as who they are, so the Mac that joined names each from its side (`viewed(leader:)`). + public static func failed(title: String, lines: [String], retry: Bool) -> ClusterOnboardingStartProgress { + var made = ClusterOnboardingStartProgress(.failed) + made.title = Self.byPart(title) + made.lines = lines.map(Self.byPart) + made.retry = retry + return made + } + + /// The same, as the Mac that joined says it: the leading Mac named `leader` ("the other Mac (Apple M3 Ultra, …)"), + /// itself "this Mac". + public func viewed(leader: String?) -> ClusterOnboardingStartProgress { + var shown = self + func view(_ text: String) -> String { + let other = ClusterOnboardingMacName.other(named: leader) + return text.replacingOccurrences(of: Self.joinedToken.upper, with: ClusterOnboardingMacName.sentence(ClusterOnboardingMacName.this)) + .replacingOccurrences(of: Self.joinedToken.lower, with: ClusterOnboardingMacName.this) + .replacingOccurrences(of: Self.leaderToken.upper, with: ClusterOnboardingMacName.sentence(other)) + .replacingOccurrences(of: Self.leaderToken.lower, with: other) + } + shown.title = title.map(view) + shown.lines = lines?.map(view) + return shown + } + + static let joinedToken = (upper: "\u{1}J", lower: "\u{1}j") + static let leaderToken = (upper: "\u{1}L", lower: "\u{1}l") + + /// The leading Mac's words with each Mac as a token: "the other Mac" with or without its name is the Mac that + /// joined, "this Mac" with or without its name the leading Mac. + static func byPart(_ text: String) -> String { + var text = text + for (pattern, upper, lower) in [(#"([Tt])he other Mac( \([^)]*\))?"#, joinedToken.upper, joinedToken.lower), + (#"([Tt])his Mac( \([^)]*\))?"#, leaderToken.upper, leaderToken.lower)] { + guard let expression = try? NSRegularExpression(pattern: pattern) else { continue } + for match in expression.matches(in: text, range: NSRange(text.startIndex..., in: text)).reversed() { + guard let range = Range(match.range, in: text), let first = Range(match.range(at: 1), in: text) else { continue } + text.replaceSubrange(range, with: text[first] == "T" ? upper : lower) + } + } + return text + } + /// The parts ready, of all of them. public var readyParts: (ready: Int, of: Int)? { guard let parts, !parts.isEmpty else { return nil } @@ -98,8 +150,12 @@ public struct ClusterOnboardingStartProgressMark: Codable, Sendable, Equatable { /// Figures older than this are not shown: whoever published them stopped. public static let freshSeconds: Double = 30 + /// How long the leading Mac's ✗ counts as the start's outcome. + public static let outcomeSeconds: Double = 1_800 public func current(now: Double, started processStarted: (Int32) -> UInt64?) -> ClusterOnboardingStartProgress? { + // The leading Mac's ✗ outlives its screen for a while (the person may leave it): it is the start's outcome. + if progress.phase == .failed { return now - at < Self.outcomeSeconds ? progress : nil } guard processStarted(pid) == started else { return nil } switch progress.phase { case .downloading, .copying, .loading: return now - at < Self.freshSeconds ? progress : nil @@ -130,7 +186,7 @@ public enum ClusterOnboardingStartStep: String, Sendable, CaseIterable { case .loading: self = .load case .testing: self = .test case .registering: self = .darkbloom - case .unknown: return nil + case .failed, .unknown: return nil } } @@ -227,6 +283,8 @@ public enum ClusterOnboardingStartWords { return viewerLeads ? ["Test: sending a test request", "Test"] : ["Test: \(other) sends a test request", "Test"] case .registering: return ["Darkbloom: registering both Macs with the coordinator", "Darkbloom: registering", "Darkbloom"] + case .failed: + return [progress.title ?? "Not serving"] case .unknown: return ["Starting"] } @@ -271,7 +329,7 @@ public struct ClusterOnboardingStartLog: Sendable { /// The lines to say for `progress` at `now` (seconds since 1970). `plain`: the window has no live rows, so the /// part changes and a copy's bytes are said too. public mutating func update(_ progress: ClusterOnboardingStartProgress?, now: Double, plain: Bool) -> [String] { - guard let progress, progress.phase != .unknown else { return [] } + guard let progress, progress.phase != .unknown, progress.phase != .failed else { return [] } var lines = [String]() if progress.phase != phase { if let phase, let step = ClusterOnboardingStartStep(phase), ClusterOnboardingStartStep(progress.phase) != step { diff --git a/provider-swift/Tests/ClusterOnboardingChecks/FollowFinalChecks.swift b/provider-swift/Tests/ClusterOnboardingChecks/FollowFinalChecks.swift new file mode 100644 index 0000000000..72fa457c29 --- /dev/null +++ b/provider-swift/Tests/ClusterOnboardingChecks/FollowFinalChecks.swift @@ -0,0 +1,126 @@ +import Foundation +import Darwin + +/// 0.10.9 DevNet, pair-2 (f2, 2026-11-05 00:23Z): 6 s after its part registered with the coordinator, the joining Mac's +/// window ended with "✗ Not serving: This Mac isn't verified by Apple yet …" and "Choose Retry on the other Mac", while +/// the leading Mac kept waiting and showed "✓ Serving Qwen 3.8 27B through Darkbloom on both Macs" 41 s later. The +/// joining Mac had judged the pair by its own wait. Now a state that clears by itself keeps it waiting, and its final ✓ +/// or ✗ is the leading Mac's, in the same words; an older leader that publishes no outcome ends in an honest ✗. +extension OnboardingChecks { + static func followFinalOutcomeChecks() { + theJoiningMacWaitsForAppleAndEndsWithTheLeadersTick() + anOlderLeaderEndsInAnHonestCross() + theLeadersFinalCrossIsTheJoiningMacsCross() + theLeaderPublishesItsFinalCrossForTheJoiningMac() + } + + static let ultraName = "Apple M3 Ultra, 256 GB" + static let appleReason = ClusterOnboardingNotServing.notVerified(ClusterOnboardingMacName.this) + static let appleWaitStatus = [ClusterOnboardingNotServing.statusLine(model: "Qwen 3.8 27B", reason: appleReason), + ClusterOnboardingNotServing.remedy(forReason: appleReason) ?? ""] + static let pairServedStatus = ["Serving Qwen 3.8 27B through Darkbloom on both Macs (tensor parallel).", + "No local API: requests reach the pair through Darkbloom"] + static let appleWaitRow = "Waiting for Apple to verify this Mac (Darkbloom retries by itself)" + + /// The joining Mac of an M3 Ultra leader whose status goes through `status` in turn (one per look, the last repeats), + /// with what it publishes of its start (`start`, by look; nil: an older leader). The joining Mac's own wait for the + /// pair (`pairServing`) says what f2's said: it must never decide. + static func followingTheUltra(_ recorder: Recorder, status: [[String]], start: [ClusterOnboardingStartProgress?] = [], + followSeconds: Double = 900) -> ClusterOnboardingOperations { + var made = operations(recorder, pairEvents: memberEvents, pairResult: .paired(role: .member, peerName: ultraName), + pairServingResults: [.failure(.init([appleReason + ".", "Then choose Retry, or serve locally only now."]))], + followSeconds: followSeconds) + let looks = Recorder() + made.leaderStatus = { + looks.note("look") + let seen = looks.all.count + return .init(lines: status[min(seen, status.count) - 1], step: .init(.starting), + start: start.isEmpty ? nil : start[min(seen, start.count) - 1]) + } + return made + } + + static func theJoiningMacWaitsForAppleAndEndsWithTheLeadersTick() { + let status = [["Stopped."], ["Starting Qwen 3.8 27B."]] + Array(repeating: appleWaitStatus, count: 30) + [pairServedStatus] + for (label, environment) in [("80 columns", colourTerminal), ("plain", ["NO_COLOR": "1"])] { + let recorder = Recorder() + let run = TerminalRun(followingTheUltra(recorder, status: status), environment: environment, columns: 80) + defer { run.release() } + expect(run.waitFor(codeQuestion), "f2 \(label): the code"); run.type("y") + expect(run.finish(seconds: 30) == 0, "f2 \(label): ends with the leader's ✓, exit 0: \(run.text)") + let text = run.text + expect(text.contains("\u{2713} Serving Qwen 3.8 27B through Darkbloom on both Macs (tensor parallel)"), "f2 \(label): the ✓: \(text)") + expect(!text.contains("\u{2717}") && !text.contains("Choose Retry"), "f2 \(label): no ✗ and no Retry for a pair that serves: \(text)") + expect(text.contains(appleWaitRow), "f2 \(label): it says it waits for Apple: \(text)") + expect(!recorder.all.contains("pairServing"), "f2 \(label): its own wait never decides: \(recorder.all)") + if label == "plain" { + expect(text.components(separatedBy: appleWaitRow).count == 2, "f2 plain: the wait said once") + } else { + expect(text.contains(appleWaitRow + " \u{00B7} "), "f2 80 columns: the live row with its time") + let rows = liveRows(text) + expect(rows.allSatisfy { $0.count <= 79 }, "f2 80 columns: every live row fits: \(rows.filter { $0.count > 79 })") + } + transcript("joining-apple-wait-\(label.replacingOccurrences(of: " ", with: "-"))", text, keys: run.keys) + } + } + + static func anOlderLeaderEndsInAnHonestCross() { + let recorder = Recorder() + let run = TerminalRun(followingTheUltra(recorder, status: [["Stopped."], ["Starting Qwen 3.8 27B."], appleWaitStatus], followSeconds: 2)) + defer { run.release() } + expect(run.waitFor(codeQuestion), "older leader: the code"); run.type("y") + expect(run.finish(seconds: 30) == 1, "older leader: exit 1: \(run.text)") + let text = run.text + expect(text.contains("\u{2717} Not serving: The other Mac (Apple M3 Ultra, 256 GB) didn't say how its start ended within"), + "older leader: the honest ✗: \(text)") + expect(text.contains("Its screen shows how the start ended and what to do next."), "older leader: where to look") + expect(!text.contains("isn't verified by Apple yet; Darkbloom retries") || !text.contains("\u{2717} Not serving: This Mac isn't verified"), + "older leader: never the transient reason as its ✗") + expect(!text.contains("Choose Retry"), "older leader: no Retry it can't see: \(text)") + expect(!recorder.all.contains("pairServing"), "older leader: its own wait never decides") + } + + static func theLeadersFinalCrossIsTheJoiningMacsCross() { + typealias P = ClusterOnboardingStartProgress + let missing = ClusterOnboardingNotServing.notLoggedIn([ClusterOnboardingMacName.other(named: "Apple M5 Max, 128 GB")]) + let published = P.failed(title: ClusterOnboardingNotServing.title(reason: missing), + lines: [ClusterOnboardingNotServing.remedy(forReason: missing) ?? ""], retry: true) + let waiting = [ClusterOnboardingNotServing.statusLine(model: "Qwen 3.8 27B", reason: "Waiting for the coordinator to pair both Macs")] + let recorder = Recorder() + let run = TerminalRun(followingTheUltra(recorder, status: [["Stopped."], ["Starting Qwen 3.8 27B."]] + Array(repeating: waiting, count: 12), + start: Array(repeating: nil, count: 14) + [published])) + defer { run.release() } + expect(run.waitFor(codeQuestion), "leader's ✗: the code"); run.type("y") + expect(run.finish(seconds: 30) == 1, "leader's ✗: exit 1: \(run.text)") + let text = run.text + expect(text.contains("\u{2717} Not serving: This Mac isn't logged in to Darkbloom, so the coordinator won't pair it.\n"), + "leader's ✗: its words, named from this Mac: \(text)") + expect(text.contains("Run `darkbloom login` on each Mac named, then Retry; or serve locally only."), "leader's ✗: its next step") + expect(text.contains(retryOnLeader), "leader's ✗: where Retry is: \(text)") + expect(text.components(separatedBy: "\u{2717}").count == 2, "leader's ✗: one ✗ only") + } + + static let retryOnLeader = "Choose Retry on the other Mac (Apple M3 Ultra, 256 GB): its screen shows the choices." + + static func theLeaderPublishesItsFinalCrossForTheJoiningMac() { + let published = Recorder() + let missing = ClusterOnboardingNotServing.notLoggedIn([ClusterOnboardingMacName.other(named: "Apple M3 Ultra, 256 GB")]) + var made = operations(Recorder(), resume: .init(role: .leader, peerName: "Apple M3 Ultra, 256 GB"), pairEvents: [], + pairResult: .failed([]), readyResult: .success(.init(servedBy: "this Mac", port: 8000, offered: "offered for pairing")), + pairServingResults: [.failure(.init(missing))]) + let shown = ClusterOnboardingMailbox() + made.publishStart = { shown.post($0); published.note($0?.phase.rawValue ?? "nil") } + let run = TerminalRun(made) + defer { run.release() } + expect(run.waitFor(prompt(2)), "leader publishes: the list"); run.type("\r") + expect(run.waitFor("Not serving: The other Mac (Apple M3 Ultra, 256 GB) isn't logged in"), "leader publishes: its ✗: \(run.text)") + _ = run.waitFor(prompt(4), seconds: 3) + run.type("q") + _ = run.finish() + let failed = shown.take().compactMap { $0 }.last { $0.phase == .failed } + expect(failed?.retry == true, "leader publishes: a final ✗ with Retry: \(published.all)") + let member = failed?.viewed(leader: "Apple M3 Ultra, 256 GB") + expect(member?.title == "Not serving: This Mac isn't logged in to Darkbloom, so the coordinator won't pair it.", + "leader publishes: the joining Mac reads it named from its side: \(String(describing: member))") + } +} diff --git a/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift b/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift index 346888091a..bb4619d0e0 100644 --- a/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift +++ b/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift @@ -197,6 +197,8 @@ import Darwin eachStageOfTheStartHasItsOwnBound() // A user's report (2026-11-04): "an infinite loop of waiting for the other Mac, Apple M5 Max 128 GB". followWaitChecks() + // 0.10.9 DevNet, pair-2 (f2): the joining Mac's last word is the leading Mac's outcome. + followFinalOutcomeChecks() // A 0.10.8 user's leader screen: its loading line repeated end to end in a narrow window. liveLineChecks() // 0.10.8, 2026-11-04: single-Mac serving held the provider instance lock on both Macs of a pair; the start looped @@ -4236,15 +4238,17 @@ import Darwin let late = [["Stopped."], ["Loading Qwen 3.8 27B: 1 of 2 parts ready."]] + Array(repeating: [offerPendingLine], count: 30) + [["Qwen 3.8 27B: registering both Macs with the coordinator for pairing."], [ClusterOnboardingNotServing.statusLine(model: "Qwen 3.8 27B", reason: notVerifiedTimed)]] - let run = joining(recorder, statusSequence: late, pairServingResults: [.failure(.init(notVerifiedTimed))]) + // f2 (0.10.9 DevNet, pair-2): Apple's verification clears by itself, so the joining Mac never judges by it; an older + // leader that publishes no outcome ends at the bound with what is known, never Retry it can't see. + let run = joining(recorder, statusSequence: late, pairServingResults: [.failure(.init(notVerifiedTimed))], followSeconds: 10) expect(run.waitFor(codeQuestion), "late offer: the code"); run.type("y") expect(run.finish(seconds: 30) == 1, "late offer: not serving is not success") let text = run.text expect(!text.contains("\u{2713} Serving") && !recorder.all.contains("testRequest"), "late offer: never an early ✓, nothing tested: \(text)") expect(text.contains(" " + ClusterOnboardingReady.offeredLine(model: "Qwen 3.8 27B") + "\n") - && text.contains(block("\u{2717}", "Not serving: " + notVerifiedTimed + ".", [ClusterOnboardingNotServing.remedy(forReason: notVerifiedTimed) ?? "-"])), - "late offer: offered, then the leader's ✗: \(text)") - expect(text.hasSuffix(ClusterOnboardingDriver.retryOnLeaderLine(leaderName) + "\n"), "late offer: where to act: \(text)") + && text.contains("\u{2717} Not serving: " + ClusterOnboardingDriver.noOutcomeReason(leaderName, seconds: 10) + ".\n"), + "late offer: offered, then the honest ✗: \(text)") + expect(!text.contains("Choose Retry") && !recorder.all.contains("pairServing"), "late offer: no Retry, no verdict of its own: \(text)") transcript("member-late-offer", text, keys: run.keys) } @@ -4286,10 +4290,10 @@ import Darwin expect(pair.waitFor(codeQuestion), "follow offered: the code"); pair.type("y") expect(pair.finish() == 0, "follow offered: exit 0") expect(pair.text.contains(" " + ClusterOnboardingReady.offeredLine(model: "Qwen 3.8 27B") + "\n"), "follow offered: said in plain words: \(pair.text)") - expect(pair.text.hasSuffix(block("\u{2713}", String(served.dropLast()), [ClusterOnboardingReady.offeredAPILine, "Test response in 0.84 s"]) - + ClusterOnboardingDriver.closeWindowLine + "\n"), "follow offered: the leader's ✓ block: \(pair.text)") - expect(pair.text.components(separatedBy: "\u{2713} Serving").count == 2 && !offered.all.contains("testRequest") && offered.all.contains("pairServing"), - "follow offered: one ✓, after the pair's own wait: \(offered.all)") + expect(pair.text.hasSuffix(block("\u{2713}", String(served.dropLast()), []) + ClusterOnboardingDriver.closeWindowLine + "\n"), + "follow offered: the leader's ✓ block: \(pair.text)") + expect(pair.text.components(separatedBy: "\u{2713} Serving").count == 2 && !offered.all.contains("testRequest") && !offered.all.contains("pairServing"), + "follow offered: one ✓, the leader's, no wait of its own: \(offered.all)") transcript("member-follows-start-offered", pair.text, keys: pair.keys) } @@ -4298,12 +4302,15 @@ import Darwin let recorder = Recorder() let run = joining(recorder, statusSequence: [["Stopped."], [ClusterOnboardingNotServing.statusLine(model: "Qwen 3.8 27B", reason: "waiting for the coordinator to pair both Macs")]], - pairServingResults: [.failure(.init(notVerifiedTimed))]) + pairServingResults: [.failure(.init(notVerifiedTimed))], followSeconds: 1) expect(run.waitFor(codeQuestion), "follow ✗: the code"); run.type("y") expect(run.finish() == 1, "follow ✗: not serving is not success") let text = run.text - expect(text.hasSuffix(block("\u{2717}", "Not serving: " + notVerifiedTimed + ".", [ClusterOnboardingNotServing.remedy(forReason: notVerifiedTimed) ?? "-"]) - + ClusterOnboardingDriver.retryOnLeaderLine(leaderName) + "\n"), "follow ✗: why, then where to act: \(text)") + // The leading Mac said no outcome (an older leader): the bound's ✗ with what is known, never a verdict of its own + // (f2) and never Retry its screen may not show; the leader's own ✗ is `followFinalOutcomeChecks`. + expect(text.hasSuffix(block("\u{2717}", ClusterOnboardingNotServing.title(reason: ClusterOnboardingDriver.noOutcomeReason(leaderName, seconds: 1)), + ["Last: Qwen 3.8 27B is not serving yet: waiting for the coordinator to pair both Macs.", ClusterOnboardingDriver.noOutcomeLine])), + "follow ✗: the honest ✗, then where to look: \(text)") expect(ClusterOnboardingDriver.retryOnLeaderLine(leaderName) == "Choose Retry on \(leaderNamed): its screen shows the choices.", "follow ✗: the leader by name") expect(!text.contains("\u{2713} Serving") && !text.contains(ClusterOnboardingDriver.closeWindowLine), "follow ✗: never ✓: \(text)") @@ -4334,8 +4341,9 @@ import Darwin let stuck = joining(Recorder(), statusSequence: [["Stopped."], ["Loading Qwen 3.8 27B: 1 of 2 parts ready."]], followSeconds: 0.6) expect(stuck.waitFor(codeQuestion), "follow bound, started: the code"); stuck.type("y") expect(stuck.finish() == 1, "follow bound, started: not success") - expect(stuck.text.contains("\u{2717} Not serving: The pair didn't report serving within 0 minutes.\n Last: Loading Qwen 3.8 27B: 1 of 2 parts ready.\n") - && stuck.text.hasSuffix(ClusterOnboardingDriver.retryOnLeaderLine(leaderName) + "\n"), "follow bound, started: ✗ with the last state: \(stuck.text)") + expect(stuck.text.contains("\u{2717} Not serving: " + ClusterOnboardingDriver.noOutcomeReason(leaderName, seconds: 0.6) + + ".\n Last: Loading Qwen 3.8 27B: 1 of 2 parts ready.\n " + ClusterOnboardingDriver.noOutcomeLine + "\n") + && !stuck.text.contains("Choose Retry"), "follow bound, started: ✗ with the last state: \(stuck.text)") } /// The leader's status once its start's test request failed (`startTestFailure`): that start's outcome. @@ -4382,8 +4390,9 @@ import Darwin [localServingLine, leadersTestLine]]) expect(run.waitFor(codeQuestion), "P2-7: the code"); run.type("y") expect(run.finish(seconds: 20) == 0, "P2-7: ends with the leader's ✓") + // Retry is pointed to only in a final ✗ the leading Mac's screen shows (f2's rule): the part starts again by itself. expect(run.text.contains(" The other Mac: " + String(ending.dropLast()) + ".\n") - && run.text.contains(ClusterOnboardingDriver.retryOnLeaderLine(leaderName)), "P2-7: the leader's state, and where to Retry: \(run.text)") + && !run.text.contains("Choose Retry"), "P2-7: the leader's state, and no Retry mid-start: \(run.text)") } /// The pair-2 DevNet run (P2-4): after the pair was stopped (`cluster stop --service` on the member), Retry in the ✗ @@ -4532,7 +4541,7 @@ import Darwin /// Failing first on a148285f70 (one bound across all stages). static func eachStageOfTheStartHasItsOwnBound() { let served = "Serving Qwen 3.8 27B through Darkbloom on both Macs (pipeline)." - let stage = 10 + let stage = 8 let stages = [["Stopped."]] + Array(repeating: ["Loading Qwen 3.8 27B: 1 of 2 parts ready."], count: stage) + Array(repeating: [offerPendingLine], count: stage) + Array(repeating: ["Qwen 3.8 27B: registering both Macs with the coordinator for pairing."], count: stage) @@ -4541,14 +4550,14 @@ import Darwin let run = joining(recorder, statusSequence: stages, pairServingResults: [.success(["in 0.84 s"])], followSeconds: 2.5) expect(run.waitFor(codeQuestion), "stages: the code"); run.type("y") expect(run.finish(seconds: 30) == 0, "stages: each within its bound, the whole start longer: serves: \(run.text)") - expect(recorder.all.filter { $0 == "status" }.count > 3 * stage && recorder.all.contains("pairServing"), - "stages: followed through every stage to the pair's own wait: \(recorder.all.count)") + expect(recorder.all.filter { $0 == "status" }.count > 3 * stage && !recorder.all.contains("pairServing"), + "stages: followed through every stage to the leader's ✓: \(recorder.all.count)") var flapping = [["Stopped."]] for _ in 0..<60 { flapping += [["Loading Qwen 3.8 27B: 1 of 2 parts ready."], ["Stopped."]] } let stuck = joining(Recorder(), statusSequence: flapping, followSeconds: 0.6) expect(stuck.waitFor(codeQuestion), "stages, back and forth: the code"); stuck.type("y") - expect(stuck.finish(seconds: 30) == 1 && stuck.text.contains("\u{2717} Not serving: The pair didn't report serving within 0 minutes."), + expect(stuck.finish(seconds: 30) == 1 && stuck.text.contains("\u{2717} Not serving: " + ClusterOnboardingDriver.noOutcomeReason(leaderName, seconds: 0.6)), "stages, back and forth: one stage, so its bound ends it: \(stuck.text)") } diff --git a/provider-swift/Tests/ClusterOnboardingChecks/run.sh b/provider-swift/Tests/ClusterOnboardingChecks/run.sh index 6df908d781..1205f296e3 100755 --- a/provider-swift/Tests/ClusterOnboardingChecks/run.sh +++ b/provider-swift/Tests/ClusterOnboardingChecks/run.sh @@ -15,5 +15,6 @@ xcrun swiftc -swift-version 6 -warnings-as-errors -parse-as-library -target "$(u "$task_sources/ClusterOnboardingSoloServing.swift" \ "$task_sources/ClusterOnboardingStartProgress.swift" \ "$task_provider/Tests/ClusterOnboardingChecks/OnboardingChecks.swift" "$task_provider/Tests/ClusterOnboardingChecks/FollowWaitChecks.swift" \ - "$task_provider/Tests/ClusterOnboardingChecks/StartProgressChecks.swift" -o "$task_build/onboarding-checks" + "$task_provider/Tests/ClusterOnboardingChecks/StartProgressChecks.swift" \ + "$task_provider/Tests/ClusterOnboardingChecks/FollowFinalChecks.swift" -o "$task_build/onboarding-checks" "$task_build/onboarding-checks" diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterOnboardingStartProgressWireTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterOnboardingStartProgressWireTests.swift index 4caa9e6f57..14579ac33f 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterOnboardingStartProgressWireTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterOnboardingStartProgressWireTests.swift @@ -28,6 +28,25 @@ struct ClusterOnboardingStartProgressWireTests { #expect(reply.start?.phase == .unknown && reply.start?.done == 3) } + /// f2 (0.10.9 DevNet, pair-2): the leading Mac's final ✗ travels in its status, each Mac named by its part, and the + /// joining Mac reads it from its own side; a record after the leader's screen ended keeps it for a while. + @Test func theLeadersFinalCrossTravelsNamedByPart() throws { + let failed = ClusterOnboardingStartProgress.failed(title: "Not serving: The other Mac (Apple M5 Max, 128 GB) isn't logged in to Darkbloom.", + lines: ["Run `darkbloom login` on this Mac and the other Mac."], retry: true) + var reply = ClusterControlReply(lines: [], failed: false) + reply.start = failed + let read = try JSONDecoder().decode(ClusterControlReply.self, from: JSONEncoder().encode(reply)) + let viewed = try #require(read.start).viewed(leader: "Apple M3 Ultra, 256 GB") + #expect(viewed.phase == .failed && viewed.retry == true) + #expect(viewed.title == "Not serving: This Mac isn't logged in to Darkbloom.") + #expect(viewed.lines == ["Run `darkbloom login` on the other Mac (Apple M3 Ultra, 256 GB) and this Mac."]) + let older = try JSONDecoder().decode(OlderReply.self, from: JSONEncoder().encode(reply)) + #expect(older.lines.isEmpty, "an older Mac reads the rest") + let mark = ClusterOnboardingStartProgressMark(progress: failed, pid: 42, started: 7, at: 100) + #expect(mark.current(now: 100 + 600, started: { _ in nil }) != nil, "the ✗ outlives the leader's screen") + #expect(mark.current(now: 100 + ClusterOnboardingStartProgressMark.outcomeSeconds, started: { _ in nil }) == nil, "for a while only") + } + @Test func theSessionNamesTheReadyRanksAndAnOlderMacIgnoresThem() throws { var session = ClusterServiceStatus.Session(observed: true, ready: false, readyRanks: 1, ranks: 2, port: nil, detail: nil) session.readyRankList = [0] From 3bf662338473a766504988408426702e6711196b Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:53:14 -0800 Subject: [PATCH 06/20] fix(cluster): only the leading Mac waits on the other Mac's held-back reason The leader keeps the other Mac's reason (`peerHeldBack`) in memory and refreshes it only while it leads and runs the cluster (`syncMembers`). If control moved to the other Mac, that reason stayed, and this Mac's part, now a member, never started: the new leader's part then waited for its missing follower and ended every 38 s, the loop the rule exists to stop. `waitsForOtherMac` now takes `leads`, and the service passes `leadsAndRunsCluster()`. Red: ClusterControlChecks failed to compile (no `leads`), and the new check "no longer leading: never waits". Green: 682 passed, 0 failed. Docs: the rule and the status fields in docs/architecture/inference.md, the block's `reason`, `next` and exit 3 in docs/provider/cli-reference.md (Docs Impact), and a missing full stop in the agent-setup troubleshooting row. Co-Authored-By: Claude Opus 5.5 --- docs/architecture/inference.md | 12 ++++++++++++ docs/provider/agent-setup.md | 2 +- docs/provider/cli-reference.md | 8 ++++++++ .../Onboarding/ClusterControlLeadership.swift | 8 +++++--- .../Distributed/Onboarding/ClusterService.swift | 3 ++- .../Tests/ClusterControlChecks/ControlChecks.swift | 11 +++++++---- .../Inference/Distributed/SoloBlockPeerTests.swift | 7 ++++--- 7 files changed, 39 insertions(+), 12 deletions(-) diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index 39cef8d19c..818b86ae9e 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -3956,6 +3956,18 @@ Mac whose pair doesn't run clears the intent and waits for the part to end (`ClusterService.releaseForSingleMac`) before single-Mac serving starts ([going back to serving on one Mac](../provider/two-mac-cluster.md#going-back-to-serving-on-one-mac)). +Single-Mac serving holds a Mac's one serving lock and never ends by itself, so +neither Mac's part starts beside it. Each Mac's status reports it in +`soloServing` whenever no part of its own holds the lock, and says why its part +can't start in `heldBack` (0.10.9; both nil from an older build). At each +15-second sync the leading Mac reads the other Mac's reason +(`ClusterService.heldBack(of:)`: `heldBack`, else its `soloServing`), and while +one is reported its own part doesn't start +(`ClusterControlPartChoice.waitsForOtherMac`): a part started anyway only waits +for its missing follower and ends again. The rule applies only while this Mac +leads and runs the cluster, and never to serving alone (`solo:`); a Mac that +doesn't answer reports nothing, so its absence follows the control lease. + ## Cluster service listeners follow the cable and the pairing Each Mac's cluster service answers the other Mac on two listeners: the setup diff --git a/docs/provider/agent-setup.md b/docs/provider/agent-setup.md index ba7acc1e70..35200930e6 100644 --- a/docs/provider/agent-setup.md +++ b/docs/provider/agent-setup.md @@ -781,7 +781,7 @@ yet"](troubleshooting.md#a-two-mac-cluster-says-not-serving-yet) and | Signal | Cause | Do | |---|---|---| | The human stopped clustering, and the Mac is online but gets no requests; `darkbloom status` says ``The other Mac (…) hasn't answered for 15 min; this Mac's part stopped.`` or ``The pair hasn't served for … min``; on 0.10.8 `darkbloom start --solo` says ``This Mac's part of the pair holds its serving lock`` | The Mac kept the pair's saved start, so its cluster service ran its part of a pair that no longer forms. That part registers only as a pair member, which gets no ordinary requests | With the human's go, run `darkbloom start` on that Mac (0.10.9 or later): it stops the leftover part and serves this Mac alone. On 0.10.8: `darkbloom cluster pair --status`, then `darkbloom cluster pair --forget `, then `darkbloom start`. Never plain `darkbloom stop` on 0.10.8 for this: it acts on the pair | -| ``✗ The pair can't start: a single-Mac Darkbloom provider (process ) is serving on , …``; a cluster status or log line ``a single-Mac Darkbloom provider (process ) is serving on this Mac, so this Mac's part can't start``; an incident `local_provider_running`. In 0.10.8 the same cause read ``another update operation owns the lock (pid , provider-instance)`` and looped ``this Mac's part ended … and starts again by itself`` | Single-Mac serving runs on that Mac and holds its one serving lock, so the pair's part can't start there. It doesn't end by itself | **STOP**: ask the human whether to stop single-Mac serving on each Mac named. With their go, run `darkbloom stop --solo` on that Mac, then `darkbloom start` (on DevNet, `darkbloom-dev`). In `darkbloom cluster`, **Stop single-Mac serving on both Macs and start the pair** does both. Both Macs' `darkbloom cluster status` say the block, with `next` ``Single-Mac serving doesn't stop by itself: …`` (`state` `not_serving`, exit status 3), and the joining Mac's window shows the same ✗. Neither Mac keeps restarting its part meanwhile; don't wait for it to clear by itself Never plain `darkbloom stop` for this: on a paired Mac it stops the pair and leaves single-Mac serving running | +| ``✗ The pair can't start: a single-Mac Darkbloom provider (process ) is serving on , …``; a cluster status or log line ``a single-Mac Darkbloom provider (process ) is serving on this Mac, so this Mac's part can't start``; an incident `local_provider_running`. In 0.10.8 the same cause read ``another update operation owns the lock (pid , provider-instance)`` and looped ``this Mac's part ended … and starts again by itself`` | Single-Mac serving runs on that Mac and holds its one serving lock, so the pair's part can't start there. It doesn't end by itself | **STOP**: ask the human whether to stop single-Mac serving on each Mac named. With their go, run `darkbloom stop --solo` on that Mac, then `darkbloom start` (on DevNet, `darkbloom-dev`). In `darkbloom cluster`, **Stop single-Mac serving on both Macs and start the pair** does both. Both Macs' `darkbloom cluster status` say the block, with `next` ``Single-Mac serving doesn't stop by itself: …`` (`state` `not_serving`, exit status 3), and the joining Mac's window shows the same ✗. Neither Mac keeps restarting its part meanwhile; don't wait for it to clear by itself. Never plain `darkbloom stop` for this: on a paired Mac it stops the pair and leaves single-Mac serving running | | 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”; if it isn't listed, click Allow when macOS asks on that Mac's screen, the next time Darkbloom dials over the cable (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, and add that macOS lists Darkbloom Dev as “Darkbloom”). `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 from about 20 seconds into its part, steadily after that while that Mac stays refused | 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” (the DevNet app is listed under that name too), or, with no such row, clicks **Allow** when macOS asks on that screen. 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 | diff --git a/docs/provider/cli-reference.md b/docs/provider/cli-reference.md index f2106e0cae..53d517f60b 100644 --- a/docs/provider/cli-reference.md +++ b/docs/provider/cli-reference.md @@ -790,6 +790,14 @@ through Darkbloom" (`OnboardingLive.notOfferedLines`): planned for Darkbloom). Or serve locally only: `darkbloom cluster local` on ." - `darkbloom start` without a terminal stops waiting at once on this reason (exit 3). +While single-Mac serving runs on either Mac of a started pair, the pair can't start there and it doesn't stop by +itself. Both Macs read `not_serving` (exit 3), never "keep trying by themselves": +- `reason` is "The pair can't start: a single-Mac Darkbloom provider (process ) is serving on , and the pair + can't share a Mac with it". +- `next` is "Single-Mac serving doesn't stop by itself: run `darkbloom stop --solo` on each Mac named, then + `darkbloom start` on either Mac. Or `darkbloom cluster` on offers to stop it and start the pair." +- `darkbloom start` without a terminal stops waiting at once on this reason (exit 3). + During a model or mode change, or while the pair updates Darkbloom, `status` and `cluster status` can read `stopped` (exit 4) or `unknown` for a minute or two while the pair is actually reloading. If such a change happened recently, or the status showed "Updating…", wait about a minute and check again before acting. Run `darkbloom start` only if it diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterControlLeadership.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterControlLeadership.swift index 556371be58..01ca7c8b31 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterControlLeadership.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterControlLeadership.swift @@ -587,9 +587,11 @@ public enum ClusterControlPartChoice: Sendable, Equatable { /// Why this Mac's part of the pair (`key` "cluster:…") waits instead of starting: the other Mac reports its own part /// can't start for a reason that doesn't clear by itself (`otherMacHeldBack`; single-Mac serving there). A part started - /// anyway only waits for its missing follower and ends again (every 38 s on pair-2). Never for serving alone ("solo:"). - public static func waitsForOtherMac(key: String, otherMacHeldBack: String?) -> String? { - guard key.hasPrefix("cluster:"), let reason = otherMacHeldBack, !reason.isEmpty else { return nil } + /// anyway only waits for its missing follower and ends again (every 38 s on pair-2). Never for serving alone ("solo:"), + /// and only while this Mac leads (`leads`): only the leader reads that reason, so a member never waits on one it read + /// while it led. + public static func waitsForOtherMac(key: String, otherMacHeldBack: String?, leads: Bool) -> String? { + guard leads, key.hasPrefix("cluster:"), let reason = otherMacHeldBack, !reason.isEmpty else { return nil } return reason } diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift index 693d6a7be0..28d0474c8b 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift @@ -1772,7 +1772,8 @@ public final class ClusterService: @unchecked Sendable { // The other Mac said its part can't start for a reason that doesn't clear by itself: this Mac's part waits for that // to change instead of starting, waiting for its missing follower and ending every 38 s (0.10.9 DevNet f1). if running == nil, let key { - let reason = ClusterControlPartChoice.waitsForOtherMac(key: key, otherMacHeldBack: lock.withLock { peerHeldBack }) + let reason = ClusterControlPartChoice.waitsForOtherMac(key: key, otherMacHeldBack: lock.withLock { peerHeldBack }, + leads: leadsAndRunsCluster()) let before = lock.withLock { () -> String? in defer { peerHeldBackSaid = reason }; return peerHeldBackSaid } if let reason { if before != reason { say("the other Mac's part can't start (\(reason)): this Mac's part waits for that to change") } diff --git a/provider-swift/Tests/ClusterControlChecks/ControlChecks.swift b/provider-swift/Tests/ClusterControlChecks/ControlChecks.swift index 020cd41972..d9c3724ee7 100644 --- a/provider-swift/Tests/ClusterControlChecks/ControlChecks.swift +++ b/provider-swift/Tests/ClusterControlChecks/ControlChecks.swift @@ -784,10 +784,13 @@ import Darwin expect(P.mayStart(key: "cluster:abc", endedKey: "cluster:abc", backoffElapsed: true), "backoff elapsed") // 0.10.9 DevNet f1: the leader's part ended every 38 s while the other Mac's single-Mac provider held its part back. let held = "a single-Mac Darkbloom provider (process 68099) is serving there" - expect(P.waitsForOtherMac(key: "cluster:abc", otherMacHeldBack: held) == held, "held back there: this Mac's part waits") - expect(P.waitsForOtherMac(key: "cluster:abc:local-only@127.0.0.1", otherMacHeldBack: held) == held, "local only: waits too") - expect(P.waitsForOtherMac(key: "solo:m", otherMacHeldBack: held) == nil, "serving alone never waits for the other Mac") - expect(P.waitsForOtherMac(key: "cluster:abc", otherMacHeldBack: nil) == nil, "nothing held back: it starts") + expect(P.waitsForOtherMac(key: "cluster:abc", otherMacHeldBack: held, leads: true) == held, "held back there: this Mac's part waits") + expect(P.waitsForOtherMac(key: "cluster:abc:local-only@127.0.0.1", otherMacHeldBack: held, leads: true) == held, "local only: waits too") + expect(P.waitsForOtherMac(key: "solo:m", otherMacHeldBack: held, leads: true) == nil, "serving alone never waits for the other Mac") + expect(P.waitsForOtherMac(key: "cluster:abc", otherMacHeldBack: nil, leads: true) == nil, "nothing held back: it starts") + // A reason read while this Mac led stays in memory after control moves to the other Mac: as a member, its part + // follows the leader's lease, never that reason (it would never start, and the leader's part would end every 38 s). + expect(P.waitsForOtherMac(key: "cluster:abc", otherMacHeldBack: held, leads: false) == nil, "no longer leading: never waits") expect(!P.mayStart(key: "solo:m", endedKey: "solo:m", backoffElapsed: false), "a crashing solo server backs off too") expect(P.mayStart(key: "cluster:abc", endedKey: nil, backoffElapsed: false), "nothing ended: at once") } diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/SoloBlockPeerTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/SoloBlockPeerTests.swift index 10248b0bbd..ecd2f5e0b2 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/SoloBlockPeerTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/SoloBlockPeerTests.swift @@ -26,9 +26,10 @@ struct SoloBlockPeerTests { let base = #""serving":true,"sessionLeader":false,"child":{"running":false,"starts":0}"# let member = try status("{\(base),\"soloServing\":{\"pid\":68099}}") let held = ClusterService.heldBack(of: member) - #expect(ClusterControlPartChoice.waitsForOtherMac(key: "cluster:84377e741989", otherMacHeldBack: held) != nil) + #expect(ClusterControlPartChoice.waitsForOtherMac(key: "cluster:84377e741989", otherMacHeldBack: held, leads: true) != nil) + #expect(ClusterControlPartChoice.waitsForOtherMac(key: "cluster:84377e741989", otherMacHeldBack: held, leads: false) == nil) #expect(ClusterControlPartChoice.waitsForOtherMac(key: "cluster:84377e741989", - otherMacHeldBack: ClusterService.heldBack(of: try status("{\(base)}"))) == nil) - #expect(ClusterControlPartChoice.waitsForOtherMac(key: "solo:EigenLabs/Qwen3.8-27B-4bit-mtp", otherMacHeldBack: held) == nil) + otherMacHeldBack: ClusterService.heldBack(of: try status("{\(base)}")), leads: true) == nil) + #expect(ClusterControlPartChoice.waitsForOtherMac(key: "solo:EigenLabs/Qwen3.8-27B-4bit-mtp", otherMacHeldBack: held, leads: true) == nil) } } From e1ab06abbcf90284d580f48c9c72a93380ed343a Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:57:07 -0800 Subject: [PATCH 07/20] fix(cluster): single-Mac serving steps aside for a started pair unless chosen; blocked ends never set the approval aside MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From "none of the steps worked" (solo-steps-failed.md §3–§5): - Self-heal for the 0.10.8 → 0.10.9 rollout: when the pair is started and wants this Mac's part ("cluster:" key) while single-Mac serving holds the lock, and no choice of single-Mac serving stands (`ClusterSoloChoice`), the cluster service runs `stop --solo` once per process, logs it and leaves a note `darkbloom status` shows. `start --solo` / "Serve on this Mac alone" record the choice; an explicit pair start here (onboarding serve, `start` → pair) and `stop --solo` clear it; a Mac updated from 0.10.8 has none, so the pair wins. Never when no part or only the degraded server is wanted, so it never fights #1793's "pair isn't running → serve alone". - Ends caused by the held lock (either Mac held back, or the lock's words) don't count toward the local-only fallback; when the blocker clears (step aside, offer, or the other Mac's held-back reason gone) the count resets and a `failing` set-aside approval is dropped, so the pair is offered to Darkbloom again at once. - The version split is said before the single-Mac ✗ (`blockApplies`). Co-Authored-By: Claude Opus 5.5 --- changelog.d/cluster-solo-steps-aside.md | 5 ++ .../ClusterApprovalCheck.swift | 15 +++- .../ClusterOnboardingLive+SoloServing.swift | 9 +-- .../Onboarding/ClusterOnboardingLive.swift | 4 +- .../ClusterOnboardingSoloServing.swift | 7 ++ .../Onboarding/ClusterService.swift | 69 +++++++++++++++++-- .../Onboarding/ClusterSoloChoice.swift | 69 +++++++++++++++++++ .../darkbloom/Start/StartCommand.swift | 16 +++++ .../StatusCommand+ClusterService.swift | 8 +++ .../Sources/darkbloom/StatusCommand.swift | 2 + .../Sources/darkbloom/StopCommand.swift | 2 + .../Distributed/SoloStepsStickTests.swift | 69 +++++++++++++++++++ 12 files changed, 264 insertions(+), 11 deletions(-) create mode 100644 changelog.d/cluster-solo-steps-aside.md create mode 100644 provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterSoloChoice.swift create mode 100644 provider-swift/Tests/ProviderCoreTests/Inference/Distributed/SoloStepsStickTests.swift diff --git a/changelog.d/cluster-solo-steps-aside.md b/changelog.d/cluster-solo-steps-aside.md new file mode 100644 index 0000000000..cd3d3ae7f6 --- /dev/null +++ b/changelog.d/cluster-solo-steps-aside.md @@ -0,0 +1,5 @@ +### Single-Mac serving steps aside for a started pair, and the pair goes back to Darkbloom at once + +- When the pair is started and wants this Mac's part, but single-Mac serving holds the Mac's serving lock and nobody chose it since the pair was started, the cluster service now stops it the way `darkbloom stop --solo` does. It logs why, and `darkbloom status` says so too. This covers single-Mac serving restarted by 0.10.8's updater during tonight's update, by a login, or by the watchdog. It doesn't step aside when you chose single-Mac serving yourself: `start --solo`, the terminal's "Serve on this Mac alone" and serving alone from the app record that choice, and starting the pair or `stop --solo` on that Mac clears it. A Mac updated from 0.10.8 has no recorded choice, so the started pair wins. It never steps aside while the pair isn't running there (serving alone stays as it is). +- Parts that ended because single-Mac serving held a Mac's serving lock no longer count toward the pair falling back to local-only serving. Once single-Mac serving stops, through the offer, `stop --solo` or a step aside, the count resets. An approval set aside for "parts kept ending" is offered to Darkbloom again at once, instead of after up to an hour. +- When the two Macs run different versions, the start's ✗ says that first, not the single-Mac block. diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Membership/ClusterApproval/ClusterApprovalCheck.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Membership/ClusterApproval/ClusterApprovalCheck.swift index 04b5e8b75b..8fb16c0c27 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Membership/ClusterApproval/ClusterApprovalCheck.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Membership/ClusterApproval/ClusterApprovalCheck.swift @@ -147,12 +147,25 @@ enum ClusterApprovalCheck { /// handles instead. A quick end because the coordinator did not accept the member role in its negotiation window /// (during a deploy, right after a restart, or when it is slow) leaves the count as it is: the coordinator decided /// it, not this Mac's part. Every other end counts, a crash or a changed input included. - static func memberQuickEnds(after count: Int, ranSeconds: Double, lastError: String?) -> Int { + static func memberQuickEnds(after count: Int, ranSeconds: Double, lastError: String?, heldBack: Bool = false) -> Int { if lastError?.contains(unreachableMemberEnd) == true { return 0 } + // A part that ended because single-Mac serving holds a Mac's serving lock (this Mac's, or the other Mac's part held + // back) says nothing about the approval: it never counts toward serving locally. + if heldBack || blockedByLock(lastError) { return count } if lastError?.contains(notAcceptedMemberEnd) == true, ranSeconds < ClusterControlSoloAdmission.quickEndSeconds { return count } return ClusterControlSoloAdmission.quickEnds(after: count, ranSeconds: ranSeconds) } + /// An end caused by the provider instance lock: single-Mac serving held it (the lock's words since 0.10.9, and before). + static func blockedByLock(_ lastError: String?) -> Bool { + guard let lastError else { return false } + return lastError.contains("single-Mac Darkbloom provider") || lastError.contains("provider-instance") + || lastError.contains("provider instance lock") + } + + /// An approval set aside because its parts kept failing is taken again once the blocker that made them end cleared. + static func clearsAfterBlocker(_ reason: ClusterApprovalFallback) -> Bool { reason == .failing } + /// How a member's error line starts when its registration wait never reached the coordinator. static let unreachableMemberEnd = String(ClusterMemberControlError.coordinatorUnreachable.rawValue.prefix(40)) /// A member's error line when the coordinator kept its registration open past the negotiation window without an diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive+SoloServing.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive+SoloServing.swift index eba81494b8..5d41cc6d20 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive+SoloServing.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive+SoloServing.swift @@ -7,11 +7,12 @@ extension OnboardingLive { /// Mac that doesn't answer, or an older build that doesn't say, adds none). func soloServing() -> [ClusterOnboardingSoloServing] { var found = [ClusterOnboardingSoloServing]() + let status = (try? command(.init(op: .status), seconds: 10)).flatMap { try? JSONDecoder().decode(ClusterServiceStatus.self, from: $0) } + // Macs on different versions can't pair whatever single-Mac serving does: that ✗ comes first, never this one. + guard ClusterOnboardingSoloServing.blockApplies(thisVersion: ProviderCore.version, otherVersion: status?.pairUpdate?.running) + else { return [] } if let holder = ProviderInstanceHolder.singleMacServing() { found.append(.init(mac: here, pid: holder.pid)) } - if let data = try? command(.init(op: .status), seconds: 10), - let status = try? JSONDecoder().decode(ClusterServiceStatus.self, from: data), let solo = status.soloServing { - found.append(.init(mac: there, pid: solo.pid)) - } + if let solo = status?.soloServing { found.append(.init(mac: there, pid: solo.pid)) } return found } diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift index a0dade7954..4ec9c6d9f0 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift @@ -1501,7 +1501,9 @@ final class OnboardingLive: @unchecked Sendable { } func serve() -> Result<[String], ClusterOnboardingFailure> { - routed(.init(op: .serve), acting: true, local: { localServe() }) { $0.lines } + // The person starts the pair from this Mac: a choice of single-Mac serving made here before no longer stands. + ClusterSoloChoice.clear(in: store.paths.directory) + return routed(.init(op: .serve), acting: true, local: { localServe() }) { $0.lines } } /// The screen's start through Darkbloom, which asks the coordinator after its test whether to offer the pair diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingSoloServing.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingSoloServing.swift index 5efa598273..779d36bf1c 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingSoloServing.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingSoloServing.swift @@ -36,6 +36,13 @@ public struct ClusterOnboardingSoloServing: Sendable, Equatable, Codable { /// Whether a not-serving reason (`ClusterOnboardingNotServing.reason(inStatusLine:)`) is this block. public static func isBlock(_ reason: String) -> Bool { reason.hasPrefix(titlePrefix) } + /// Whether the single-Mac block is the one to say: not when the two Macs run different versions (the version split + /// is said first, with `darkbloom update` on the Mac behind; PR #1795). Unknown versions don't decide. + public static func blockApplies(thisVersion: String?, otherVersion: String?) -> Bool { + guard let thisVersion, let otherVersion else { return true } + return thisVersion == otherVersion + } + /// On the Mac that joined: the leading Mac's screen offers the stop too (`stopAndStartItem`). public static func leaderOffersLine(_ leader: String?) -> String { "Or choose \"Stop single-Mac serving … and start the pair\" on \(ClusterOnboardingMacName.other(named: leader)): it stops it " diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift index 693d6a7be0..85a9178b2e 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift @@ -107,6 +107,11 @@ public final class ClusterService: @unchecked Sendable { /// On the leader: why the other Mac's part can't start now, as its status last said (`ClusterService.heldBack(of:)`); /// this Mac's part waits for it instead of starting and ending again. Nil when it says none or didn't answer. private var peerHeldBack: String? + /// A step aside of single-Mac serving runs (`stepAsideIfUnchosen`), and the process it was for. + private var steppingAside = false + private var steppedAsidePID: Int32? + /// How single-Mac serving is stopped (`stop --solo`); tests stand in. + var stopSingleMac: @Sendable (URL) -> Result = { ClusterService.stopSoloServing(executable: $0) } private var peerHeldBackSaid: String? private var nextSync = Date.distantPast // Setting the cluster up again after a Darkbloom update (`checkForUpdate`). @@ -772,6 +777,8 @@ public final class ClusterService: @unchecked Sendable { guard ProviderInstanceHolder.current(lockFile: providerInstanceLock)?.kind == .singleMac else { return try encoder.encode(status()) } if case .failure(let failure) = Self.stopSoloServing(executable: settings.wizard.darkbloomExecutable) { throw failure } say("stopped single-Mac serving on this Mac, as the other Mac's screen asked") + ClusterSoloChoice.clear(in: store.paths.directory) + blockerCleared(say: say) lock.withLock { nextStart = .distantPast; backoff = 3 } return try encoder.encode(status()) case .prompt: @@ -1550,17 +1557,63 @@ public final class ClusterService: @unchecked Sendable { /// Whether single-Mac serving on this Mac holds back this Mac's part now: said once when it is first seen, and once /// when it stopped. - private func holdsBackForSoloServing(say: @escaping @Sendable (String) -> Void) -> Bool { + private func holdsBackForSoloServing(key: String?, say: @escaping @Sendable (String) -> Void) -> Bool { let found = ProviderInstanceHolder.current(lockFile: providerInstanceLock).flatMap { $0.kind == .singleMac ? $0 : nil } let before = lock.withLock { () -> ProviderInstanceHolder.Holder? in defer { soloServing = found }; return soloServing } if let found { if before != found { say(Self.soloServingError(found) + "; this Mac's part waits for it to stop") } + stepAsideIfUnchosen(found, key: key, say: say) return true } - if before != nil { say("single-Mac serving stopped on this Mac: starting this Mac's part") } + if before != nil { + say("single-Mac serving stopped on this Mac: starting this Mac's part") + blockerCleared(say: say) + } return false } + /// Single-Mac serving that nobody chose since the pair was last started here (`ClusterSoloChoice.stepsAside`; for + /// example 0.10.8's updater restarted it) is stopped as `darkbloom stop --solo` stops it, once per process, on a thread + /// of its own. A choice the person made keeps it, and the block stays on both screens. + private func stepAsideIfUnchosen(_ holder: ProviderInstanceHolder.Holder, key: String?, say: @escaping @Sendable (String) -> Void) { + let directory = store.paths.directory + guard ClusterSoloChoice.stepsAside(wantedKey: key, chosenAt: ClusterSoloChoice.chosenAt(in: directory)) else { return } + let begin = lock.withLock { () -> Bool in + guard !steppingAside, steppedAsidePID != holder.pid || holder.pid == nil else { return false } + steppingAside = true; steppedAsidePID = holder.pid; return true + } + guard begin else { return } + let executable = settings.wizard.darkbloomExecutable, stop = stopSingleMac + say(ProviderInstanceHolder.clause(holder) + ", and nobody chose it since the pair was started here: stopping it as " + + "`\(BuildEnvironment.current.cliName) stop --solo` does, so the pair can start") + Thread.detachNewThread { [weak self] in + let result = stop(executable) + self?.lock.withLock { self?.steppingAside = false } + switch result { + case .success: + ClusterSoloChoice.noteSteppedAside(.init(at: Date().timeIntervalSince1970, pid: holder.pid), in: directory) + say(ClusterSoloChoice.line(.init(at: Date().timeIntervalSince1970, pid: holder.pid), cli: BuildEnvironment.current.cliName)) + case .failure(let failure): + say("single-Mac serving could not step aside: \(failure.text); `\(BuildEnvironment.current.cliName) stop --solo` on this Mac stops it") + } + } + } + + /// The blocker cleared (single-Mac serving stopped here, or on the other Mac): its blocked ends are forgotten, and an + /// approval they set aside as failing is taken again now, so the pair goes back to Darkbloom at once, not after an hour. + private func blockerCleared(say: @escaping @Sendable (String) -> Void) { + lock.withLock { memberQuickEnds = 0; nextStart = .distantPast; backoff = 3 } + guard let record = try? store.readRecord(), let setAside = record.approvalSetAside, + ClusterApprovalCheck.clearsAfterBlocker(setAside.reason) else { return } + try? store.updateRecord { if $0.approvalSetAside.map { ClusterApprovalCheck.clearsAfterBlocker($0.reason) } == true { $0.approvalSetAside = nil } } + say("the blocker cleared: offering the pair to Darkbloom again with approval \(setAside.approval.id)") + } + + /// This Mac's cluster setup directory, where the person's choice of single-Mac serving is kept (`ClusterSoloChoice`). + public static func soloChoiceDirectory() -> URL? { + (try? ClusterUserPaths()).map { ClusterSetupPaths(paths: $0).directory } + } + /// How long a consented stop of single-Mac serving lets its accepted requests finish (`stop --solo --timeout`). public static let soloStopSeconds = 120 @@ -1699,7 +1752,10 @@ public final class ClusterService: @unchecked Sendable { // accepted in time) is not counted. if lock.withLock({ childIsMember }) { let lastError = Self.lastError(in: serviceFiles.rankLog, from: lock.withLock { childLogOffset }, preferStopReason: false) - lock.withLock { memberQuickEnds = ClusterApprovalCheck.memberQuickEnds(after: memberQuickEnds, ranSeconds: ran, lastError: lastError) } + // An end while either Mac's part is held back (single-Mac serving) is the blocker's, not the approval's. + let heldBack = lock.withLock { peerHeldBack != nil || soloServing != nil } + lock.withLock { memberQuickEnds = ClusterApprovalCheck.memberQuickEnds(after: memberQuickEnds, ranSeconds: ran, lastError: lastError, + heldBack: heldBack) } } // F14: a solo server that keeps ending right after its start is not started again for this plan and model // (`ClusterControlSoloAdmission`): the status then says this Mac cannot serve it alone. @@ -1767,7 +1823,7 @@ public final class ClusterService: @unchecked Sendable { // Single-Mac serving holds this Mac's one serving lock and never ends by itself: a part started beside it only // ended at once and started again every few seconds (0.10.8, 2026-11-04: "this Mac's part ended (exit 1: …)" // in a loop on both Macs). Nothing starts until it stops; the status names it meanwhile. - if running == nil, key != nil, holdsBackForSoloServing(say: say) { return } + if running == nil, key != nil, holdsBackForSoloServing(key: key, say: say) { return } if key == nil { lock.withLock { soloServing = nil } } // The other Mac said its part can't start for a reason that doesn't clear by itself: this Mac's part waits for that // to change instead of starting, waiting for its missing follower and ending every 38 s (0.10.9 DevNet f1). @@ -1778,7 +1834,10 @@ public final class ClusterService: @unchecked Sendable { if before != reason { say("the other Mac's part can't start (\(reason)): this Mac's part waits for that to change") } return } - if before != nil { say("the other Mac's part can start again: starting this Mac's part") } + if before != nil { + say("the other Mac's part can start again: starting this Mac's part") + blockerCleared(say: say) + } } // The restart backoff holds back only the part that ended: serving alone after the grace starts at once. guard running == nil, let key, lock.withLock({ !stopping && ClusterControlPartChoice.mayStart(key: key, endedKey: endedKey, diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterSoloChoice.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterSoloChoice.swift new file mode 100644 index 0000000000..e45de4e5fa --- /dev/null +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterSoloChoice.swift @@ -0,0 +1,69 @@ +import Foundation + +/// Whether single-Mac serving on a paired Mac was the person's own choice, made after the pair was last started here. +/// +/// Tonight's 0.10.8 → 0.10.9 update runs 0.10.8's updater, which can restart single-Mac serving on a paired Mac (its job +/// was left set up by a `darkbloom start` from before 0.10.8). Single-Mac serving then holds the Mac's one serving lock, +/// and the pair can never start again. So on a Mac whose pair is started and wants its part, the cluster service stops +/// single-Mac serving by itself, as `darkbloom stop --solo` does (`stepsAside`), unless the person chose it: `start +/// --solo`, the terminal's "Serve on this Mac alone" and Go Online serving alone record the choice here (`record`), and +/// an explicit start of the pair or `stop --solo` on this Mac clears it (`clear`). A Mac updated from 0.10.8 has no +/// record, so the started pair wins. +public enum ClusterSoloChoice { + /// The choice's file in this Mac's cluster setup directory. + static func file(in directory: URL) -> URL { directory.appendingPathComponent("solo-choice.json") } + /// What the last step aside did, for `darkbloom status` (`steppedAside`). + static func noteFile(in directory: URL) -> URL { directory.appendingPathComponent("solo-stepped-aside.json") } + + struct Choice: Codable { var chosenAt: Double } + public struct SteppedAside: Codable, Equatable, Sendable { + public var at: Double + public var pid: Int32? + public init(at: Double, pid: Int32?) { self.at = at; self.pid = pid } + } + + /// The person chose single-Mac serving on this Mac now (seconds since 1970). + public static func record(in directory: URL, now: Double = Date().timeIntervalSince1970) { + try? FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true) + guard let data = try? JSONEncoder().encode(Choice(chosenAt: now)) else { return } + try? data.write(to: file(in: directory), options: .atomic) + try? FileManager.default.removeItem(at: noteFile(in: directory)) + } + + /// The pair was started on this Mac, or single-Mac serving was stopped here: no choice stands any more. + public static func clear(in directory: URL) { + try? FileManager.default.removeItem(at: file(in: directory)) + } + + /// When the person chose single-Mac serving here; nil when no choice stands. + public static func chosenAt(in directory: URL) -> Double? { + guard let data = try? Data(contentsOf: file(in: directory)) else { return nil } + return (try? JSONDecoder().decode(Choice.self, from: data))?.chosenAt + } + + /// Single-Mac serving steps aside for the pair: the pair is started and wants this Mac's part ("cluster:" key, never + /// the degraded server of a pair that doesn't run, nor no part at all, so it never fights "the pair isn't running: + /// serve alone"), and the person didn't choose single-Mac serving since the pair was last started here. + public static func stepsAside(wantedKey: String?, chosenAt: Double?) -> Bool { + guard let wantedKey, wantedKey.hasPrefix("cluster:") else { return false } + return chosenAt == nil + } + + public static func noteSteppedAside(_ note: SteppedAside, in directory: URL) { + try? FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true) + guard let data = try? JSONEncoder().encode(note) else { return } + try? data.write(to: noteFile(in: directory), options: .atomic) + } + + public static func steppedAside(in directory: URL) -> SteppedAside? { + guard let data = try? Data(contentsOf: noteFile(in: directory)) else { return nil } + return try? JSONDecoder().decode(SteppedAside.self, from: data) + } + + /// The line `darkbloom status` and the service log say after a step aside. + public static func line(_ note: SteppedAside, cli: String) -> String { + let time = ISO8601DateFormatter().string(from: Date(timeIntervalSince1970: note.at)) + return "Single-Mac serving stepped aside for the pair at \(time)" + (note.pid.map { " (process \($0))" } ?? "") + + ": the pair is started here and nobody chose single-Mac serving since. `\(cli) start --solo` serves this Mac alone again." + } +} diff --git a/provider-swift/Sources/darkbloom/Start/StartCommand.swift b/provider-swift/Sources/darkbloom/Start/StartCommand.swift index 74138d4393..7e1113cc2f 100644 --- a/provider-swift/Sources/darkbloom/Start/StartCommand.swift +++ b/provider-swift/Sources/darkbloom/Start/StartCommand.swift @@ -198,6 +198,18 @@ struct Start: AsyncParsableCommand { /// How long the leftover part gets to release its model and the serving lock. static let releaseSeconds: Double = 300 + /// The person chose single-Mac serving on this paired Mac (`ClusterSoloChoice`): it doesn't step aside for the pair. + static func recordSoloChoice() { + guard ClusterPairSummary.readsThisMacsCluster, let directory = ClusterService.soloChoiceDirectory() else { return } + ClusterSoloChoice.record(in: directory) + } + + /// The person starts the pair here: an earlier choice of single-Mac serving no longer stands. + static func clearSoloChoice() { + guard ClusterPairSummary.readsThisMacsCluster, let directory = ClusterService.soloChoiceDirectory() else { return } + ClusterSoloChoice.clear(in: directory) + } + static func releaseLeftoverPart() async -> Bool { if let release = releaseForTesting { return release() } guard ClusterPairSummary.readsThisMacsCluster else { return true } @@ -261,8 +273,10 @@ struct Start: AsyncParsableCommand { switch choice { case .single(let note): if let note { print(note) } + if pair.paired { Self.recordSoloChoice() } case .serveAlone(let note): print(note) + Self.recordSoloChoice() let released = !pair.started || !pair.serviceRunning ? true : await Self.releaseLeftoverPart() guard released else { for line in pair.releaseFailedLines { print(line) } @@ -277,10 +291,12 @@ struct Start: AsyncParsableCommand { for line in lines { print(line) } throw ExitCode.validationFailure case .openScreen: + Self.clearSoloChoice() print(pair.actingLine("starting the pair")) try await ClusterPairCommands.openScreen(config: configOptions.config) return case .startPair: + Self.clearSoloChoice() let code = await ClusterPairCommands.start(pair, actions: ClusterPairActions.live(config: configOptions.config), config: configOptions.config) if code != 0 { throw ExitCode(code) } diff --git a/provider-swift/Sources/darkbloom/StatusCommand+ClusterService.swift b/provider-swift/Sources/darkbloom/StatusCommand+ClusterService.swift index fde1e0f9df..a558c6c133 100644 --- a/provider-swift/Sources/darkbloom/StatusCommand+ClusterService.swift +++ b/provider-swift/Sources/darkbloom/StatusCommand+ClusterService.swift @@ -28,6 +28,14 @@ extension Status { /// No running provider (no state, or a stale one): on a Mac in a cluster single-Mac serving is off, which /// `darkbloom start` would not fix. `unsure`: its pairing record couldn't be read. + /// Why single-Mac serving isn't running on a paired Mac when it stepped aside for the pair by itself + /// (`ClusterSoloChoice`); nil otherwise. + static func steppedAsideLine(paired: Bool) -> String? { + guard paired, ClusterPairSummary.readsThisMacsCluster, let directory = ClusterService.soloChoiceDirectory(), + let note = ClusterSoloChoice.steppedAside(in: directory) else { return nil } + return ClusterSoloChoice.line(note, cli: BuildEnvironment.current.cliName) + } + static func daemonNotRunningLine(paired: Bool, unsure: Bool = false, staleStateFile: Bool = false) -> String { if paired { return unsure ? ClusterPairSummary.singleMacServingOffUnsureLine : ClusterPairSummary.singleMacServingOffLine } return staleStateFile ? "Daemon: not running (stale state file)" : "Daemon: not running (run `\(BuildEnvironment.current.cliName) start`)" diff --git a/provider-swift/Sources/darkbloom/StatusCommand.swift b/provider-swift/Sources/darkbloom/StatusCommand.swift index 5b8e2751e7..e74b057cec 100644 --- a/provider-swift/Sources/darkbloom/StatusCommand.swift +++ b/provider-swift/Sources/darkbloom/StatusCommand.swift @@ -149,11 +149,13 @@ struct Status: AsyncParsableCommand { let now = Date().timeIntervalSince1970 guard let state = DaemonStateFile.read() else { print(Self.daemonNotRunningLine(paired: pair.paired, unsure: pair.pairingUnreadable)) + if let line = Self.steppedAsideLine(paired: pair.paired) { print(line) } return } let alive = daemonProcessAlive(pid: state.pid) if !alive { print(Self.daemonNotRunningLine(paired: pair.paired, unsure: pair.pairingUnreadable, staleStateFile: true)) + if let line = Self.steppedAsideLine(paired: pair.paired) { print(line) } return } print(daemonHealthLine( diff --git a/provider-swift/Sources/darkbloom/StopCommand.swift b/provider-swift/Sources/darkbloom/StopCommand.swift index 5f187d14d4..4342325ac2 100644 --- a/provider-swift/Sources/darkbloom/StopCommand.swift +++ b/provider-swift/Sources/darkbloom/StopCommand.swift @@ -74,6 +74,8 @@ struct Stop: AsyncParsableCommand { throw ExitCode.failure } } + // Stopping single-Mac serving here: a choice of it made before no longer stands. + if pair.paired { Start.clearSoloChoice() } let wasLoaded = LaunchAgent.isLoaded() if pair.paired, !wasLoaded, !uninstall { if stop != .stopHere { for line in pair.soloStopNothing { print(line) } } diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/SoloStepsStickTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/SoloStepsStickTests.swift new file mode 100644 index 0000000000..50a2f19b1d --- /dev/null +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/SoloStepsStickTests.swift @@ -0,0 +1,69 @@ +import Foundation +import Testing +@testable import ProviderCore + +/// "None of the steps worked" (`solo-steps-failed.md`): single-Mac serving a 0.10.8 updater restarted keeps a started +/// pair down, and the ends it causes set the Darkbloom approval aside for an hour. +@Suite("Single-Mac serving steps aside for a started pair, and its blocked ends don't count", .serialized) +struct SoloStepsStickTests { + private func directory() -> URL { + FileManager.default.temporaryDirectory.appendingPathComponent("solo-choice-\(UUID().uuidString)", isDirectory: true) + } + + @Test("an update, a login or a watchdog revival that restarts unchosen single-Mac serving: it steps aside for the started pair") + func unchosenStepsAside() { + let dir = directory() + defer { try? FileManager.default.removeItem(at: dir) } + // A Mac updated from 0.10.8 has no choice recorded: the started pair, wanting this Mac's part, wins. + #expect(ClusterSoloChoice.chosenAt(in: dir) == nil) + #expect(ClusterSoloChoice.stepsAside(wantedKey: "cluster:84377e741989", chosenAt: ClusterSoloChoice.chosenAt(in: dir))) + #expect(ClusterSoloChoice.stepsAside(wantedKey: "cluster:84377e741989:local-only@127.0.0.1", chosenAt: nil)) + } + + @Test("the person's own choice of single-Mac serving stands until the pair is started or `stop --solo` runs here") + func chosenStays() { + let dir = directory() + defer { try? FileManager.default.removeItem(at: dir) } + ClusterSoloChoice.record(in: dir, now: 1_000) + #expect(ClusterSoloChoice.chosenAt(in: dir) == 1_000) + #expect(!ClusterSoloChoice.stepsAside(wantedKey: "cluster:abc", chosenAt: ClusterSoloChoice.chosenAt(in: dir))) + ClusterSoloChoice.clear(in: dir) + #expect(ClusterSoloChoice.stepsAside(wantedKey: "cluster:abc", chosenAt: ClusterSoloChoice.chosenAt(in: dir))) + } + + @Test("it never fights \"the pair isn't running: serve alone\": no part wanted, or the degraded server, never steps aside") + func neverFightsServingAlone() { + #expect(!ClusterSoloChoice.stepsAside(wantedKey: nil, chosenAt: nil)) + #expect(!ClusterSoloChoice.stepsAside(wantedKey: "solo:EigenLabs/Qwen3.8-27B-4bit-mtp", chosenAt: nil)) + } + + @Test("status says why after a step aside, in the build's own command") + func steppedAsideNote() { + let dir = directory() + defer { try? FileManager.default.removeItem(at: dir) } + ClusterSoloChoice.noteSteppedAside(.init(at: 0, pid: 68099), in: dir) + let note = ClusterSoloChoice.steppedAside(in: dir) + #expect(note == .init(at: 0, pid: 68099)) + let line = ClusterSoloChoice.line(note!, cli: "darkbloom-dev") + #expect(line == "Single-Mac serving stepped aside for the pair at 1970-01-01T00:00:00Z (process 68099): the pair is started " + + "here and nobody chose single-Mac serving since. `darkbloom-dev start --solo` serves this Mac alone again.") + ClusterSoloChoice.record(in: dir) // A new choice clears the note. + #expect(ClusterSoloChoice.steppedAside(in: dir) == nil) + } + + @Test("a part ended by the held lock never counts toward serving locally (old API: the lock's words)") + func lockEndsDoNotCount() { + for words in ["a single-Mac Darkbloom provider (process 68099) is serving on this Mac; `darkbloom stop --solo` stops it", + "another update operation owns the lock (pid 9523, provider-instance)"] { + #expect(ClusterApprovalCheck.memberQuickEnds(after: 2, ranSeconds: 3, lastError: words) == 2, "\(words)") + } + #expect(ClusterApprovalCheck.memberQuickEnds(after: 2, ranSeconds: 3, lastError: "exit 1") == 3, "an ordinary quick end counts") + } + + @Test("an end while either Mac's part is held back doesn't count; once the blocker clears, a failing set-aside goes") + func heldBackAndClear() { + #expect(ClusterApprovalCheck.memberQuickEnds(after: 2, ranSeconds: 3, lastError: "closed", heldBack: true) == 2) + #expect(ClusterApprovalCheck.clearsAfterBlocker(.failing)) + #expect(!ClusterApprovalCheck.clearsAfterBlocker(.withdrawn) && !ClusterApprovalCheck.clearsAfterBlocker(.unreachable)) + } +} From 368c2841d01836efd9429d49adff9ca839fd8b67 Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:59:42 -0800 Subject: [PATCH 08/20] fix(cluster): a version split is named everywhere, ends the wait at once, and single-Mac updates bring the pair along - ClusterOnboardingVersionSplit: both versions, the Mac behind and the build's own command (darkbloom-dev on DevNet). The leader's start reads it before the parts start, every few polls of the wait (before single-Mac serving), and before a Retry; it offers Check the versions again / Leave, never a Retry loop. The joining Mac's wait ends at once on it, from its own side. - The status line both Macs show carries a Mac-neutral reason; darkbloom status / cluster status --json read it as notServing with a final reason, and next names the Mac to update for each window. - The R5-4 member wait line and the leader's same-build wait line name the other Mac's version and the command (asked over the cable, at most every 30 s). - The follow check also follows a partner that is updating to a newer release. The provider's background updater, on a Mac whose pair actually runs there (ClusterService.pairServesHere), asks the cluster service to restart into the release with the other Mac; the watchdog never installs under a running pair. A Mac whose pair is gone simply updates. - Docs (two-mac-cluster.md: pair owners' top line, different versions) and the changelog fragment. Co-Authored-By: Claude Opus 5.5 --- ...ster-pair-version-split-follows-forward.md | 10 +- docs/provider/two-mac-cluster.md | 48 +++++- .../Onboarding/ClusterOnboardingFlow.swift | 134 ++++++++++++++- .../Onboarding/ClusterOnboardingFollow.swift | 18 +- .../ClusterOnboardingLive+VersionSplit.swift | 21 +++ .../Onboarding/ClusterOnboardingLive.swift | 19 ++- .../Onboarding/ClusterService.swift | 30 +++- .../ProviderLoop+AutoUpdate.swift | 16 +- .../ClusterPairUpdate.swift | 11 ++ .../Update/ClusterPairUpdateCycle.swift | 20 ++- .../darkbloom/ClusterPairSummary.swift | 4 + .../Sources/darkbloom/WatchdogCommand.swift | 13 +- .../OnboardingChecks.swift | 2 + .../VersionSplitChecks.swift | 158 ++++++++++++++++++ .../Tests/ClusterOnboardingChecks/run.sh | 3 +- .../PairVersionSplitTests.swift | 75 +++++++++ .../ClusterServiceStopReasonTests.swift | 4 +- .../Update/ClusterPairUpdateTests.swift | 8 + 18 files changed, 566 insertions(+), 28 deletions(-) create mode 100644 provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive+VersionSplit.swift create mode 100644 provider-swift/Tests/ClusterOnboardingChecks/VersionSplitChecks.swift create mode 100644 provider-swift/Tests/DarkbloomCLITests/PairVersionSplitTests.swift diff --git a/changelog.d/cluster-pair-version-split-follows-forward.md b/changelog.d/cluster-pair-version-split-follows-forward.md index 87276f2b33..c288422609 100644 --- a/changelog.d/cluster-pair-version-split-follows-forward.md +++ b/changelog.d/cluster-pair-version-split-follows-forward.md @@ -1,6 +1,6 @@ -### A pair Mac left on an older release catches up with the other Mac within a minute +### Two-Mac pairs: the Macs no longer stay on different versions -- When one Mac of a `darkbloom cluster` pair already runs a newer release (it updated alone, through single-Mac serving, `darkbloom update`, or because this Mac was asleep at the pair's update slot), the other Mac's cluster service notices within a minute and updates right away, instead of waiting for the pair's next update slot. -- With automatic updates off, the cluster service log says which version the other Mac runs and to run `darkbloom update` on this Mac. -- Each newer release triggers one immediate update attempt. If that attempt fails, the Mac tries again at the pair's update slots as before. A release quarantined on this Mac is never installed this way. -- When a pair's start fails because the two Macs run different Darkbloom versions, the error now says so first: "The two Macs run different Darkbloom versions: the other Mac (…) runs 0.10.7, this Mac runs 0.10.8." It then names the Mac to run `darkbloom update` on, instead of guessing at the link. This works with an other Mac on 0.10.7 or later whose cluster service publishes its version. +- **Pair owners, for this update:** run `darkbloom update` on **both** Macs, then check that `darkbloom --version` shows the same version on both. If either Mac ever ran a plain `darkbloom start` before 0.10.8, run `darkbloom stop --solo` on that Mac first. +- When one Mac of a `darkbloom cluster` pair already runs a newer release, or is updating to one, the other Mac's cluster service notices within a minute and updates right away, instead of waiting for the pair's next update slot. This covers a Mac that updated alone (single-Mac serving or `darkbloom update`), or a Mac that was asleep at the slot. Each newer release gets one immediate try; after that the Mac tries again at the update slots as before. A release quarantined on that Mac is never installed this way. With automatic updates off, the log says which version the other Mac runs and to run `darkbloom update` on this Mac. +- The provider's background updater no longer leaves a pair split: when it updates a Mac whose pair runs there, it asks the cluster service to restart into the release together with the other Mac. The watchdog doesn't install a release while the pair runs on that Mac. A Mac that only serves alone, its pair gone, simply updates. +- When the two Macs run different versions, both screens say so at once: "The two Macs run different Darkbloom versions: the other Mac (…) runs 0.10.7, this Mac runs 0.10.8", with the Mac to run `darkbloom update` on. The start no longer loops: it offers to check the versions again, and a Retry checks them first. `darkbloom status`, `darkbloom cluster status --json` (`reason` and `next`) and the cluster service's wait lines also name the other Mac's version and the command. The version split is shown before single-Mac serving when both apply. DevNet builds say `darkbloom-dev`. diff --git a/docs/provider/two-mac-cluster.md b/docs/provider/two-mac-cluster.md index 38226391fc..f96afb7ba5 100644 --- a/docs/provider/two-mac-cluster.md +++ b/docs/provider/two-mac-cluster.md @@ -1,6 +1,6 @@ # Two Macs as one provider (guided setup) -> Last updated: 2026-11-04 +> Last updated: 2026-11-05 Two Apple Silicon Macs joined by one Thunderbolt 5 cable serve a model together: each Mac holds part of its layers, and the pair serves as one provider. Setting @@ -1075,6 +1075,11 @@ happens by itself; `darkbloom cluster` says which applies to each Mac. ## Updating Darkbloom on the pair +**For pair owners:** run `darkbloom update` on **both** Macs, then check that +`darkbloom --version` shows the same version on both. If either Mac ever ran a +plain `darkbloom start` before 0.10.8 (which meant single-Mac serving), run +`darkbloom stop --solo` on that Mac first. + The Macs of a pair update themselves together, as a single Mac does, while `auto_update` is on (the default) and `DARKBLOOM_NO_UPDATE_CHECK` is not set on either Mac. Nothing needs to be run. Every 30 minutes, at the pair's update slot @@ -1132,6 +1137,47 @@ from a plain `darkbloom start` before 0.10.8, which meant single-Mac serving), says so, with `darkbloom stop --solo` to remove it. The watchdog doesn't start it again while the pair is started. +### When the two Macs run different versions + +One Mac can end up on a newer release than the other: it updated alone through +single-Mac serving, `darkbloom update` ran on it only, or the other Mac was +asleep or off at the pair's update slot. Then: + +- **The older Mac catches up within about a minute** (from 0.10.9), once its + cluster service sees the other Mac running a newer release, or updating to + one. It runs the pair's update at once instead of waiting for the slot: one + immediate try per release, then the slots as before. It never installs a + release it quarantined. With automatic updates off, its cluster service log + says "the other Mac runs v, newer than this Mac's v, and + automatic updates are off on this Mac: run `darkbloom update` on this Mac". +- **The provider's own background updater does not leave the pair split.** When + it updates a Mac whose pair actually runs there, it also asks that Mac's + cluster service to restart into the release together with the other Mac, as + `darkbloom update` does, so the other Mac follows. The watchdog doesn't + install a release while the pair runs on that Mac. A Mac that only serves + alone, its pair gone, simply updates. +- **Both screens say it at once:** "✗ The two Macs run different Darkbloom + versions: The other Mac (…) runs 0.10.7, this Mac runs 0.10.8.", then "On , run `darkbloom update`; the pair starts once both Macs run + ." The start doesn't wait or loop. It offers **Check the versions + again** (it reads both versions again, and starts the pair once they match) + or **Leave**. A Retry after any other failure checks the versions first. The + version split is said before single-Mac serving when both apply. +- **`darkbloom status` and `darkbloom cluster status --json`** give the reason + "the two Macs run different Darkbloom versions, and : run + `darkbloom update` on the Mac with ", and as `next` the Mac to update, + named for each Mac: "On this Mac, run `darkbloom update`; …" or "On the other + Mac (…), run `darkbloom update`; …". +- **The wait lines in the cluster service log name the other Mac's version:** + the leader's "Darkbloom changed on …: waiting until both Macs answer with the + same build …" and the other Mac's "waiting for the other Mac's setup for + v …" end with "; the other Mac runs v, this Mac v: + run `darkbloom update` on ". + +The other Mac's version comes from its cluster service, which publishes it from +0.10.7 on. If the other Mac publishes no version, check with `darkbloom --version` +on both Macs. DevNet builds say `darkbloom-dev`. + While a Mac serves, the re-plan uses the speed it measured while idle and never runs a GPU benchmark beside the model ([device profile](../architecture/inference.md#automatic-local-cluster-batching)). diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFlow.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFlow.swift index 2d9a584d7b..123e720a36 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFlow.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFlow.swift @@ -733,9 +733,26 @@ public enum ClusterOnboardingUpdate { } /// The member's log and status line while it waits for the leader's setup after an update. - public static func memberWaitLine(version: String) -> String { + public static func memberWaitLine(version: String, otherVersion: String? = nil) -> String { "this Mac runs Darkbloom v\(version), but its saved setup is for an earlier build: " + "waiting for the other Mac's setup for v\(version) (the old setup is not started)" + + splitClause(thisVersion: version, otherVersion: otherVersion) + } + + /// The control leader's line while the two Macs don't answer with one build: with the other Mac's version, when it + /// runs another, the Mac to update and the command. + public static func leaderWaitLine(macs: String, model: String, thisVersion: String, otherVersion: String?) -> String { + "Darkbloom changed on \(macs): waiting until both Macs answer with the same build to set the cluster up again for \(model)" + + splitClause(thisVersion: thisVersion, otherVersion: otherVersion) + } + + /// "; the other Mac runs v0.10.8, this Mac v0.10.9: run `darkbloom update` on the other Mac", or nothing when one + /// version (or the other Mac's is unknown). + static func splitClause(thisVersion: String, otherVersion: String?) -> String { + guard let split = ClusterOnboardingVersionSplit.detect(thisVersion: thisVersion, otherVersion: otherVersion, + other: ClusterOnboardingMacName.other) else { return "" } + return "; the other Mac runs v\(split.otherVersion), this Mac v\(split.thisVersion): run " + + ClusterOnboardingCommand.named("`darkbloom update`") + " on " + split.olderMac } /// Both Macs' teardown summaries (`ClusterService.teardownLines`, one per Mac) say nothing is left running. @@ -1049,9 +1066,87 @@ public enum ClusterOnboardingSync { } } +/// The two Macs of a pair run different Darkbloom versions (one updated alone): a cause that never clears by itself +/// until the older Mac updates, so the start ends at once with it named, before single-Mac serving or any part end. +/// `other` is the other Mac as the screens name it ("the other Mac (Apple M4 Max, 128 GB)"); commands are named for the +/// running build (`ClusterOnboardingCommand`). +public struct ClusterOnboardingVersionSplit: Sendable, Equatable { + public var thisVersion: String + public var otherVersion: String + public var other: String + + /// A split when both versions are known, numeric, and differ; nil otherwise (one version, or the other Mac's unknown: + /// an older peer without a supervisor publishes none). + public static func detect(thisVersion: String?, otherVersion: String?, other: String) -> ClusterOnboardingVersionSplit? { + guard let thisVersion, let otherVersion, older(thisVersion, otherVersion) != nil else { return nil } + return .init(thisVersion: thisVersion, otherVersion: otherVersion, other: other) + } + + /// Whether `a` is older than `b`; nil when equal or not numeric. + static func older(_ a: String, _ b: String) -> Bool? { + func numbers(_ text: String) -> [Int]? { + let parts = text.trimmingCharacters(in: .whitespaces).split(separator: ".").map { Int($0) } + return parts.isEmpty || parts.contains(nil) ? nil : parts.compactMap { $0 } + } + guard let left = numbers(a), let right = numbers(b) else { return nil } + for index in 0.. String? { + guard reason.contains(reasonMarker), + let colon = reason.range(of: ", ", range: reason.range(of: reasonMarker)!.upperBound.. [ClusterOnboardingSoloServing] = { [] } + /// The two Macs' versions when they differ (this Mac's; the other Mac's status), read before the parts start, during + /// the wait and before a Retry: nil when one version or unknown. Not in `init`: only the live operations set it. + public var versionSplit: @Sendable () -> ClusterOnboardingVersionSplit? = { nil } /// Stops single-Mac serving on each Mac that runs it (`darkbloom stop --solo` there), asked only after the person /// chose it; its lines say what was stopped. Not in `init`: only the live operations set it. public var stopSoloServing: @Sendable () -> Result<[String], ClusterOnboardingFailure> = { @@ -2556,6 +2654,8 @@ public enum ClusterOnboardingDriver { return 1 } } + // Different versions, then single-Mac serving: neither ends by itself, so each is said before anything starts. + guard clearVersionSplit(operations.versionSplit(), operations, console) else { return 1 } // Single-Mac serving on either Mac never ends by itself: said once, before anything starts, never waited for. guard clearSoloServing(operations.soloServing(), operations, console) else { return 1 } switch busy(console, "Starting both Macs", operations.serve) { @@ -2594,6 +2694,8 @@ public enum ClusterOnboardingDriver { case served(title: String, lines: [String], ready: ClusterOnboardingReady), testFailed, notServing([String]), left /// Single-Mac serving blocks the pair (`ClusterOnboardingSoloServing`): no Retry, it never clears by itself. case soloServing([ClusterOnboardingSoloServing]) + /// The two Macs run different versions (`ClusterOnboardingVersionSplit`): no Retry until the older Mac updates. + case versionSplit(ClusterOnboardingVersionSplit) } /// After the start. Serving and Done are said only once the model is loaded on both Macs and a request answered @@ -2628,6 +2730,14 @@ public enum ClusterOnboardingDriver { console.say("") console.say("Setup saved, but the test failed. To test again, run `darkbloom cluster` and choose \(title): it sends one test request.") return 1 + case .versionSplit(let split): + guard clearVersionSplit(split, operations, console), + clearSoloServing(operations.soloServing(), operations, console) else { return 1 } + if case .failure(let failure) = busy(console, "Starting both Macs", operations.serve) { + for line in failure.lines { console.say(" " + line) } + return 1 + } + continue case .soloServing(let serving): guard clearSoloServing(serving, operations, console) else { return 1 } if case .failure(let failure) = busy(console, "Starting both Macs", operations.serve) { @@ -2638,6 +2748,8 @@ public enum ClusterOnboardingDriver { case .notServing(let lines): switch notServing(lines, operations, console) { case .retry: + // The versions first: a Retry of a pair split across versions would only end the same way. + guard clearVersionSplit(operations.versionSplit(), operations, console) else { return 1 } // A pair stopped meanwhile (`cluster stop --service` on a Mac): Retry starts it again and says so, instead // of waiting for parts nothing would start (the pair-2 run, P2-4). if operations.status().first?.hasPrefix("Stopped") == true { @@ -2687,6 +2799,7 @@ public enum ClusterOnboardingDriver { let ready: ClusterOnboardingReady switch waitForParts(title: title, operations, console) { case .success(let value)?: ready = value + case .failure(let failure)? where failure.versionSplit != nil: return .versionSplit(failure.versionSplit!) case .failure(let failure)? where !failure.soloServing.isEmpty: return .soloServing(failure.soloServing) case .failure(let failure)?: return .notServing(failure.lines) case nil: return .left @@ -2727,6 +2840,25 @@ public enum ClusterOnboardingDriver { /// process and what to run there, then the choice to stop it on each Mac named and start the pair, or to leave. /// True when nothing blocks the pair (none ran, or the person chose to stop it and it stopped); false when nothing /// starts, said on the last line. + /// Different versions on the two Macs: the ✗ with the Mac to update and the command, then Check again (the versions + /// are read again; the start goes on once they match) or Leave. True when nothing splits the pair (any more). + static func clearVersionSplit(_ split: ClusterOnboardingVersionSplit?, _ operations: ClusterOnboardingOperations, + _ console: ClusterOnboardingConsole) -> Bool { + guard var split else { return true } + while true { + console.result(false, split.title + ".", split.remedies) + guard console.choose([versionCheckAgainItem, "Leave"], selected: 0) == 0 else { + console.say(versionSplitLeftLine) + return false + } + guard let still = operations.versionSplit() else { return true } + split = still + } + } + + public static let versionCheckAgainItem = "Check the versions again (after `darkbloom update` on the Mac named)" + public static let versionSplitLeftLine = "The pair was not started. Run `darkbloom update` on the Mac named, then `darkbloom cluster` here." + static func clearSoloServing(_ serving: [ClusterOnboardingSoloServing], _ operations: ClusterOnboardingOperations, _ console: ClusterOnboardingConsole) -> Bool { guard !serving.isEmpty else { return true } diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift index 7eee3459fa..2b9ee3fbe4 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift @@ -51,6 +51,11 @@ extension ClusterOnboardingDriver { "If it still doesn't start, run `darkbloom --version` on both Macs; if they differ, run `darkbloom update` on the one that's behind."] } + /// After the version split's ✗ on the Mac that joined. + static func versionSplitAfterLine(_ leader: String?) -> String { + ClusterOnboardingCommand.named("Once both Macs run the same version, run `darkbloom cluster` on \(ClusterOnboardingMacName.other(named: leader)) again; this Mac follows it by itself.") + } + /// After that block: nothing stops here. public static let notStartedAfterLine = "When it starts, this Mac runs its part by itself; run `darkbloom cluster` here to see it." @@ -158,6 +163,8 @@ extension ClusterOnboardingDriver { let timing = operations.followTiming console.say(" " + waitingForStartLine(leader)) let looks = ClusterOnboardingMailbox() + // The two Macs' versions, read with each look: a split never clears by itself, so the wait ends at once on it. + let splits = ClusterOnboardingMailbox() var asking = false, asked = Date.distantPast var begun = Date() var started: Date?, latest: String?, stage = 0, step: ClusterOnboardingLeaderStep?, lastStatus: String? @@ -178,7 +185,16 @@ extension ClusterOnboardingDriver { if !asking, Date().timeIntervalSince(asked) >= timing.pollSeconds { asking = true asked = Date() - Thread.detachNewThread { looks.post(operations.leaderStatus?() ?? .init(lines: operations.status(), step: nil)) } + Thread.detachNewThread { + if let split = operations.versionSplit() { splits.post(split) } + looks.post(operations.leaderStatus?() ?? .init(lines: operations.status(), step: nil)) + } + } + if let split = splits.take().last { + console.settle() + console.result(false, split.title + ".", split.remedies) + console.say(" " + versionSplitAfterLine(leader)) + return 1 } if let look = looks.take().last { asking = false diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive+VersionSplit.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive+VersionSplit.swift new file mode 100644 index 0000000000..f548077e3e --- /dev/null +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive+VersionSplit.swift @@ -0,0 +1,21 @@ +import Foundation + +/// The two Macs of the pair on different Darkbloom versions (`ClusterOnboardingVersionSplit`): read before the parts +/// start, while the start waits (both windows), before a Retry, and for the status line. +extension OnboardingLive { + /// This Mac's version against the other Mac's, which its cluster service publishes (`pairUpdate.running`, from a + /// supervisor of 0.10.7 or later); nil when they match, or the other Mac doesn't answer or say. Answering the other + /// Mac's screen, the split is said from that screen's side. + func versionSplit() -> ClusterOnboardingVersionSplit? { + guard let data = try? command(.init(op: .status), seconds: 10), + let status = try? JSONDecoder().decode(ClusterServiceStatus.self, from: data) else { return nil } + let theirs = status.pairUpdate?.running + // Answering the other Mac's screen, "the other Mac" there is this one (`there` says this Mac then). + if there == ClusterOnboardingMacName.this { + return ClusterOnboardingVersionSplit.detect(thisVersion: theirs, otherVersion: ProviderCore.version, + other: ClusterOnboardingMacName.other) + } + return ClusterOnboardingVersionSplit.detect(thisVersion: ProviderCore.version, otherVersion: theirs, + other: there) + } +} diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift index c2fc30dd65..fb97652044 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift @@ -72,6 +72,7 @@ extension ClusterOnboardingOperations { made.publishStep = { live.publishStep($0) } made.thisVersion = ProviderCore.version made.soloServing = { live.soloServing() } + made.versionSplit = { live.versionSplit() } made.stopSoloServing = { live.stopSoloServing() } made.publishStart = { live.publishStart($0) } made.thisRank = { live.context.savedConfiguration().configuration?.localRank } @@ -1725,7 +1726,11 @@ final class OnboardingLive: @unchecked Sendable { while Date() < deadline { // Single-Mac serving on either Mac never ends by itself: the wait ends at once with it named, never a loop of // part ends (read every few polls: it asks the other Mac over the cable). - if polls % Self.soloServingEveryPolls == 0, let solo = soloServingFailure() { return .failure(solo) } + // Different versions come first: the older Mac must update before anything else can be fixed. + if polls % Self.soloServingEveryPolls == 0 { + if let split = versionSplit() { return .failure(split.failure) } + if let solo = soloServingFailure() { return .failure(solo) } + } polls += 1 var once: (ready: ClusterOnboardingReady?, line: String, parts: [ClusterOnboardingStartProgress.Part]?) if forwards { @@ -1893,11 +1898,9 @@ final class OnboardingLive: @unchecked Sendable { thisVersion: String? = nil, otherVersion: String? = nil) -> [String] { // The Macs run different versions (one updated alone): that is the cause, with the Mac and the command, and no // guess at the link. `otherVersion` is what the other Mac's supervisor publishes (`pairUpdate.running`). - if let thisVersion, let otherVersion, thisVersion != otherVersion, - let behindHere = ClusterOnboardingLeaderStep.isOlder(thisVersion, than: otherVersion) { - let older = behindHere ? "this Mac" : there.prefix(1).lowercased() + there.dropFirst() - return ["The two Macs run different Darkbloom versions: \(there) runs \(otherVersion), this Mac runs \(thisVersion).", - "On \(older), run `darkbloom update`; the pair starts once both Macs run \(behindHere ? otherVersion : thisVersion)."] + if let split = ClusterOnboardingVersionSplit.detect(thisVersion: thisVersion, otherVersion: otherVersion, + other: there.prefix(1).lowercased() + there.dropFirst()) { + return [split.title + "."] + split.remedies } func line(_ mac: String, _ child: ClusterServiceStatus.Child?, unreachable: String? = nil) -> String { if let unreachable { return "\(mac): did not answer over the cable (\(unreachable))." } @@ -2362,6 +2365,10 @@ final class OnboardingLive: @unchecked Sendable { if leadership?.serving != true { lines.append("Stopped\(leadership?.modelName.map { "; last model " + modelTitle($0) } ?? "").") if let scope = leadership?.scope, scope.isLocalOnly { lines.append("When it starts: " + scope.line + ".") } + } else if let split = versionSplit() { + // Different versions never clear by themselves: both windows say it, with the versions and the command. + lines.append(ClusterOnboardingNotServing.statusLine(model: model, reason: split.reason)) + lines += split.remedies } else if let solo = soloServingFailure() { // Single-Mac serving blocks the pair and never ends by itself: both windows say it, naming the Mac and process. lines.append(ClusterOnboardingNotServing.statusLine(model: model, reason: ClusterOnboardingSoloServing.title(solo.soloServing))) diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift index 7fcf2d6d06..f7607ef1a0 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift @@ -113,6 +113,11 @@ public final class ClusterService: @unchecked Sendable { private var updateWaitLine: String? /// The member's line while its saved setup pins an earlier build than it runs (said once per wait). private var memberSetupWaitLine: String? + /// The other Mac's version as its service last published it (`pairUpdate.running`), for the wait lines, and when it + /// may be asked again (`otherMacVersion`). + private var otherVersion: String? + private var otherVersionAsked = Date.distantPast + private var otherVersionAsking = false // The cluster approval is asked for once per run of this service on the control leader, and again every minute // while the pair is offered or serves locally with its approval set aside (`checkApproval`). private var approvalChecked = false @@ -1063,6 +1068,26 @@ public final class ClusterService: @unchecked Sendable { /// adopted, synced to the member and served, as `m` with the same model would, with nobody running a command. /// Checked every `ClusterOnboardingUpdate.checkEverySeconds` on a thread of its own; holds the command lock so a /// person's command and this never run at once. + /// The other Mac's version for the wait lines: asked over the cable at most every 30 s, off the caller's thread unless + /// `refresh` (already a background thread); the last answer meanwhile, nil before the first. + private func otherMacVersion(refresh: Bool = false) -> String? { + let ask: Bool = lock.withLock { + guard !otherVersionAsking, Date().timeIntervalSince(otherVersionAsked) >= 30 else { return false } + otherVersionAsking = true + otherVersionAsked = Date() + return true + } + if ask { + let read: @Sendable () -> Void = { [weak self] in + var version: String? + if case .reported(let progress) = ClusterPairUpdateCycle.livePartner(.init()) { version = progress.running } + self?.lock.withLock { self?.otherVersion = version ?? self?.otherVersion; self?.otherVersionAsking = false } + } + if refresh { read() } else { Thread.detachNewThread(read) } + } + return lock.withLock { otherVersion } + } + private func checkForUpdate(say: @escaping @Sendable (String) -> Void) { guard let leadership = (try? store.readRecord())?.leadership, leadership.serving, let model = leadership.modelName, lock.withLock({ control?.leads == true }) else { return } @@ -1087,7 +1112,8 @@ public final class ClusterService: @unchecked Sendable { let macs = changed.count == 1 && changed[0] == local.id ? "this Mac" : changed.count == 1 ? "the other Mac" : "both Macs" // The two Macs restart into an update seconds apart, or one was updated alone: plan once both run one build. guard ClusterOnboardingUpdate.oneBuild(pinned: pinned, current: current) else { - let line = "Darkbloom changed on \(macs): waiting until both Macs answer with the same build to set the cluster up again for \(model)" + let line = ClusterOnboardingUpdate.leaderWaitLine(macs: macs, model: model, thisVersion: ProviderCore.version, + otherVersion: self.otherMacVersion(refresh: true)) if self.lock.withLock({ self.updateWaitLine != line }) { self.lock.withLock { self.updateWaitLine = line } say(line) @@ -1769,7 +1795,7 @@ public final class ClusterService: @unchecked Sendable { let local = configuration.peers[configuration.localRank] if ClusterOnboardingUpdate.memberWaitsForLeaderSetup(pinned: local.runtimeBinarySHA256, installed: try? context.workerSHA256(local.workerExecutable)) { - let line = ClusterOnboardingUpdate.memberWaitLine(version: ProviderCore.version) + let line = ClusterOnboardingUpdate.memberWaitLine(version: ProviderCore.version, otherVersion: otherMacVersion()) if lock.withLock({ memberSetupWaitLine != line }) { lock.withLock { memberSetupWaitLine = line } say(line) diff --git a/provider-swift/Sources/ProviderCore/ProviderLoop+AutoUpdate.swift b/provider-swift/Sources/ProviderCore/ProviderLoop+AutoUpdate.swift index 35c76ceb09..347814b1a9 100644 --- a/provider-swift/Sources/ProviderCore/ProviderLoop+AutoUpdate.swift +++ b/provider-swift/Sources/ProviderCore/ProviderLoop+AutoUpdate.swift @@ -85,7 +85,8 @@ extension ProviderLoop { coordinatorURL: String, updater injectedUpdater: SelfUpdater? = nil, launchSnapshot: @escaping @Sendable () -> ProviderLaunchSnapshot? = { LaunchAgent.launchSnapshot() }, - restart: @escaping @Sendable () throws -> Void = { try ProcessLifecycle.restartAfterUpdate() } + restart: @escaping @Sendable () throws -> Void = { try ProcessLifecycle.restartAfterUpdate() }, + pairFollows: @escaping @Sendable () -> Bool = { ProviderLoop.askPairToFollowSingleMacUpdate() } ) async -> AutoUpdateController.Outcome { let updater = injectedUpdater ?? SelfUpdater(coordinatorBaseURL: coordinatorURL) let me = self @@ -134,7 +135,11 @@ extension ProviderLoop { return await me.prepareInstalledCandidateRestart( updater: updater, baseline: launchSnapshot) }, - restart: { try await me.restartAfterAutoUpdate(restart) }, + restart: { + // On a Mac whose pair runs here, the pair follows this install instead of staying split. + if pairFollows() { logger.info("Auto-update: this Mac's pair runs here; asked its cluster service to restart into the release with the other Mac") } + try await me.restartAfterAutoUpdate(restart) + }, restartDidFail: { try? updater.cancelPendingCandidateAttempt( operation: "background-restart-failure") @@ -169,6 +174,13 @@ extension ProviderLoop { return outcome } + /// `ClusterPairUpdate.askPairToFollow` with this Mac's actual pair state and its cluster service's request path. + static func askPairToFollowSingleMacUpdate() -> Bool { + guard let directory = try? ClusterService.paths().lock.deletingLastPathComponent() else { return false } + return ClusterPairUpdate.askPairToFollow(pairServes: ClusterService.pairServesHere(), + requestPath: ClusterServiceAgent.updateRequestPath(serviceDirectory: directory), now: Date().timeIntervalSince1970) + } + // MARK: - Auto-Update Phase Transitions /// Atomically claim the update cycle. Returns `false` if a cycle is already diff --git a/provider-swift/Sources/ProviderCore/Service/ClusterSupervision/ClusterPairUpdate.swift b/provider-swift/Sources/ProviderCore/Service/ClusterSupervision/ClusterPairUpdate.swift index 0a2b6aed31..8d1bc42eec 100644 --- a/provider-swift/Sources/ProviderCore/Service/ClusterSupervision/ClusterPairUpdate.swift +++ b/provider-swift/Sources/ProviderCore/Service/ClusterSupervision/ClusterPairUpdate.swift @@ -87,6 +87,17 @@ public enum ClusterPairUpdate { } } + /// A single-Mac updater (the provider's background updater) installed a release on a Mac whose pair runs here + /// (`ClusterService.pairServesHere`, the actual state, not the saved start): this Mac's cluster service supervisor is + /// asked to restart into it together with the other Mac, as `darkbloom update` asks, and the other Mac's follow check + /// sees this Mac updating and follows (`ClusterPairUpdateCycle.ahead`). A Mac whose pair doesn't run here (it serves + /// alone, its pair gone) simply updates. True when asked. + @discardableResult + public static func askPairToFollow(pairServes: Bool, requestPath: URL?, now: Double) -> Bool { + guard pairServes, let requestPath else { return false } + return writeRequest(Request(createdAt: now), to: requestPath) + } + /// `darkbloom update` on a cluster Mac: restart into the release it installed, together with the other Mac. public struct Request: Codable, Equatable, Sendable { public var id: String diff --git a/provider-swift/Sources/ProviderCore/Update/ClusterPairUpdateCycle.swift b/provider-swift/Sources/ProviderCore/Update/ClusterPairUpdateCycle.swift index 038025e7c6..844c59af34 100644 --- a/provider-swift/Sources/ProviderCore/Update/ClusterPairUpdateCycle.swift +++ b/provider-swift/Sources/ProviderCore/Update/ClusterPairUpdateCycle.swift @@ -146,6 +146,16 @@ public final class ClusterPairUpdateCycle: @unchecked Sendable { case followed(AutoUpdateController.Outcome) } + /// The newer release the other Mac runs, or is updating to (a fresh working phase), than `mine`; nil when none. + public static func ahead(of mine: String, partner progress: ClusterPairUpdateProgress, now: Double) -> String? { + guard let running = SemanticVersion(mine) else { return nil } + if let theirs = SemanticVersion(progress.running), running < theirs { return progress.running } + let working: Set = [.checking, .staged, .draining, .drained, .restarting] + guard working.contains(progress.phase), now - progress.writtenAt <= ClusterPairUpdate.progressStaleSeconds, + let target = progress.target, let theirs = SemanticVersion(target), running < theirs else { return nil } + return target + } + /// The other Mac rolled back and quarantined the release this Mac runs (`ClusterPairUpdateProgress.quarantined`), /// and runs the release this Mac keeps for rollback (`plan.to`). public static func follows(_ partner: ClusterPairUpdate.Partner, plan: SelfUpdater.RollbackPlan) -> Bool { @@ -175,11 +185,11 @@ public final class ClusterPairUpdateCycle: @unchecked Sendable { Self.installed(recorded) != mine { return .otherMacStillRuns("the other Mac still runs v\(mine), which is quarantined on this Mac") } - // The other Mac updated alone and runs a newer release: this Mac follows it forward, never into one it quarantined. - if let running = SemanticVersion(Self.installed(recorded) ?? updater.currentVersion), - let theirs = SemanticVersion(progress.running), running < theirs, - recorded?.quarantine?.version != progress.running { - return .otherMacNewer(progress.running) + // The other Mac updated alone and runs a newer release, or is updating to one (a single-Mac updater or + // `darkbloom update` there asked its pair to follow): this Mac follows it forward, never into one it quarantined. + if let ahead = Self.ahead(of: Self.installed(recorded) ?? updater.currentVersion, partner: progress, now: Self.now()), + recorded?.quarantine?.version != ahead { + return .otherMacNewer(ahead) } // A Mac that runs the release it quarantined (installed again with `--override-quarantine`) rolled nothing back. guard let quarantined = progress.quarantined, progress.running != quarantined, diff --git a/provider-swift/Sources/darkbloom/ClusterPairSummary.swift b/provider-swift/Sources/darkbloom/ClusterPairSummary.swift index 4d16ae857a..fec8346b04 100644 --- a/provider-swift/Sources/darkbloom/ClusterPairSummary.swift +++ b/provider-swift/Sources/darkbloom/ClusterPairSummary.swift @@ -407,6 +407,7 @@ extension ClusterPairSummary { guard let reason else { return true } return ClusterOnboardingNotServing.isMissingLogin(reason) || reason.contains("The clock of") || reason.contains("doesn't let") || reason.contains("run different Darkbloom builds") + || reason.contains(ClusterOnboardingVersionSplit.reasonMarker) || ClusterOnboardingReady.isNotOffered(reason) } @@ -453,6 +454,9 @@ extension ClusterPairSummary { case .notServing: if let words = localNetworkWords { return words.next } let reason = reason ?? "" + // Different versions: the Mac to update, named for this window, before anything else. + if let split = ClusterOnboardingVersionSplit.next(reason: reason, thisVersion: ProviderCore.version, + other: otherMac, cli: Self.cli) { return split } if ClusterOnboardingNotServing.isMissingLogin(reason) { return "Run `\(Self.cli) login` on each Mac named, then `\(Self.cli) cluster` on \(leadingMac). Or serve " + "locally only: `\(Self.cli) cluster local` on \(leadingMac)." diff --git a/provider-swift/Sources/darkbloom/WatchdogCommand.swift b/provider-swift/Sources/darkbloom/WatchdogCommand.swift index 7c1b4ed2ea..c0e750c46d 100644 --- a/provider-swift/Sources/darkbloom/WatchdogCommand.swift +++ b/provider-swift/Sources/darkbloom/WatchdogCommand.swift @@ -43,6 +43,13 @@ struct Watchdog: AsyncParsableCommand { !providerActive && !jobIsClusterMember && pairServes } + /// The watchdog installs releases only for single-Mac serving: never for a cluster member's job, and never while the + /// pair actually runs here (`ClusterService.pairServesHere`), whose cluster service updates both Macs together; an + /// install by the watchdog then would leave the pair on two versions. A Mac whose pair is gone simply updates. + static func updates(autoUpdate: Bool, jobIsClusterMember: Bool, pairServes: Bool) -> Bool { + autoUpdate && !jobIsClusterMember && !pairServes + } + static func runTick(configPath: String?) async { let now = Date().timeIntervalSince1970 let tickDeadline = ContinuousClock.now @@ -51,7 +58,9 @@ struct Watchdog: AsyncParsableCommand { // A cluster member's supervisor owns its update (both members drain // and update together at the cluster's slot, S18); a watchdog that // updated one member alone would leave the pair on mixed code. - let autoUpdate = settings.autoUpdate && !LaunchAgent.installedJobIsClusterMember() + let pairServes = ClusterService.pairServesHere() + let autoUpdate = Self.updates(autoUpdate: settings.autoUpdate, jobIsClusterMember: LaunchAgent.installedJobIsClusterMember(), + pairServes: pairServes) let liveness = WatchdogProbe.probeProvider(now: now) let daemonState = DaemonStateFile.read() let providerActive = WatchdogProbe.providerActive( @@ -75,7 +84,7 @@ struct Watchdog: AsyncParsableCommand { // A single-Mac provider job left loaded on a Mac whose pair is started is not revived: it would take the serving // lock the pair's part needs the moment that part lets it go (`ClusterService.pairServesHere`). let pairOwnsServing = Self.pairOwnsServing(providerActive: providerActive, jobIsClusterMember: LaunchAgent.installedJobIsClusterMember(), - pairServes: ClusterService.pairServesHere()) + pairServes: pairServes) let decision = WatchdogPolicy.decide( autoRestartEnabled: settings.autoRestart, providerLoaded: liveness.loaded && !pairOwnsServing, diff --git a/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift b/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift index 346888091a..94e77703c8 100644 --- a/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift +++ b/provider-swift/Tests/ClusterOnboardingChecks/OnboardingChecks.swift @@ -199,6 +199,8 @@ import Darwin followWaitChecks() // A 0.10.8 user's leader screen: its loading line repeated end to end in a narrow window. liveLineChecks() + // 0.10.8, 2026-11-04: one Mac of a pair updated alone; its part ended every 38 s and no screen named the versions. + versionSplitChecks() // 0.10.8, 2026-11-04: single-Mac serving held the provider instance lock on both Macs of a pair; the start looped // "this Mac's part ended (… another update operation owns the lock (pid 9523, provider-instance)) and starts again // by itself", the other Mac read "no error reported", and the guidance was `darkbloom stop`, which stops the pair. diff --git a/provider-swift/Tests/ClusterOnboardingChecks/VersionSplitChecks.swift b/provider-swift/Tests/ClusterOnboardingChecks/VersionSplitChecks.swift new file mode 100644 index 0000000000..c4d8ed0567 --- /dev/null +++ b/provider-swift/Tests/ClusterOnboardingChecks/VersionSplitChecks.swift @@ -0,0 +1,158 @@ +import Foundation +import Darwin + +/// The two Macs of a pair on different Darkbloom versions (account 668cf2b3, 2026-11-04: the M5 Max updated to 0.10.8 +/// alone, its part ended every 38 s and no screen named the versions). The split is said before anything starts, ends +/// the wait at once on both Macs, is re-checked before a start goes on, comes before single-Mac serving, and names the +/// Mac to update with the build's own command. +extension OnboardingChecks { + static func versionSplitChecks() { + aVersionSplitIsWordedForEachMacAndTheStatus() + aVersionSplitIsSaidBeforeAnythingStartsAndCheckedAgain() + aVersionSplitIsLeftWithNothingStarted() + aVersionSplitFoundWhileWaitingIsNeverRetried() + aVersionSplitComesBeforeSingleMacServing() + aVersionSplitNamesTheDevNetCommand() + theJoinedMacEndsItsWaitAtOnceOnAVersionSplit() + theWaitLinesNameTheOtherMacsVersion() + } + + static let m4Max = "the other Mac (Apple M4 Max, 128 GB)" + /// This Mac on 0.10.8, the other Mac still on 0.10.7. + static let splitThere = ClusterOnboardingVersionSplit(thisVersion: "0.10.8", otherVersion: "0.10.7", other: m4Max) + static let splitTitle = "\u{2717} The two Macs run different Darkbloom versions: The other Mac (Apple M4 Max, 128 GB) runs 0.10.7, this Mac runs 0.10.8." + static let splitChoices = " 1) Check the versions again (after `darkbloom update` on the Mac named)\n 2) Leave\n" + + static func aVersionSplitIsWordedForEachMacAndTheStatus() { + typealias V = ClusterOnboardingVersionSplit + expect(V.detect(thisVersion: "0.10.9", otherVersion: "0.10.9", other: m4Max) == nil, "split: one version is none") + expect(V.detect(thisVersion: "0.10.9", otherVersion: nil, other: m4Max) == nil, "split: an unknown version is none") + expect(V.detect(thisVersion: "0.10.9", otherVersion: "dev", other: m4Max) == nil, "split: a non-numeric version is none") + expect(splitThere.remedies == ["On the other Mac (Apple M4 Max, 128 GB), run `darkbloom update`; the pair starts once both Macs run 0.10.8.", + "Check with `darkbloom --version` on both Macs."], "split: the older Mac there: \(splitThere.remedies)") + let here = V(thisVersion: "0.10.8", otherVersion: "0.10.10", other: m4Max) + expect(here.remedies.first == "On this Mac, run `darkbloom update`; the pair starts once both Macs run 0.10.10.", + "split: the older Mac here, compared by number: \(here.remedies)") + expect(splitThere.reason == "the two Macs run different Darkbloom versions, 0.10.8 and 0.10.7: run `darkbloom update` on the Mac with 0.10.7", + "split: the status reason names no Mac by 'this': \(splitThere.reason)") + // `status` on each Mac reads the same reason and names the Mac for its own window. + expect(V.next(reason: splitThere.reason, thisVersion: "0.10.7", other: "the other Mac (Apple M5 Max, 128 GB)", cli: "darkbloom") + == "On this Mac, run `darkbloom update`; then check that `darkbloom --version` shows 0.10.8 on both Macs.", + "split: next on the older Mac") + expect(V.next(reason: splitThere.reason, thisVersion: "0.10.8", other: m4Max, cli: "darkbloom-dev") + == "On the other Mac (Apple M4 Max, 128 GB), run `darkbloom-dev update`; then check that `darkbloom-dev --version` shows 0.10.8 on both Macs.", + "split: next on the newer Mac, with the build's command") + expect(V.next(reason: "the other Mac lacks free memory", thisVersion: "0.10.8", other: m4Max, cli: "darkbloom") == nil, + "split: any other reason has no split next") + } + + /// The leading Mac's start with the other Mac on 0.10.7 until `splitsFor` version reads, then one version. + static func splitOperations(_ recorder: Recorder, splitsFor reads: Int, solo: [ClusterOnboardingSoloServing] = [], + readyResults: [Result]? = nil) -> ClusterOnboardingOperations { + var made = soloOperations(recorder, serving: solo, readyResults: readyResults) + let counted = Recorder() + made.versionSplit = { + recorder.note("versionSplit") + counted.note("read") + return counted.all.count <= reads ? splitThere : nil + } + return made + } + + static func aVersionSplitIsSaidBeforeAnythingStartsAndCheckedAgain() { + let recorder = Recorder() + let run = TerminalRun(splitOperations(recorder, splitsFor: 2)) + expect(run.waitFor(prompt(2)), "split start: choice"); run.type("\r") + expect(run.waitFor(splitChoices), "split start: Check again or Leave: \(run.text)") + expect(!recorder.all.contains("serve"), "split start: nothing started: \(recorder.all)") + run.type("1") + // Still split at the second read: the ✗ again, nothing started. + expect(run.waitFor(splitChoices + "\n") || run.text.components(separatedBy: splitTitle).count >= 3, + "split start: still split, said again: \(run.text)") + expect(!recorder.all.contains("serve"), "split start: still nothing started") + run.type("1") + expect(run.finish() == 0, "split start: served once the versions match: \(run.text)") + expect(run.text.contains(splitTitle + "\n"), "split start: the ✗ names both versions: \(run.text)") + expect(run.text.contains("On the other Mac (Apple M4 Max, 128 GB), run `darkbloom update`; the pair starts once both Macs run 0.10.8."), + "split start: the Mac and the command") + expect(!run.text.contains(notServingChoices) && !run.text.contains("starts again by itself"), "split start: never a Retry loop") + expect(recorder.all.filter { $0 == "versionSplit" }.count >= 3, "split start: re-read before starting: \(recorder.all)") + } + + static func aVersionSplitIsLeftWithNothingStarted() { + let recorder = Recorder() + let run = TerminalRun(splitOperations(recorder, splitsFor: 99)) + expect(run.waitFor(prompt(2)), "split leave: choice"); run.type("\r") + expect(run.waitFor(splitChoices), "split leave: the choices"); run.type("2") + expect(run.finish() == 1, "split leave: exit 1") + expect(run.text.contains("The pair was not started. Run `darkbloom update` on the Mac named, then `darkbloom cluster` here."), + "split leave: the last line: \(run.text)") + expect(!recorder.all.contains("serve") && !recorder.all.contains("waitReady"), "split leave: nothing started: \(recorder.all)") + } + + static func aVersionSplitFoundWhileWaitingIsNeverRetried() { + let recorder = Recorder() + let ready = ClusterOnboardingReady(servedBy: "this Mac", port: 8000, + deployment: "Serving Gemma 4 26B across both Macs: tensor parallel", split: "tensor parallel") + // Found by the wait (the other Mac's part loops on the old setup); the update there lands before Check again. + let run = TerminalRun(splitOperations(recorder, splitsFor: 0, readyResults: [.failure(splitThere.failure), .success(ready)])) + expect(run.waitFor(prompt(2)), "split wait: choice"); run.type("\r") + expect(run.waitFor(splitChoices), "split wait: Check again, not Retry: \(run.text)") + run.type("1") + expect(run.finish() == 0, "split wait: served once the versions match: \(run.text)") + expect(run.text.contains(splitTitle + "\n") && !run.text.contains(notServingChoices), "split wait: the ✗, no Retry: \(run.text)") + expect(recorder.all.filter { $0 == "serve" }.count == 2, "split wait: started again once: \(recorder.all)") + } + + static func aVersionSplitComesBeforeSingleMacServing() { + let recorder = Recorder() + let run = TerminalRun(splitOperations(recorder, splitsFor: 99, solo: [soloBoth[1]])) + expect(run.waitFor(prompt(2)), "split first: choice"); run.type("\r") + expect(run.waitFor(splitChoices), "split first: the split's choices: \(run.text)") + run.type("2") + expect(run.finish() == 1, "split first: exit 1") + expect(run.text.contains(splitTitle) && !run.text.contains("single-Mac Darkbloom provider"), + "split first: the versions, before single-Mac serving: \(run.text)") + } + + static func aVersionSplitNamesTheDevNetCommand() { + ClusterOnboardingCommand.use("darkbloom-dev") + defer { ClusterOnboardingCommand.use("darkbloom") } + let run = TerminalRun(splitOperations(Recorder(), splitsFor: 99)) + expect(run.waitFor(prompt(2)), "split dev: choice"); run.type("\r") + expect(run.waitFor(" 2) Leave\n"), "split dev: the choices"); run.type("2") + expect(run.finish() == 1, "split dev: exit 1") + expect(run.text.contains("run `darkbloom-dev update`") && run.text.contains("`darkbloom-dev --version`") + && !run.text.contains("`darkbloom update`"), "split dev: the DevNet app's command: \(run.text)") + } + + static func theJoinedMacEndsItsWaitAtOnceOnAVersionSplit() { + var made = followingTheM5Max(steps: [nil], thisVersion: "0.10.7") + made.versionSplit = { ClusterOnboardingVersionSplit(thisVersion: "0.10.7", otherVersion: "0.10.8", other: m5MaxNamed) } + let run = TerminalRun(made) + defer { run.release() } + expect(run.waitFor(codeQuestion), "split follow: the code"); run.type("y") + let began = Date() + expect(run.finish() == 1, "split follow: not success") + expect(Date().timeIntervalSince(began) < 5, "split follow: at once, not after the bound") + expect(run.text.contains("\u{2717} The two Macs run different Darkbloom versions: The other Mac (Apple M5 Max, 128 GB) runs 0.10.8, this Mac runs 0.10.7."), + "split follow: the ✗ from this Mac's side: \(run.text)") + expect(run.text.contains("On this Mac, run `darkbloom update`; the pair starts once both Macs run 0.10.8."), "split follow: update here") + expect(run.text.contains("Once both Macs run the same version, run `darkbloom cluster` on the other Mac (Apple M5 Max, 128 GB) again"), + "split follow: what then") + } + + static func theWaitLinesNameTheOtherMacsVersion() { + typealias U = ClusterOnboardingUpdate + expect(U.memberWaitLine(version: "0.10.9", otherVersion: "0.10.8") + == "this Mac runs Darkbloom v0.10.9, but its saved setup is for an earlier build: waiting for the other Mac's setup for v0.10.9 " + + "(the old setup is not started); the other Mac runs v0.10.8, this Mac v0.10.9: run `darkbloom update` on the other Mac", + "wait: the member names the leader's version and the command: \(U.memberWaitLine(version: "0.10.9", otherVersion: "0.10.8"))") + expect(U.memberWaitLine(version: "0.10.9", otherVersion: "0.10.9") == U.memberWaitLine(version: "0.10.9"), + "wait: one version keeps the line") + expect(U.leaderWaitLine(macs: "this Mac", model: "gemma-4-26b", thisVersion: "0.10.9", otherVersion: "0.10.8").hasSuffix( + "for gemma-4-26b; the other Mac runs v0.10.8, this Mac v0.10.9: run `darkbloom update` on the other Mac"), "wait: the leader too") + expect(U.leaderWaitLine(macs: "the other Mac", model: "m", thisVersion: "0.10.8", otherVersion: "0.10.9").hasSuffix( + "run `darkbloom update` on this Mac"), "wait: this Mac behind") + } +} diff --git a/provider-swift/Tests/ClusterOnboardingChecks/run.sh b/provider-swift/Tests/ClusterOnboardingChecks/run.sh index 6df908d781..26d86c5a36 100755 --- a/provider-swift/Tests/ClusterOnboardingChecks/run.sh +++ b/provider-swift/Tests/ClusterOnboardingChecks/run.sh @@ -15,5 +15,6 @@ xcrun swiftc -swift-version 6 -warnings-as-errors -parse-as-library -target "$(u "$task_sources/ClusterOnboardingSoloServing.swift" \ "$task_sources/ClusterOnboardingStartProgress.swift" \ "$task_provider/Tests/ClusterOnboardingChecks/OnboardingChecks.swift" "$task_provider/Tests/ClusterOnboardingChecks/FollowWaitChecks.swift" \ - "$task_provider/Tests/ClusterOnboardingChecks/StartProgressChecks.swift" -o "$task_build/onboarding-checks" + "$task_provider/Tests/ClusterOnboardingChecks/StartProgressChecks.swift" \ + "$task_provider/Tests/ClusterOnboardingChecks/VersionSplitChecks.swift" -o "$task_build/onboarding-checks" "$task_build/onboarding-checks" diff --git a/provider-swift/Tests/DarkbloomCLITests/PairVersionSplitTests.swift b/provider-swift/Tests/DarkbloomCLITests/PairVersionSplitTests.swift new file mode 100644 index 0000000000..5e835abd14 --- /dev/null +++ b/provider-swift/Tests/DarkbloomCLITests/PairVersionSplitTests.swift @@ -0,0 +1,75 @@ +import Foundation +import Testing + +@testable import ProviderCore +@testable import darkbloom + +// 0.10.8, account 668cf2b3 (2026-11-04): the M5 Max updated alone through single-Mac serving and the pair never served; +// no screen or status named the versions. Fixtures only: no pairing, cluster service, launchd or ~/.darkbloom is read. + +private let otherMac = "the other Mac (Apple M4 Max, 128 GB)" +private let cli = ClusterPairSummary.cli + +private func pair(role: ClusterPairSummary.Role) -> ClusterPairSummary { + var pair = ClusterPairSummary(paired: true) + pair.role = role + pair.otherMacName = "Apple M4 Max, 128 GB" + pair.modelID = "gemma-4-26b-qat-4bit" + pair.modelName = "Gemma 4 26B" + pair.started = true + pair.serviceRunning = true + return pair +} + +@Suite("Pair version split") +struct PairVersionSplitTests { + /// The status line both Macs read (the joining Mac shows the leading Mac's): not serving, why, and on each Mac the + /// Mac to update with the build's command; a final reason, so a start's wait ends on it. + @Test(arguments: [true, false]) + func statusNamesTheMacToUpdateOnEachMac(thisMacNewer: Bool) { + let older = "0.0.1", newer = "999.0.0" + let split = ClusterOnboardingVersionSplit(thisVersion: thisMacNewer ? ProviderCore.version : older, + otherVersion: thisMacNewer ? older : newer, other: otherMac) + let line = ClusterOnboardingNotServing.statusLine(model: "Gemma 4 26B", reason: split.reason) + var summary = pair(role: thisMacNewer ? .leader : .member) + summary.read(status: [line] + split.remedies, leaderMode: nil) + #expect(summary.state == .notServing) + #expect(summary.reason?.contains("the two Macs run different Darkbloom versions") == true, "\(summary.reason ?? "")") + #expect(ClusterPairSummary.isFinalReason(summary.reason)) + let expected = thisMacNewer + ? "On the other Mac (Apple M4 Max, 128 GB), run `\(cli) update`; then check that `\(cli) --version` shows \(ProviderCore.version) on both Macs." + : "On the Mac with \(older), run `\(cli) update`; then check that `\(cli) --version` shows \(newer) on both Macs." + #expect(summary.next == expected, "\(summary.next ?? "")") + } + + /// This Mac on the older version reads "On this Mac". + @Test func statusOnTheOlderMacSaysThisMac() { + let split = ClusterOnboardingVersionSplit(thisVersion: "999.0.0", otherVersion: ProviderCore.version, other: otherMac) + var summary = pair(role: .member) + summary.read(status: [ClusterOnboardingNotServing.statusLine(model: "Gemma 4 26B", reason: split.reason)], leaderMode: nil) + #expect(summary.next == "On this Mac, run `\(cli) update`; then check that `\(cli) --version` shows 999.0.0 on both Macs.") + } + + /// The watchdog installs only for single-Mac serving: never for a member's job, never while the pair runs here + /// (actual state); a Mac whose pair is gone simply updates. + @Test func watchdogNeverUpdatesUnderARunningPair() { + #expect(Watchdog.updates(autoUpdate: true, jobIsClusterMember: false, pairServes: false)) + #expect(!Watchdog.updates(autoUpdate: true, jobIsClusterMember: false, pairServes: true)) + #expect(!Watchdog.updates(autoUpdate: true, jobIsClusterMember: true, pairServes: false)) + #expect(!Watchdog.updates(autoUpdate: false, jobIsClusterMember: false, pairServes: false)) + } + + /// The background updater on a Mac whose pair runs here asks its cluster service to restart into the release with the + /// other Mac (`darkbloom update`'s request); a Mac serving alone, its pair gone, asks nothing. + @Test func singleMacUpdateAsksARunningPairToFollow() throws { + let directory = FileManager.default.temporaryDirectory.appendingPathComponent("pair-follow-\(UUID().uuidString)") + try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true) + defer { try? FileManager.default.removeItem(at: directory) } + let path = ClusterServiceAgent.updateRequestPath(serviceDirectory: directory) + let now = Date().timeIntervalSince1970 + #expect(!ClusterPairUpdate.askPairToFollow(pairServes: false, requestPath: path, now: now)) + #expect(!FileManager.default.fileExists(atPath: path.path), "a Mac whose pair is gone simply updates") + #expect(ClusterPairUpdate.askPairToFollow(pairServes: true, requestPath: path, now: now)) + #expect(ClusterPairUpdate.takeRequest(from: path, now: now) != nil, "the supervisor takes it as `darkbloom update`'s") + } +} diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterServiceStopReasonTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterServiceStopReasonTests.swift index bc9694af33..fc36383f82 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterServiceStopReasonTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterServiceStopReasonTests.swift @@ -76,12 +76,12 @@ struct ClusterServiceStopReasonTests { let behindThere = OnboardingLive.errorLines(here: "This Mac", there: there, own: own, other: other, otherUnreachable: nil, thisVersion: "0.10.8", otherVersion: "0.10.7") #expect(behindThere.first == "The two Macs run different Darkbloom versions: The other Mac (Apple M4 Max, 128 GB) runs 0.10.7, this Mac runs 0.10.8.") - #expect(behindThere.dropFirst().first == "On the other Mac (Apple M4 Max, 128 GB), run `darkbloom update`; the pair starts once both Macs run 0.10.8.") + #expect(behindThere.dropFirst().first == "On the other Mac (Apple M4 Max, 128 GB), run `\(ClusterOnboardingCommand.name) update`; the pair starts once both Macs run 0.10.8.") #expect(!behindThere.contains { $0.contains("doesn't report its worker restarting") }, "no guess at the cause: \(behindThere)") let behindHere = OnboardingLive.errorLines(here: "This Mac", there: there, own: own, other: other, otherUnreachable: nil, thisVersion: "0.10.8", otherVersion: "0.10.9") - #expect(behindHere.dropFirst().first == "On this Mac, run `darkbloom update`; the pair starts once both Macs run 0.10.9.") + #expect(behindHere.dropFirst().first == "On this Mac, run `\(ClusterOnboardingCommand.name) update`; the pair starts once both Macs run 0.10.9.") let same = OnboardingLive.errorLines(here: "This Mac", there: there, own: own, other: other, otherUnreachable: nil, thisVersion: "0.10.9", otherVersion: "0.10.9") diff --git a/provider-swift/Tests/ProviderCoreTests/Update/ClusterPairUpdateTests.swift b/provider-swift/Tests/ProviderCoreTests/Update/ClusterPairUpdateTests.swift index f0b9a87d6d..97ec276b55 100644 --- a/provider-swift/Tests/ProviderCoreTests/Update/ClusterPairUpdateTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Update/ClusterPairUpdateTests.swift @@ -576,6 +576,14 @@ struct ClusterPairUpdateTests { let outcome = await behind.cycle(partner: ahead, log: log).followRollback { restarts.record("behind", $0) } #expect(outcome == .nothingToFollow, "the other Mac on v\(running)") } + // The other Mac is updating to a newer release (a single-Mac updater there asked its pair to follow): followed + // while its progress is fresh, not once it went stale. + let now = Date().timeIntervalSince1970 + ClusterPairUpdate.writeProgress(.init(phase: .staged, target: "2.0.0", running: "1.0.0", writtenAt: now), to: ahead.progressPath) + #expect(await behind.cycle(partner: ahead, log: log).followRollback { restarts.record("behind", $0) } == .otherMacNewer("2.0.0")) + ClusterPairUpdate.writeProgress(.init(phase: .staged, target: "2.0.0", running: "1.0.0", + writtenAt: now - ClusterPairUpdate.progressStaleSeconds - 5), to: ahead.progressPath) + #expect(await behind.cycle(partner: ahead, log: log).followRollback { restarts.record("behind", $0) } == .nothingToFollow) publish("2.0.0") let outcome = await behind.cycle(partner: ahead, log: log).followRollback { restarts.record("behind", $0) } #expect(outcome == .otherMacNewer("2.0.0")) From c9c8c5b8290d1c6a1e39ed07ad0f27981eb0eee3 Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Wed, 4 Nov 2026 17:01:40 -0800 Subject: [PATCH 09/20] fix(cluster): a pair the coordinator's catalog won't pair says why DevNet 2026-11-05 (0.10.6-dev.branch.81): a Gemma 4 26B tensor-parallel pair offered under devnet/gemma-4-26b-qat-4bit/s1 sat on "waiting for the coordinator to pair both Macs" (cluster status: loading, exit 3) for 11+ minutes. The coordinator refused it on every one-second pass with `serves_model`: its pair check needs a model-catalog row for each member's model (modelAllowedByCatalogLocked), and DevNet's catalog has no Gemma, though its pair-approval catalog does. The coordinator tells neither Mac. The member registration was not the cause: a member already sends an empty ordinary inventory and exactly its setup's model in cluster_models (ClusterMemberRegistrationTests cover it). - An offered part reads the coordinator's public /v1/models/catalog once after it registers; when the catalog doesn't list its model it writes "Notice: The coordinator does not pair Macs for : its model catalog does not list it" (ClusterLocalServing.catalogRefusal). An unreadable catalog says nothing; the part keeps running. - The service reads that notice as the part's current one; the setup screens on both Macs end at once with it (pairLook, pairServing), and cluster status reports not serving with it instead of loading (ClusterPairSummary.ownState). Tests (red first): ClusterLocalServingTests.aPartOfferedForAModelTheCoordinatorsCatalogDoesNotListSaysSo, ClusterPairCommandsTests.ownState. Co-Authored-By: Claude Opus 5.5 --- changelog.d/gemma-pair-eligibility.md | 4 +++ docs/provider/two-mac-cluster.md | 9 +++++-- .../Installed/ClusterLocalServing.swift | 26 ++++++++++++++++++- .../Onboarding/ClusterOnboardingLive.swift | 12 ++++++--- .../darkbloom/ClusterPairSummary+Live.swift | 2 ++ .../StartCommand+ClusterMember.swift | 20 +++++++++++++- .../ClusterPairCommandsTests.swift | 9 +++++++ .../ClusterLocalServingTests.swift | 23 ++++++++++++++++ 8 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 changelog.d/gemma-pair-eligibility.md diff --git a/changelog.d/gemma-pair-eligibility.md b/changelog.d/gemma-pair-eligibility.md new file mode 100644 index 0000000000..9b9e7720cc --- /dev/null +++ b/changelog.d/gemma-pair-eligibility.md @@ -0,0 +1,4 @@ +### A pair the coordinator won't pair for its model says why + +- A two-Mac pair offered through Darkbloom for a model that the coordinator's model catalog doesn't list waited on "waiting for the coordinator to pair both Macs" until the 15-minute limit, and `darkbloom cluster status` showed `loading` for as long as it ran. The coordinator refuses such a pair on every check (`serves_model`) and tells neither Mac. On DevNet this hit Gemma 4 26B and every other model that has a DevNet pair approval but no DevNet catalog entry. +- Each Mac's part now reads the coordinator's public model catalog once after it registers. If the catalog doesn't list the model, the part says so: "The coordinator does not pair Macs for : its model catalog does not list it". The setup screens on both Macs show that reason at once, and `darkbloom cluster status` and `darkbloom status` report the pair as not serving with that reason instead of `loading`. A catalog that can't be read changes nothing. The part keeps running, so a pair whose model is added to the catalog later still forms. diff --git a/docs/provider/two-mac-cluster.md b/docs/provider/two-mac-cluster.md index 38226391fc..4e18d6bc95 100644 --- a/docs/provider/two-mac-cluster.md +++ b/docs/provider/two-mac-cluster.md @@ -1,6 +1,6 @@ # Two Macs as one provider (guided setup) -> Last updated: 2026-11-04 +> Last updated: 2026-11-05 Two Apple Silicon Macs joined by one Thunderbolt 5 cable serve a model together: each Mac holds part of its layers, and the pair serves as one provider. Setting @@ -141,7 +141,12 @@ follows the start from the cluster's status the two Macs exchange over the cable in `darkbloom cluster` on either Mac) and this Mac keeps following. Offered, it says "Offered to Darkbloom as a pair for ; waiting for Darkbloom to accept this pair…" and waits as the leader does, so both screens end the - same way. Every start the leader's screen makes publishes its test's outcome, + same way. When Darkbloom's model catalog does not list the model, Darkbloom + never pairs the Macs for it; each Mac's part reads the catalog after it + registers, and both screens and `darkbloom cluster status` end with "✗ Not + serving: The coordinator does not pair Macs for : its model catalog + does not list it" (`ClusterLocalServing.catalogRefusal`) instead of waiting. + Every start the leader's screen makes publishes its test's outcome, and this Mac ends with it, without a test of its own: a pass with the leader's response time ("Test response in 0.61 s (the leading Mac's test)"), a failure with the same ✗, reason and note ("Setup saved, but the test failed."; through diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Installed/ClusterLocalServing.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Installed/ClusterLocalServing.swift index 9da3477073..f696473fd4 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Installed/ClusterLocalServing.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Installed/ClusterLocalServing.swift @@ -40,6 +40,30 @@ public enum ClusterLocalServing { /// a control-only member writes. public static var offeredLogLine: String { logPrefix + offeredNotice + " with an installed cluster approval" } + /// What an offered part writes after its registration when the coordinator's model catalog does not list its model. + /// The coordinator's pair check (`serves_model`) needs a catalog row for every member's model, so it refuses such a + /// pair on every pass and tells neither Mac (DevNet Gemma pair, 2026-11-05). + static let catalogRefusalPrefix = "The coordinator does not pair Macs for " + + /// The refusal for `modelID`, nil when `catalogIDs` lists it or is empty (a catalog that wasn't read says nothing). + public static func catalogRefusal(modelID: String, catalogIDs: Set) -> String? { + guard !catalogIDs.isEmpty, !catalogIDs.contains(modelID) else { return nil } + return catalogRefusalPrefix + modelID + ": its model catalog does not list it" + } + + /// `notice` when it is a part's catalog refusal in plain text, else nil. + public static func pairRefusal(notice: String?) -> String? { + guard let notice, notice.hasPrefix(catalogRefusalPrefix), notice.count <= 300, + !notice.unicodeScalars.contains(where: { $0.value < 0x20 || (0x7F...0x9F).contains($0.value) }) + else { return nil } + return notice + } + + /// Whether a part's notice says it registered offered for pairing (refused by the catalog or not). + public static func registeredOffered(notice: String?) -> Bool { + notice == offeredNotice || pairRefusal(notice: notice) != nil + } + /// The leader part's start option that skips the coordinator entirely (`darkbloom start --distributed`). public static let noCoordinatorFlag = "--no-coordinator" @@ -59,7 +83,7 @@ public enum ClusterLocalServing { case logLine: return notice case localOnlyLogLine: return localOnlyNotice case offeredLogLine: return offeredNotice - default: return nil + case let line: return pairRefusal(notice: String(line.dropFirst(logPrefix.count))) } } diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift index a0dade7954..6a8f4af865 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingLive.swift @@ -2150,7 +2150,7 @@ final class OnboardingLive: @unchecked Sendable { func offeredReadiness(_ offered: String, own: ClusterServiceStatus.Child?) -> (ready: ClusterOnboardingReady?, line: String) { let peer = (try? JSONDecoder().decode(ClusterServiceStatus.self, from: command(.init(op: .status), seconds: 10)))?.child func registered(_ child: ClusterServiceStatus.Child?) -> Bool { - child?.running == true && child?.notice == ClusterLocalServing.offeredNotice + child?.running == true && ClusterLocalServing.registeredOffered(notice: child?.notice) } if registered(own), registered(peer) { return (.init(servedBy: here, port: 0, deployment: savedDeployment(perspective: true) ?? leadership?.deployment, @@ -2182,7 +2182,9 @@ final class OnboardingLive: @unchecked Sendable { if look.serving { return .success([look.test ?? ""]) } if let reason = look.reason { last = reason - let settle = ClusterOnboardingNotServing.isMissingLogin(reason) ? 0 : Self.pairReasonSettleSeconds + // A login missing, or a model the coordinator's catalog does not list, holds until a person acts. + let settle = ClusterOnboardingNotServing.isMissingLogin(reason) || ClusterLocalServing.pairRefusal(notice: reason) != nil + ? 0 : Self.pairReasonSettleSeconds if Date().timeIntervalSince(started) >= settle { return .failure(.init(reason)) } } if look.progress != said { progress(look.progress); said = look.progress } @@ -2204,7 +2206,7 @@ final class OnboardingLive: @unchecked Sendable { // The wait, then one row per Mac (`ClusterOnboardingLoadRows`): registered, then loading once the coordinator // committed the start (rank 0's part says so for both). func row(_ mac: String, _ child: ClusterServiceStatus.Child?) -> String { - let registered = child?.running == true && child?.notice == ClusterLocalServing.offeredNotice + let registered = child?.running == true && ClusterLocalServing.registeredOffered(notice: child?.notice) let state = rankZero == .starting ? "loading its share" : registered ? "registered; waiting for the coordinator" : "registering with the coordinator" return ClusterOnboardingMacName.sentence(mac) + ": " + state @@ -2221,6 +2223,10 @@ final class OnboardingLive: @unchecked Sendable { if case .stopped(let why)? = rankZero { return (false, nil, progress, ClusterOnboardingNotServing.words(reason: why, mac: "one of the Macs")) } + // The coordinator refuses every pair for a model its catalog does not list, and tells neither Mac. + for child in [own?.child, peer?.child] { + if let refusal = ClusterLocalServing.pairRefusal(notice: child?.notice) { return (false, nil, progress, refusal) } + } return (false, nil, progress, nil) } diff --git a/provider-swift/Sources/darkbloom/ClusterPairSummary+Live.swift b/provider-swift/Sources/darkbloom/ClusterPairSummary+Live.swift index 6019c7a083..ab414207cd 100644 --- a/provider-swift/Sources/darkbloom/ClusterPairSummary+Live.swift +++ b/provider-swift/Sources/darkbloom/ClusterPairSummary+Live.swift @@ -175,6 +175,8 @@ extension ClusterPairSummary { case .stopped(let why): return (.notServing, ClusterOnboardingNotServing.words(reason: why, mac: "one of the Macs")) } } + // A part offered for a model the coordinator's catalog does not list: the coordinator never pairs it. + if let refusal = ClusterLocalServing.pairRefusal(notice: own?.child.notice) { return (.notServing, refusal) } // A part registered with the coordinator as a pair member, before its pair line: the coordinator may still pair it. if own?.child.notice == ClusterLocalServing.offeredNotice { return (.loading, nil) } if let session = own?.session, session.observed { diff --git a/provider-swift/Sources/darkbloom/StartCommand+ClusterMember.swift b/provider-swift/Sources/darkbloom/StartCommand+ClusterMember.swift index d3e1ed8faf..3d55dc3ce4 100644 --- a/provider-swift/Sources/darkbloom/StartCommand+ClusterMember.swift +++ b/provider-swift/Sources/darkbloom/StartCommand+ClusterMember.swift @@ -118,7 +118,11 @@ extension Start { try await loop.waitForClusterMemberRegistration(until: .now.advanced(by: wait)) print("darkbloom \(ProviderCore.version) (registered cluster member; solo inference disabled)") // The cluster service reads its part's latest notice line (unbuffered stderr): this part is offered. - if offered { printError(ClusterLocalServing.offeredLogLine) } + if offered { + printError(ClusterLocalServing.offeredLogLine) + let url = coordinatorURL ?? (try? ConfigManager.load(from: path))?.coordinator.url + if let url { Self.sayCatalogRefusal(modelID: prepared.model.id, coordinatorURL: url) } + } try await withTaskCancellationHandler { try await task.value } onCancel: { task.cancel() } } catch { @@ -131,6 +135,20 @@ extension Start { } } + /// Reads the coordinator's public model catalog once, without holding up the part, and writes the refusal notice + /// when it does not list `modelID` (`ClusterLocalServing.catalogRefusal`). A catalog that can't be read says nothing. + static func sayCatalogRefusal(modelID: String, coordinatorURL: String) { + Task.detached { + let configuration = URLSessionConfiguration.ephemeral + configuration.timeoutIntervalForRequest = 20 + let client = ModelCatalogClient(coordinatorURL: coordinatorURL, urlSession: URLSession(configuration: configuration)) + guard let catalog = try? await client.fetchCatalog(), + let refusal = ClusterLocalServing.catalogRefusal(modelID: modelID, catalogIDs: Set(catalog.map(\.id))) + else { return } + printError(ClusterLocalServing.logPrefix + refusal) + } + } + /// The orphan sweep at a member's start and end. Its outcome is one log /// line when it found something; a sweep that cannot run (no home) is /// noted and never fails the member. diff --git a/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift b/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift index 6510cf537a..e64926b07f 100644 --- a/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift +++ b/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift @@ -175,6 +175,15 @@ struct ClusterPairHabitCommandsTests { #expect(ClusterPairSummary.ownState(started: true, own: own) == (.serving, nil)) own.child.pair = "starting" #expect(ClusterPairSummary.ownState(started: true, own: own) == (.loading, nil)) + // A part the coordinator will not pair (its catalog lacks the model): not serving, with the reason, instead of + // "waiting for the coordinator" (DevNet Gemma pair, 2026-11-05). + let refusal = ClusterLocalServing.catalogRefusal(modelID: "gemma-4-26b-qat-4bit", catalogIDs: ["glm-5.3-flash"])! + var refused = own + refused.child.pair = nil + refused.child.notice = refusal + #expect(ClusterPairSummary.ownState(started: true, own: refused) == (.notServing, refusal)) + refused.child.notice = ClusterLocalServing.offeredNotice + #expect(ClusterPairSummary.ownState(started: true, own: refused) == (.loading, nil)) own.control = .init(leaderID: "a", leaderName: "Apple M3 Ultra, 256 GB", term: 1, reason: "", leads: true, line: "The other Mac (Apple M5 Max, 128 GB) is gone; …", mode: "waiting") #expect(ClusterPairSummary.ownState(started: true, own: own) == (.otherMacAway, "The other Mac (Apple M5 Max, 128 GB) is gone; …")) diff --git a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterLocalServingTests.swift b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterLocalServingTests.swift index ee855b107a..0d8a4711c7 100644 --- a/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterLocalServingTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Inference/Distributed/ClusterLocalServingTests.swift @@ -34,6 +34,29 @@ struct ClusterLocalServingTests { #expect(ClusterLocalServing.notice(inLog: "Error: The coordinator could not be reached\n") == nil) } + /// DevNet 2026-11-05 (0.10.6-dev.branch.81): a Gemma pair offered under `devnet/gemma-4-26b-qat-4bit/s1` waited + /// 11 minutes on "waiting for the coordinator to pair both Macs". The coordinator refused it on every pass + /// (`serves_model`): its model catalog had no row for the model. A part offered for a model the catalog does not + /// list says so, and that notice replaces the offered one as the current run's. + @Test func aPartOfferedForAModelTheCoordinatorsCatalogDoesNotListSaysSo() { + let model = "gemma-4-26b-qat-4bit" + #expect(ClusterLocalServing.catalogRefusal(modelID: model, catalogIDs: ["Qwen3.5-9B", "glm-5.3-flash"]) + == "The coordinator does not pair Macs for gemma-4-26b-qat-4bit: its model catalog does not list it") + #expect(ClusterLocalServing.catalogRefusal(modelID: model, catalogIDs: [model, "glm-5.3-flash"]) == nil) + // An unread catalog is no evidence: nothing is said. + #expect(ClusterLocalServing.catalogRefusal(modelID: model, catalogIDs: []) == nil) + let refusal = ClusterLocalServing.catalogRefusal(modelID: model, catalogIDs: ["glm-5.3-flash"])! + let log = "\(ClusterLocalServing.offeredLogLine)\n\(ClusterLocalServing.logPrefix)\(refusal)\n" + #expect(ClusterLocalServing.notice(inLog: log) == refusal) + #expect(ClusterLocalServing.pairRefusal(notice: refusal) == refusal) + #expect(ClusterLocalServing.pairRefusal(notice: ClusterLocalServing.offeredNotice) == nil) + #expect(ClusterLocalServing.pairRefusal(notice: nil) == nil) + // A later run that registered without the refusal reads as offered again. + #expect(ClusterLocalServing.notice(inLog: log + ClusterLocalServing.offeredLogLine + "\n") == ClusterLocalServing.offeredNotice) + // Only the part's own wording is taken from its log. + #expect(ClusterLocalServing.notice(inLog: "\(ClusterLocalServing.logPrefix)The coordinator does not pair Macs for \u{1B}[2J: x\n") == nil) + } + @Test func theReadyScreenAddsTheNoticeAfterTheAPILine() { let ready = ClusterOnboardingReady(servedBy: "this Mac", port: 8000, deployment: "Serving M across both Macs: pipeline", notice: ClusterLocalServing.notice) From f25d2e39e800469270adaf4df658baab6c9e63f8 Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Wed, 4 Nov 2026 17:01:58 -0800 Subject: [PATCH 10/20] fix(cluster): `stop --solo` on the wrong Mac stops it on the other Mac; a blocked pair's `start` never serves alone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `stop --solo` where nothing runs here asks the other Mac (its status) and, with consent or `--yes`, stops single-Mac serving there (`.stopSolo`); declined, it says where to run it and exits 1. Its "nothing to stop" line no longer suggests plain `stop` (solo-steps-failed.md §3.3). - #1793 coordination: while single-Mac serving blocks a started pair whose other Mac answers, `start` goes to the pair (`.openScreen` / `.startPair`), never `.choose` or serve-alone (pinned by a test); "set up" means the job is loaded (`LaunchAgent.singleMacSetUp`), not that the plist exists. Co-Authored-By: Claude Opus 5.5 --- .../cluster-solo-stop-on-the-right-mac.md | 5 ++ .../Onboarding/ClusterService.swift | 3 +- .../ProviderCore/Service/LaunchAgent.swift | 4 ++ .../darkbloom/ClusterPairCommands.swift | 10 +++- .../darkbloom/ClusterPairSummary.swift | 4 +- .../darkbloom/Start/StartCommand.swift | 13 ++++- .../Sources/darkbloom/StopCommand.swift | 38 +++++++++++++++ .../ClusterPairCommandsTests.swift | 48 ++++++++++++++++++- 8 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 changelog.d/cluster-solo-stop-on-the-right-mac.md diff --git a/changelog.d/cluster-solo-stop-on-the-right-mac.md b/changelog.d/cluster-solo-stop-on-the-right-mac.md new file mode 100644 index 0000000000..da5deae4a9 --- /dev/null +++ b/changelog.d/cluster-solo-stop-on-the-right-mac.md @@ -0,0 +1,5 @@ +### `stop --solo` on the wrong Mac finds the right one + +- If `darkbloom stop --solo` finds no single-Mac serving on this Mac but finds it on the other Mac of the pair, it names that Mac and its process and offers to stop it there. `--yes` stops it without asking, for scripts. It no longer points to plain `darkbloom stop`, which stops the pair and leaves single-Mac serving running. +- While single-Mac serving blocks a started pair whose other Mac answers, `darkbloom start` starts the pair (in a terminal, the screen that offers to stop it). It no longer offers "Serve on this Mac alone", which would recreate the block. +- "Single-Mac serving is set up" now means its job is loaded, not that its file exists. After `stop --solo`, a pair whose other Mac goes quiet no longer gives up its part for single-Mac serving that can't come back. diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift index 85a9178b2e..41d29cf307 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterService.swift @@ -1680,7 +1680,8 @@ public final class ClusterService: @unchecked Sendable { if previous.givesUpPart, verdict.running { say("the other Mac answers again: this Mac's part may start again") } return want } - let singleMacJob = LaunchAgent.isInstalled() && !LaunchAgent.installedJobIsClusterMember() + // Set up means loaded (an enabled job): the plist outlives `stop --solo`, which disables and unloads it. + let singleMacJob = LaunchAgent.singleMacSetUp() let part = ClusterPairWatch.part(want, verdict: verdict, localOnly: scope.isLocalOnly, singleMacJob: singleMacJob) if part != want, !previous.givesUpPart, let line = ClusterPairWatch.line(verdict, otherMac: lock.withLock { otherMacNameLocked() }, cli: BuildEnvironment.current.cliName) { diff --git a/provider-swift/Sources/ProviderCore/Service/LaunchAgent.swift b/provider-swift/Sources/ProviderCore/Service/LaunchAgent.swift index 5800d24bf8..e1164f5ef8 100644 --- a/provider-swift/Sources/ProviderCore/Service/LaunchAgent.swift +++ b/provider-swift/Sources/ProviderCore/Service/LaunchAgent.swift @@ -42,6 +42,10 @@ public enum LaunchAgent: Sendable { isLoaded(label: label) } + /// Single-Mac serving is set up on this Mac: its job is loaded (`stop` disables and unloads it; the plist stays on + /// disk for `restart`), and it isn't a cluster member's job. + public static func singleMacSetUp() -> Bool { isLoaded() && !installedJobIsClusterMember() } + private static func isLoaded(label: String) -> Bool { LaunchctlControl.printSucceeds(label: label) } diff --git a/provider-swift/Sources/darkbloom/ClusterPairCommands.swift b/provider-swift/Sources/darkbloom/ClusterPairCommands.swift index baac62ace6..0c57fdc31c 100644 --- a/provider-swift/Sources/darkbloom/ClusterPairCommands.swift +++ b/provider-swift/Sources/darkbloom/ClusterPairCommands.swift @@ -10,6 +10,9 @@ struct ClusterPairActions: Sendable { var serve: @Sendable () -> Result<[String], ClusterOnboardingFailure> var stop: @Sendable () -> Result<[String], ClusterOnboardingFailure> var verifyTeardown: @Sendable () -> Result<[String], ClusterOnboardingFailure> + /// Single-Mac serving on either Mac, and its stop with consent (`stop --solo` on the wrong Mac). + var soloServing: @Sendable () -> [ClusterOnboardingSoloServing] = { [] } + var stopSoloServing: @Sendable () -> Result<[String], ClusterOnboardingFailure> = { .failure(.init("not available")) } /// Tests give the commands actions of their own. @TaskLocal static var forTesting: ClusterPairActions? @@ -20,8 +23,11 @@ struct ClusterPairActions: Sendable { if let actions = forTesting { return actions } guard ClusterPairSummary.readsThisMacsCluster, let operations = try? ClusterOnboardingOperations.live(.clusterService(config: config, worker: worker)) else { return nil } - return ClusterPairActions(resume: operations.resume, ensureService: operations.ensureService, serve: operations.serve, - stop: operations.stop, verifyTeardown: operations.verifyTeardown) + var actions = ClusterPairActions(resume: operations.resume, ensureService: operations.ensureService, serve: operations.serve, + stop: operations.stop, verifyTeardown: operations.verifyTeardown) + actions.soloServing = operations.soloServing + actions.stopSoloServing = operations.stopSoloServing + return actions } } diff --git a/provider-swift/Sources/darkbloom/ClusterPairSummary.swift b/provider-swift/Sources/darkbloom/ClusterPairSummary.swift index 6cd59ec596..857bed5a99 100644 --- a/provider-swift/Sources/darkbloom/ClusterPairSummary.swift +++ b/provider-swift/Sources/darkbloom/ClusterPairSummary.swift @@ -298,7 +298,9 @@ struct ClusterPairSummary: Sendable, Equatable { /// `darkbloom stop --solo` where no single-Mac serving runs on a Mac in a cluster. var soloStopNothing: [String] { - ["`\(Self.cli) stop --solo` stops single-Mac serving, and none runs on this Mac: nothing was stopped.", soloLeftPair("stop")] + ["`\(Self.cli) stop --solo` stops single-Mac serving, and none runs on this Mac: nothing was stopped.", + pairingUnreadable ? Self.checkPairingLine + : "The pair keeps running. If single-Mac serving blocks it, it runs on \(otherMac): run `\(Self.cli) stop --solo` there."] } /// After `darkbloom stop --solo` (or `--uninstall`) stopped single-Mac serving on a Mac in a cluster. diff --git a/provider-swift/Sources/darkbloom/Start/StartCommand.swift b/provider-swift/Sources/darkbloom/Start/StartCommand.swift index 7e1113cc2f..880935cc2a 100644 --- a/provider-swift/Sources/darkbloom/Start/StartCommand.swift +++ b/provider-swift/Sources/darkbloom/Start/StartCommand.swift @@ -174,9 +174,12 @@ struct Start: AsyncParsableCommand { } static func pairStart(_ pair: ClusterPairSummary, solo: Bool, terminal: Bool, - singleMacOptions: [String] = []) -> PairStart { + singleMacOptions: [String] = [], soloBlocked: Bool = false) -> PairStart { guard pair.paired else { return .single(note: nil) } if pair.pairingUnreadable { return solo ? .single(note: pair.startNote) : .refuse(pair.startRefusal) } + // Single-Mac serving blocks a started pair whose other Mac answers: `start` (the ✗'s "Then run `darkbloom start`") + // starts the pair, whose screen offers to stop it; never "Serve on this Mac alone", which would recreate the block. + if soloBlocked, !solo, singleMacOptions.isEmpty, pair.started, pair.otherMacReachable { return terminal ? .openScreen : .startPair } // The pair doesn't run here (stopped, or left from a pair whose other Mac stopped taking part): the way back to // single-Mac serving is never refused. A person at a terminal chooses; everything else serves this Mac alone, // unless the other Mac answers: a pair that hasn't served yet may still be loading, so only --solo stops it then. @@ -198,6 +201,12 @@ struct Start: AsyncParsableCommand { /// How long the leftover part gets to release its model and the serving lock. static let releaseSeconds: Double = 300 + /// Single-Mac serving blocks the pair: on this Mac (its serving lock), or as the pair's status says. + static func soloBlocksPair(_ pair: ClusterPairSummary) -> Bool { + guard pair.paired, ClusterPairSummary.readsThisMacsCluster else { return false } + return ProviderInstanceHolder.singleMacServing() != nil || pair.reason.map(ClusterOnboardingSoloServing.isBlock) == true + } + /// The person chose single-Mac serving on this paired Mac (`ClusterSoloChoice`): it doesn't step aside for the pair. static func recordSoloChoice() { guard ClusterPairSummary.readsThisMacsCluster, let directory = ClusterService.soloChoiceDirectory() else { return } @@ -259,7 +268,7 @@ struct Start: AsyncParsableCommand { if startsSingleMacServing, !ClusterPairSummary.startedByClusterService() { let pair = ClusterPairSummary.local() let pairStart = Self.pairStart(pair, solo: solo, terminal: ClusterPairCommands.isTerminal(), - singleMacOptions: singleMacOptions) + singleMacOptions: singleMacOptions, soloBlocked: Self.soloBlocksPair(pair)) // Only single-Mac serving opens with the mark here: a refusal starts nothing, and the cluster's screen // draws the mark itself. var choice = pairStart diff --git a/provider-swift/Sources/darkbloom/StopCommand.swift b/provider-swift/Sources/darkbloom/StopCommand.swift index 4342325ac2..8e598cc710 100644 --- a/provider-swift/Sources/darkbloom/StopCommand.swift +++ b/provider-swift/Sources/darkbloom/StopCommand.swift @@ -18,6 +18,43 @@ struct Stop: AsyncParsableCommand { @Flag(help: "On a Mac in a two-Mac cluster: stop single-Mac serving on this Mac only; the pair keeps running.") var solo = false + @Flag(help: "With --solo, when single-Mac serving runs on the other Mac instead: stop it there without asking.") + var yes = false + + /// The other Mac's single-Mac serving, when `stop --solo` finds none here. + static func otherMacSolo(_ found: [ClusterOnboardingSoloServing]) -> ClusterOnboardingSoloServing? { + found.first { $0.mac != ClusterOnboardingMacName.this } + } + + static func otherMacLines(_ solo: ClusterOnboardingSoloServing, cli: String) -> [String] { + ["Single-Mac serving doesn't run on this Mac; it runs on \(solo.mac)" + (solo.pid.map { " (process \($0))" } ?? "") + ".", + "Stop it there? `\(cli) stop --solo --yes` does it without asking."] + } + + static func otherMacDeclined(_ solo: ClusterOnboardingSoloServing, cli: String) -> String { + "Nothing was stopped. On \(solo.mac), run `\(cli) stop --solo`." + } + + /// `stop --solo` where none runs here: single-Mac serving on the other Mac is named and stopped there with consent + /// (`--yes` for scripts). True when it handled the stop (stopped there); throws when declined or it failed. + private func stopOnOtherMac() throws -> Bool { + guard solo, let actions = ClusterPairActions.live(config: nil), + let there = Self.otherMacSolo(actions.soloServing()) else { return false } + let cli = BuildEnvironment.current.cliName + let lines = Self.otherMacLines(there, cli: cli) + print(lines[0]) + var go = yes + if !go, ClusterPairCommands.isTerminal() { + print(lines[1] + " [y/N]: ", terminator: ""); fflush(stdout) + go = (readLine() ?? "").trimmingCharacters(in: .whitespaces).lowercased().hasPrefix("y") + } + guard go else { print(Self.otherMacDeclined(there, cli: cli)); throw ExitCode.failure } + switch actions.stopSoloServing() { + case .success(let said): for line in said { print(line) }; return true + case .failure(let failure): for line in failure.lines { print(line) }; throw ExitCode.failure + } + } + /// What `darkbloom stop` does on a Mac in a two-Mac cluster. enum PairedStop: Equatable { /// Stop the pair on both Macs (`ClusterPairCommands.stop`). @@ -78,6 +115,7 @@ struct Stop: AsyncParsableCommand { if pair.paired { Start.clearSoloChoice() } let wasLoaded = LaunchAgent.isLoaded() if pair.paired, !wasLoaded, !uninstall { + if stop == .stopSingleMac, !pair.pairingUnreadable, try stopOnOtherMac() { return } if stop != .stopHere { for line in pair.soloStopNothing { print(line) } } else if !pair.started { print("Nothing serves on this Mac: nothing was stopped.") } return diff --git a/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift b/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift index 18e22657b4..5c243d3a1a 100644 --- a/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift +++ b/provider-swift/Tests/DarkbloomCLITests/ClusterPairCommandsTests.swift @@ -88,10 +88,21 @@ struct ClusterPairHabitCommandsTests { #expect(Stop.pairedStop(pair(), solo: true, uninstall: false) == .stopSingleMac) #expect(Stop.pairedStop(pair(), solo: false, uninstall: true) == .stopSingleMac) #expect(Stop.pairedStop(.notPaired, solo: false, uninstall: false) == .stopSingleMac) + // Never plain `stop` here (solo-steps-failed.md §3.3: it stops the pair and leaves single-Mac serving running). #expect(pair().soloStopNothing == [ "`darkbloom stop --solo` stops single-Mac serving, and none runs on this Mac: nothing was stopped.", - "The pair was not stopped; `darkbloom stop` stops both Macs.", + "The pair keeps running. If single-Mac serving blocks it, it runs on \(otherMac): run `darkbloom stop --solo` there.", + ]) + let found = [ClusterOnboardingSoloServing(mac: "this Mac", pid: nil), + ClusterOnboardingSoloServing(mac: "the other Mac (Apple M5 Max, 128 GB)", pid: 68099)] + #expect(Stop.otherMacSolo(found) == found[1]) + #expect(Stop.otherMacSolo([found[0]]) == nil) + #expect(Stop.otherMacLines(found[1], cli: "darkbloom-dev") == [ + "Single-Mac serving doesn't run on this Mac; it runs on the other Mac (Apple M5 Max, 128 GB) (process 68099).", + "Stop it there? `darkbloom-dev stop --solo --yes` does it without asking.", ]) + #expect(Stop.otherMacDeclined(found[1], cli: "darkbloom-dev") + == "Nothing was stopped. On the other Mac (Apple M5 Max, 128 GB), run `darkbloom-dev stop --solo`.") #expect(pair().stopAddendum == [ "This Mac serves in a two-Mac cluster with \(otherMac): it leads; Qwen 3.8 27B through Darkbloom.", "The pair was not stopped; `darkbloom stop` stops both Macs.", @@ -110,6 +121,20 @@ struct ClusterPairHabitCommandsTests { @Test("start on a Mac in a cluster starts the pair: the cluster's screen in a terminal, the saved model otherwise") func startDecision() throws { #expect(Start.pairStart(pair(), solo: false, terminal: true) == .openScreen) + // The single-Mac ✗'s "Then run `darkbloom start`" on a started pair that doesn't run (#1793's `pairRunning` false) + // while single-Mac serving blocks it: the pair's start, never "Serve on this Mac alone" (it would recreate the block). + var blocked = pair() + blocked.pairRunning = false + blocked.otherMacReachable = true + for terminal in [true, false] { + let start = Start.pairStart(blocked, solo: false, terminal: terminal, soloBlocked: true) + #expect(start == (terminal ? .openScreen : .startPair), "terminal \(terminal): \(start)") + } + #expect(Start.pairStart(blocked, solo: false, terminal: true) == .choose(aloneByDefault: false), "unblocked: #1793's choice") + var silent = blocked + silent.otherMacReachable = false + #expect(Start.pairStart(silent, solo: false, terminal: false, soloBlocked: true) == .serveAlone(note: silent.servingAloneLine), + "the other Mac gone: #1793's serve alone stays") #expect(Start.pairStart(pair(role: .member), solo: false, terminal: false) == .startPair) // A stopped pair doesn't run here: a script serves this Mac alone (`UnpairedMacServesNormallyTests`). #expect(Start.pairStart(pair(role: .member, started: false, serviceRunning: false), solo: false, terminal: false) @@ -768,11 +793,30 @@ struct ClusterPairControlTests { } #expect(lines(result?.standardOutputContent) == [ "`darkbloom stop --solo` stops single-Mac serving, and none runs on this Mac: nothing was stopped.", - "The pair was not stopped; `darkbloom stop` stops both Macs.", ""]) + "The pair keeps running. If single-Mac serving blocks it, it runs on \(otherMac): run `darkbloom stop --solo` there.", ""]) let calls = pairActionCalls(text(result?.standardErrorContent)) #expect(calls.isEmpty, "\(calls)") } + /// solo-steps-failed.md §3.3: `stop --solo` run on the wrong Mac finds single-Mac serving on the other Mac and stops it + /// there with consent (`--yes` here); never plain `stop`, and the pair isn't touched. + @Test("`darkbloom stop --solo --yes` on the wrong Mac stops single-Mac serving on the other Mac") + func stopSoloOnTheWrongMac() async { + let result = await #expect(processExitsWith: .success, observing: [\.standardOutputContent, \.standardErrorContent]) { + var actions = pairActions() + actions.soloServing = { [ClusterOnboardingSoloServing(mac: "the other Mac (Apple M5 Max, 128 GB)", pid: 68099)] } + actions.stopSoloServing = { + FileHandle.standardError.write(Data("pair action: stopSoloServing\n".utf8)) + return .success(["\u{2713} Stopped single-Mac serving on the other Mac (Apple M5 Max, 128 GB)."]) + } + try await exitWithPair(servingPair(), actions: actions) { _ in try await runCLICommand(Stop.self, ["stop", "--solo", "--yes"]) } + } + #expect(lines(result?.standardOutputContent) == [ + "Single-Mac serving doesn't run on this Mac; it runs on the other Mac (Apple M5 Max, 128 GB) (process 68099).", + "\u{2713} Stopped single-Mac serving on the other Mac (Apple M5 Max, 128 GB).", ""]) + #expect(pairActionCalls(text(result?.standardErrorContent)) == ["stopSoloServing"]) + } + @Test("`darkbloom start` in a terminal opens exactly what `darkbloom cluster` runs on this Mac") func startInATerminal() async { let result = await #expect(processExitsWith: .success, observing: [\.standardOutputContent, \.standardErrorContent]) { From 88740bd4469a9578bfe4e02418a7bdce62fda477 Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Wed, 4 Nov 2026 17:05:57 -0800 Subject: [PATCH 11/20] fix(cluster): the version split's hunks sit apart from the single-Mac and follow-final branches The joining Mac reads the versions on its own cadence at the top of its wait loop, the final-reason check is its own line, and the checks file is listed beside the onboarding sources, so this branch merges cleanly with fix/solo-block-both-screens and fix/follow-final-outcome. No behavior change. Co-Authored-By: Claude Opus 5.5 --- .../Onboarding/ClusterOnboardingFollow.swift | 29 +++++++++++-------- .../darkbloom/ClusterPairSummary.swift | 2 +- .../Tests/ClusterOnboardingChecks/run.sh | 4 +-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift index 2b9ee3fbe4..4d83f952f7 100644 --- a/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift +++ b/provider-swift/Sources/ProviderCore/Inference/Distributed/Onboarding/ClusterOnboardingFollow.swift @@ -163,8 +163,6 @@ extension ClusterOnboardingDriver { let timing = operations.followTiming console.say(" " + waitingForStartLine(leader)) let looks = ClusterOnboardingMailbox() - // The two Macs' versions, read with each look: a split never clears by itself, so the wait ends at once on it. - let splits = ClusterOnboardingMailbox() var asking = false, asked = Date.distantPast var begun = Date() var started: Date?, latest: String?, stage = 0, step: ClusterOnboardingLeaderStep?, lastStatus: String? @@ -181,20 +179,27 @@ extension ClusterOnboardingDriver { console.settle() console.say(line) } + // The two Macs' versions, read on the looks' cadence: a split never clears by itself, so the wait ends at once. + let splits = ClusterOnboardingMailbox() + var splitAsking = false, splitAsked = Date.distantPast while true { + if !splitAsking, Date().timeIntervalSince(splitAsked) >= timing.pollSeconds { + (splitAsking, splitAsked) = (true, Date()) + Thread.detachNewThread { splits.post(operations.versionSplit()) } + } + if let read = splits.take().last { + splitAsking = false + if let split = read { + console.settle() + console.result(false, split.title + ".", split.remedies) + console.say(" " + versionSplitAfterLine(leader)) + return 1 + } + } if !asking, Date().timeIntervalSince(asked) >= timing.pollSeconds { asking = true asked = Date() - Thread.detachNewThread { - if let split = operations.versionSplit() { splits.post(split) } - looks.post(operations.leaderStatus?() ?? .init(lines: operations.status(), step: nil)) - } - } - if let split = splits.take().last { - console.settle() - console.result(false, split.title + ".", split.remedies) - console.say(" " + versionSplitAfterLine(leader)) - return 1 + Thread.detachNewThread { looks.post(operations.leaderStatus?() ?? .init(lines: operations.status(), step: nil)) } } if let look = looks.take().last { asking = false diff --git a/provider-swift/Sources/darkbloom/ClusterPairSummary.swift b/provider-swift/Sources/darkbloom/ClusterPairSummary.swift index fec8346b04..d66fddeb4e 100644 --- a/provider-swift/Sources/darkbloom/ClusterPairSummary.swift +++ b/provider-swift/Sources/darkbloom/ClusterPairSummary.swift @@ -405,9 +405,9 @@ extension ClusterPairSummary { /// screen does, within the bounded wait. static func isFinalReason(_ reason: String?) -> Bool { guard let reason else { return true } + if reason.contains(ClusterOnboardingVersionSplit.reasonMarker) { return true } return ClusterOnboardingNotServing.isMissingLogin(reason) || reason.contains("The clock of") || reason.contains("doesn't let") || reason.contains("run different Darkbloom builds") - || reason.contains(ClusterOnboardingVersionSplit.reasonMarker) || ClusterOnboardingReady.isNotOffered(reason) } diff --git a/provider-swift/Tests/ClusterOnboardingChecks/run.sh b/provider-swift/Tests/ClusterOnboardingChecks/run.sh index 26d86c5a36..3bb1fc4c31 100755 --- a/provider-swift/Tests/ClusterOnboardingChecks/run.sh +++ b/provider-swift/Tests/ClusterOnboardingChecks/run.sh @@ -13,8 +13,8 @@ xcrun swiftc -swift-version 6 -warnings-as-errors -parse-as-library -target "$(u "$task_sources/ClusterOnboardingBrand.swift" "$task_sources/ClusterOnboardingPairServing.swift" \ "$task_sources/ClusterOnboardingFollow.swift" "$task_sources/ClusterOnboardingLeaderStep.swift" \ "$task_sources/ClusterOnboardingSoloServing.swift" \ + "$task_provider/Tests/ClusterOnboardingChecks/VersionSplitChecks.swift" \ "$task_sources/ClusterOnboardingStartProgress.swift" \ "$task_provider/Tests/ClusterOnboardingChecks/OnboardingChecks.swift" "$task_provider/Tests/ClusterOnboardingChecks/FollowWaitChecks.swift" \ - "$task_provider/Tests/ClusterOnboardingChecks/StartProgressChecks.swift" \ - "$task_provider/Tests/ClusterOnboardingChecks/VersionSplitChecks.swift" -o "$task_build/onboarding-checks" + "$task_provider/Tests/ClusterOnboardingChecks/StartProgressChecks.swift" -o "$task_build/onboarding-checks" "$task_build/onboarding-checks" From 3eb36c57ff4cea091f9fbc6d4e7ca2cc53309a8f Mon Sep 17 00:00:00 2001 From: jonathan308 <5055076+jonathan308@users.noreply.github.com> Date: Wed, 4 Nov 2026 17:09:34 -0800 Subject: [PATCH 12/20] fix(cluster): an orphaned pair part is never single-Mac serving; a check proves the stop sticks - `ProviderInstanceHolder.singleMacServing` excludes the part this Mac's cluster service recorded, even once launchd adopted it (its arguments read like `start --local`), so nobody is told to `stop --solo` what it can't stop. - `SoloStopSticksTests`: after the stop, a watchdog tick doesn't revive it, an update restarts the pair and not it, and a login or 0.10.8's updater that starts it anyway meets the step aside while the pair's blocked ends never cost its approval. - Docs: the step aside, the recorded choice, the reset of the fallback, and `stop --solo` on the wrong Mac. Co-Authored-By: Claude Opus 5.5 --- .../cluster-solo-stop-on-the-right-mac.md | 1 + docs/provider/two-mac-cluster.md | 17 ++++++- .../Service/ProviderInstanceHolder.swift | 10 ++++- .../SoloStopSticksTests.swift | 45 +++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 provider-swift/Tests/DarkbloomCLITests/SoloStopSticksTests.swift diff --git a/changelog.d/cluster-solo-stop-on-the-right-mac.md b/changelog.d/cluster-solo-stop-on-the-right-mac.md index da5deae4a9..149f6bbc78 100644 --- a/changelog.d/cluster-solo-stop-on-the-right-mac.md +++ b/changelog.d/cluster-solo-stop-on-the-right-mac.md @@ -3,3 +3,4 @@ - If `darkbloom stop --solo` finds no single-Mac serving on this Mac but finds it on the other Mac of the pair, it names that Mac and its process and offers to stop it there. `--yes` stops it without asking, for scripts. It no longer points to plain `darkbloom stop`, which stops the pair and leaves single-Mac serving running. - While single-Mac serving blocks a started pair whose other Mac answers, `darkbloom start` starts the pair (in a terminal, the screen that offers to stop it). It no longer offers "Serve on this Mac alone", which would recreate the block. - "Single-Mac serving is set up" now means its job is loaded, not that its file exists. After `stop --solo`, a pair whose other Mac goes quiet no longer gives up its part for single-Mac serving that can't come back. +- An orphaned pair part, one that outlived its cluster service, is never reported as single-Mac serving. `stop --solo` can't stop it, so you're never told to try. diff --git a/docs/provider/two-mac-cluster.md b/docs/provider/two-mac-cluster.md index e126d26cee..9937479421 100644 --- a/docs/provider/two-mac-cluster.md +++ b/docs/provider/two-mac-cluster.md @@ -1303,7 +1303,22 @@ Mac reports single-Mac serving. `darkbloom cluster status` says the block on both Macs, with `Next:` ``Single-Mac serving doesn't stop by itself: run `darkbloom stop --solo` on each Mac named, then `darkbloom start` on either Mac. …``, and a scripted `darkbloom start` ends its wait at once with that -reason (exit status 3). Plain `darkbloom stop` on a paired +reason (exit status 3). + +When nobody chose single-Mac serving since the pair was started on that Mac +(for example, the update from 0.10.8 restarted a job a plain `darkbloom start` +left set up, or a login or the watchdog started it), the Mac's cluster service +stops it by itself, as `darkbloom stop --solo` does. It writes that to its log, +and `darkbloom status` on that Mac says ``Single-Mac serving stepped aside for +the pair at