Skip to content
Merged
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,9 @@ jobs:
- name: Run cluster model provisioning checks
if: ${{ !cancelled() && steps.toolchain.outcome == 'success' }}
run: bash provider-swift/Tests/ClusterModelProvisioningChecks/run.sh provisioning
- name: Run cluster onboarding checks
if: ${{ !cancelled() && steps.toolchain.outcome == 'success' }}
run: bash provider-swift/Tests/ClusterOnboardingChecks/run.sh

provider-test-gate:
name: Provider Tests
Expand Down
6 changes: 6 additions & 0 deletions docs/architecture/inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ ready screen shows the registered line (`ClusterOnboardingReady.offered`,
`OnboardingLive.offeredReadiness`). How the approval is fetched, matched,
checked on each Mac and saved:
[coordinator-paired member](../reference/configuration.md#coordinator-paired-member).
The control leader checks the approval again under the command lock
(`ClusterService.checkApproval`) and checks a save against its own files
before any part stops (`ClusterApprovalSync.apply`). It compares the other
Mac's approval only when that Mac reports one
(`ClusterApprovalCheck.peerApprovalID`). It counts the quick ends of a part
only from that part's own rank-log lines (`ClusterService.lastError(in:from:)`).
`OnboardingLive` uses fresh peer display facts only while their authenticated
member identity matches the current pairing. These labels do not rewrite saved
serving intent or change model eligibility and placement. See the
Expand Down
6 changes: 5 additions & 1 deletion docs/developer/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,11 @@ root for model-free pseudo-terminal checks of setup stages, menu selection,
failed test responses, terminal restoration and plain output. Set
`ONBOARDING_TRANSCRIPTS` to a private output directory to retain screen text.
The harness compiles only the onboarding flow, terminal and scripted operations;
it does not configure a network port, start a service or load a model.
it does not configure a network port, start a service or load a model. CI runs
it in the `Cluster Metadata Checks` job (step `Run cluster onboarding checks`).
Its rows include the end of the setup after the cluster registers with the
coordinator: the screen waits for both parts to serve again before it says
Done (`leaderWaitsForThePartsAfterTheRegistration`).

`ClusterOnboardingPeerLabelTests` checks the live adapter with injected pairing
facts: fresh authenticated peer labels replace saved display names, changed
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,8 @@ saves it on both Macs. The cluster service then runs each Mac's part as
| When | After the guided setup's Test stage passed (control operation `register`, run by the control leader: `OnboardingLive.localRegister`), once at each start of the control leader's cluster service and after an update re-adopted the setups, and every minute while a serving pair is offered or has its approval kept aside (`ClusterService.checkApproval`). A local-only cluster never asks (`ClusterApprovalSync.asks`) | as named |
| Lifetime | A saved approval with more than `renewWithinSeconds = 86_400` left is kept. Within that day a later matching entry replaces it. An ended one is removed: each Mac saves its setup without it before its part starts, and its part then serves on the leader's local API (`ClusterService.supervise`) | `ClusterApprovalLifetime.decide` |
| Serve locally | Both Macs save their setups without the approval, the other Mac first, and the pair serves on the leader's local API, when: no request gets an HTTP answer for the absence grace (`ClusterService.soloGraceSeconds`: 600 s; `DARKBLOOM_DEBUG_CLUSTER_SOLO_GRACE_SECONDS` in a development build); the coordinator answers (a 404, or a list) without the saved approval and serves no other matching entry; or either Mac's coordinator-paired parts ended `ClusterControlSoloAdmission.maximumQuickEnds = 3` times in a row right after starting (each Mac's status, `memberQuickEnds`; an end because the coordinator was out of reach is not counted). When either Mac cannot save, both keep the approval and the next check tries again. The leader keeps the approval and the reason in its setup record (`approvalSetAside`). When an answer lists a matching entry, the pair is registered again through the Save step; after repeated failures, only a later entry | `ClusterApprovalCheck.step`, `ClusterApprovalSync.serveLocally`; `ClusterService.checkApproval` |
| Both or neither | A send whose reply is lost may come after the other Mac saved: the leader gives it its setup back. Each Mac's status names its saved cluster approval (`approvalID`). On every check the leader compares it with its own; while they differ, it gives the other Mac its approval (while offered) or none, and when the other Mac refuses its approval, it saves its own setup without it too | `ClusterApprovalCheck.macsDiffer`, `ClusterApprovalSync.converge` |
| Both or neither | A send whose reply is lost may come after the other Mac saved: the leader gives it its setup back. Each Mac's status names its saved cluster approval (`approvalID`, `""` for none; a build without the field is unknown and never compared). On every check the leader compares it with its own; while they differ, it gives the other Mac its approval (while offered) or none, and saves its own setup without an approval it does not offer; when the other Mac refuses its approval, it saves its own setup without it too | `ClusterApprovalCheck.peerApprovalID`, `macsDiffer`, `ClusterApprovalSync.converge` |
| Changing | The leader decides under the command lock, from the setup, record and the other Mac's status as they are then. A save is first checked against the leader's own files, so no part stops for an approval it refuses. A busy command lock waits for the next check, a minute later | `ClusterService.checkApproval`, `ClusterApprovalSync.apply` |

A coordinator that answers 404, serves no matching entry or serves only ended
entries leaves both saved setups byte for byte as they were: nothing is sent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ public struct ClusterServiceStatus: Codable, Sendable, Equatable {
/// control leader makes the pair serve locally when either Mac's count reaches the solo server's limit. Nil from an
/// older build.
public var memberQuickEnds: Int? = nil
/// The ID of the cluster approval this Mac's saved setup carries (none: absent). The control leader compares it
/// with its own on each check and gives this Mac its own, or none, when they differ (`ClusterApprovalCheck`).
/// The ID of the cluster approval this Mac's saved setup carries, "" for none. Absent (nil) from a build that does
/// not report it, which the control leader never reads as "none" (`ClusterApprovalCheck.peerApprovalID`). The
/// leader compares it with its own on each check and gives this Mac its own, or none, when they differ.
public var approvalID: String? = nil
public struct Control: Codable, Sendable, Equatable {
public var leaderID: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ enum ClusterApprovalCheck {
return first || macsDiffer || (serving && (offered || setAside))
}

/// Whether the other Mac's saved cluster approval (`peerApprovalID`, from its status; nil: it did not answer) is not
/// The other Mac's saved cluster approval as its status reports it: `.some(id)`, `.some(nil)` for none, and nil when
/// it did not answer or its build does not report the field (an older follower), which is never compared.
static func peerApprovalID(_ status: ClusterServiceStatus?) -> String?? {
guard let reported = status?.approvalID else { return nil }
return .some(reported.isEmpty ? nil : reported)
}

/// Whether the other Mac's saved cluster approval (`peerApprovalID`, from its status; nil: unknown) is not
/// this Mac's. A pair approval saved by hand on this Mac is the operator's and never compared.
static func macsDiffer(_ saved: ClusterConfigurationStore.Saved, peerApprovalID: String??) -> Bool {
guard saved.configuration.nativeMember?.approval == nil, let peer = peerApprovalID else { return false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,44 @@ public enum ClusterApprovalSync {
return Result(changed: true, line: line, note: .some(line))
}

/// The control leader's change for `step` (`ClusterService.checkApproval`, under the command lock). A save is first
/// checked against this Mac's own files and pairing, so no part stops for an approval this Mac refuses. Then `stop`
/// stops both parts (nil when they stopped, else the line why not, and nothing changes), the change runs on both
/// Macs, and `serve` starts the parts again.
static func apply(_ step: ClusterApprovalCheck.Step, grace: Double, paths: ClusterUserPaths, providerConfiguration: URL,
pairingStore: ClusterPairingStore, scratch: URL, now: Double, stop: () -> String?, serve: () -> Void,
sendToPeer: (ClusterServiceCommand) throws -> Void, chipClass: ClusterChipClass? = ClusterChipClass.local(),
facts: (ClusterConfiguration) throws -> ClusterRuntimeApprovalFacts = ClusterApprovalAttachment.installedFacts)
-> Result {
if case .keep = step { return .unchanged }
if case .save(let approval) = step,
let saved = try? ClusterApprovalAttachment.savedSetup(paths: paths, providerConfiguration: providerConfiguration) {
do {
_ = try ClusterApprovalAttachment.attachment(for: approval, saved: saved, paths: paths, pairingStore: pairingStore,
edge: nil, now: now, chipClass: chipClass, facts: facts)
} catch {
let line = "Not offered for pairing: this Mac's check refused it: \(refusal(error))"
return Result(changed: false, line: line, note: .some(line))
}
}
if let failure = stop() { return Result(changed: false, line: failure, note: nil) }
defer { serve() }
switch step {
case .keep:
return .unchanged
case .save(let approval):
return run(fetched: .approvals([approval]), paths: paths, providerConfiguration: providerConfiguration,
pairingStore: pairingStore, scratch: scratch, now: now, sendToPeer: sendToPeer, chipClass: chipClass, facts: facts)
case .serveLocally(let approval, let reason):
return serveLocally(approval, line: reason.line(approval, grace: grace), paths: paths,
providerConfiguration: providerConfiguration, pairingStore: pairingStore, scratch: scratch,
sendToPeer: sendToPeer)
case .converge(let target):
return converge(target, paths: paths, providerConfiguration: providerConfiguration, pairingStore: pairingStore,
scratch: scratch, sendToPeer: sendToPeer)
}
}

/// `ClusterApprovalCheck.Step.converge`: the other Mac's saved cluster approval differs from this Mac's (a lost
/// reply, a failed give-back), so it is given this Mac's (`target`), which it checks against its own files, or
/// none. When it refuses this Mac's, this Mac saves its setup without it too: both Macs carry the approval, or
Expand Down Expand Up @@ -111,9 +149,19 @@ public enum ClusterApprovalSync {
catch { line += " (this Mac could not save its setup yet: \(refusal(error)))" }
return Result(changed: true, line: line, note: .some(line))
}
let line = target.map { "The other Mac's cluster approval differed from this Mac's: both Macs now carry approval \($0.id)" }
?? "The other Mac's cluster approval differed from this Mac's: neither Mac carries one now"
return Result(changed: true, line: line, note: nil)
guard let target else {
// None: this Mac also saves its setup without a cluster approval it still holds but does not offer (it
// ended, or the cluster serves locally only), so both Macs hold none and the next check finds no difference.
var line = "The other Mac's cluster approval differed from this Mac's: neither Mac carries one now"
if saved.configuration.nativeMember?.clusterApproval != nil {
do { _ = try ClusterApprovalAttachment.save(nil, saved: saved, paths: paths, providerConfiguration: providerConfiguration,
scratch: scratch) }
catch { line += " (this Mac could not save its setup yet: \(refusal(error)))" }
}
return Result(changed: true, line: line, note: nil)
}
return Result(changed: true, line: "The other Mac's cluster approval differed from this Mac's: both Macs now carry approval \(target.id)",
note: nil)
}

/// One run of the step. `sendToPeer` delivers an `approval` command over the cable and throws the other Mac's
Expand Down
Loading
Loading