Repository navigation
cluster: the pair's leader takes local requests beside Darkbloom (L5a) - #1875
Merged
Merged
Conversation
…L5a) Eleven CPU-only tests, each failing today: - the leader member's local API serves its pair slot (today a member refuses any local API at `prepareClusterMemberControl`); - only the slot's host runs one, and only with a key; - "the pair is not serving now" is a 503 (today the member guard's untyped error, a 500); another model is a 404; - a local request waits in a bounded FIFO queue for one of the pair's lanes (today it is handed the bridge at once and refused at submit): 429 when full, 503 past its ceiling, cancelled waiters leave; - nothing slips in during the warmup canary; - retirement while queued is a 503 and the stream in flight ends; - a three-rank roster (today the pair engine requires exactly two peers); - a local request behind a Darkbloom request wakes when it ends; - Darkbloom requests see no extra wait with the local API idle; - stopping drains a local stream and frees the port. The counts the tests read (waiting requests, the owner's use) are stubbed at zero; the next commit implements them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The leader member's unified local endpoint now serves its published pair slot, through the slot's one bridge and its lanes. No process, copy or buffer is added, and a Darkbloom request's path is unchanged. - Only the member that hosts the slot (the serving host role a rank-0 installation gives) may run a local API, and only with a key; every other member keeps refusing one at `prepareClusterMemberControl`. - "The pair is not serving now" (before its slot, while it re-forms, after it retired) answers 503, as `cluster local` does, not the member guard's untyped error (a 500). Another model is a 404. - A local request that finds every lane busy waits in a FIFO queue, bounded as `cluster local`'s (`DARKBLOOM_CLUSTER_QUEUE_WAITING`, 429 when full, 503 past the ceiling). A waiter is parked, never polled: a released local lane, the capacity refresh after each Darkbloom request, admission opening and the slot retiring wake it. A free lane with nobody waiting is taken at once. - Local admission opens only after the warmup canary passed: a request made during it waits, and hears 503 if the slot retires. - `noteClusterPairLocalUse` is the owner-pause hook: the owner's use of the pair begins when a request starts waiting (or takes a lane) and ends once. - The pair engine's identity check accepted exactly two peers; it now takes two or more distinct peers (pairs of two unchanged). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Direct mode gains the leader member's local API (who runs it, its answers, its queue, what it costs); the inference architecture gains its invariants. One changelog fragment. The cluster guide keeps "no local API" for a pair served through Darkbloom: no command starts the leader's API yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
With the periodic capacity refresh off, a local request parked for a lane hears a drain (a stop or an update) only when some other event wakes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`beginServingDrain` wakes them, so each hears the drain's refusal (429) at once instead of at the next capacity refresh. With nobody waiting, and on every single Mac, the call is one count check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The required refactor pass on #1875. Behaviour-preserving: the same checks, in the same order, with the same suspensions; no public name changes, and the L5b hooks (`noteClusterPairLocalUse`, `clusterMemberHeartbeat()`) are untouched. - One "next in line" rule. `ClusterPairLocalLanes.isNext` (the first waiter, or a newcomer while nobody waits) is checked inside `grantClusterPairLaneIfFree`, before and after the engine's count. Before, each caller checked it and the grant checked it again in another form. `isFirst` is private now. - The waiting loop reads check, take, park. Parking is its own `parkClusterPairWaiter`, and "the slot this request is bound to still serves" is `clusterPairSlotStillServes` (it was written out twice). - Comments state the invariants: only the slot's host runs a local API, and only with a key; the queue is bounded and first in, first out; Darkbloom requests never enter it, and their side pays one count check; why the identity check's relaxation to two or more peers still refuses a repeated or an impostor peer; why the pair's release stays apart from a single Mac's. - Tests: one helper builds the member loops (three copies before) and one the serving context (two). `nothingKeysOnTwoRanks` also proves that a repeated peer in a pair of two and an impostor third rank are refused. - Docs: the architecture section says why the relaxed identity check is still safe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 of 16 tasks
jonathan308
added a commit
that referenced
this pull request
Nov 7, 2026
The required refactor pass on #1881. Behaviour-preserving: no public name or signature changes, and the shipped code is byte for byte the same (the prelinked ProviderCore.o is identical before and after; the one source file touched changes only in comments). - ProviderLoop+ClusterPairMeFirst states its invariants as a list: the leader decides for the pair, whatever its number of Macs (the process that owns the pair's local API owns the pause; nothing counts ranks); every other member stays control-only; nothing in flight is cancelled; nothing polls (O(1) request edges, heartbeats only on transitions, the idle check on the pause's one timer and the member beat that already runs every 5 s). - Tests: ClusterPairMeFirstTests runs its leader on #1875's PairLeaderFixture, which it copied in 75 lines (LeaderRunFixture). The fixture is internal now and takes the leader's [local] section, shared serving by default as before; its discovery check also covers the pid. ControlOnlyMember replaces the untouched member's setup and beat-and- compare, written out in two tests. Dead code is gone: stableHeartbeat's unused `dropping:` and pairMember's `coordinatorURL`. Every test keeps its assertions (the same count of #expect and #require in each). - owner-pause.md: the tests paragraph said the pair suite runs without the GPU. Its two tests that complete Darkbloom requests need a Metal device (each terminal reads MLX's memory counters), though they submit no GPU work. Checks (prod, CPU-only: empty kernel libraries, a sampler saw no GPU work): ClusterPairMeFirstTests 7/7, #1877's suites 28/28, #1875's cluster selection 305/305 and the drain/settings selection 46/46, the same 386 per-test outcomes as the merge before this commit; the pair suites 5 more times and #1877's 3 more times. Mutants (no forwarding to the pause, no resume on the member beat, a saved single-Mac mode honoured, no timer cancel on stop, the fixture ignoring [local]) are each killed. docs-check, docs-impact-check and changelog check pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…view) The independent review found two tests that passed with their code removed: - The warm-up test ran with one lane, which the canary itself holds, so the engine's own count kept a local request out without the admission gate. It now runs with two lanes (the canary leaves one free) and checks that no local request holds a lane while the canary runs. With the gate removed from `clusterPairLaneFreeHere`, it fails: the request takes the free lane. - The cancel test cancelled the first waiter, which the periodic capacity refresh wakes anyway. It now cancels the second of two waiters, which only its own cancellation handler wakes, and bounds the wait. With the handler removed from `parkClusterPairWaiter`, it fails in 1.6 s: the waiter keeps its place until the one ahead of it leaves. Tests only; no behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"A client that goes away leaves the queue" overstated it. A cancelled request or a reset connection leaves at once. A client that closes its connection normally (curl, URLSession) keeps its place until its turn, then reaches the pair, the same as on `cluster local`: the close is seen at the request's first write, which ends it and frees its lane, and so bounds the waste. Direct mode, the architecture invariant and the code comments now say so. Docs and comments only; no behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR L5a of the local-first work for provider 0.10.11: a pair's leader takes the owner's local requests beside Darkbloom, in provider core only. The leader member's existing unified local endpoint now serves the published pair slot through the slot's own bridge and lanes (spike S5). It closes the spike's four gaps: the member guard, a 503 instead of a 500, a bounded lane queue, and no slip-in during the warm-up canary. Nothing keys on two Macs. No CLI or screen change: that is L5b.
Draft. Do not merge: no
devmerges until the owner says so, because adevmerge publishes a DevNet build.Linked issue
None. Part of the local-first goal (
GOAL.mdcriteria 1, 5 and 8;SPIKE-S5.md§5.1).What changes
prepareClusterMemberControl)clusterPairServing, the serving-host role a rank-0 installation gives) may run one, and only with a key. Every other member still refuses itensureModelLoadedthrew the member guard's untyped error: HTTP 500requestRejected(DistributedRequestQueue.unavailableMessage)), ascluster localanswers. Another model is 404cluster local:DARKBLOOM_CLUSTER_QUEUE_WAITING(default 64), 429 when full, 503 pastLimits.waitCeiling. A cancelled request or a reset connection leaves the queue at once. A connection closed normally (curl, URLSession) keeps its place until its turn, then reaches the pair and is seen at its first write, as oncluster localclusterPairAdmissionOpenSlotID). A request made during it waits, and gets 503 if the slot retiresDistributedResidentIdentity.validaterequired exactly two peersOverhead (owner, criterion 8: "make sure this all does not add much overhead")
How it stays cheap:
EngineV2Bridge, through the samemakeLocalInferenceApplicationstack as single-Mac unified mode.AcquiredModelhands the local app the pair's bridge itself; tokens stream from it as on one Mac.ClusterPairLocalLanes.park). Something that can free a lane wakes the first waiter: a released local lane, the capacity refresh that already follows each Darkbloom request's end, or admission opening. Something that refuses waiters wakes them all: a drain beginning (each hears 429) or the slot retiring (503). The queue has no timer of its own except each waiter's ceiling (one sleep). The existing periodic capacity refresh (heartbeat ÷ 2) also wakes the first waiter. That covers a request that ended here while the pair's engine still retires it.owner.concurrentRequests, and the engine's admission is untouched.handleInferenceRequestis untouched, and no per-token work is added.wakeClusterPairLocalWaiters(): one at the end of the member's existingrefreshClusterPairCapacity(), and one inbeginServingDrain(a single Mac included). Each does nothing while nobody waits.Measured on Mac A, CPU-only, with scripted owners and a loopback
MockCoordinator, while other builds ran in parallel:cluster localpolls every 10 ms)The committed test
aDarkbloomRequestSeesNoExtraWaitWhenNoLocalRequestIsQueuedchecks this: the median push → lane with an idle local API stays within 2× + 25 ms of the leader without one. Every third request follows a local request that has just released the lane.The hook for the owner pause (L5b, after L1/L2)
ProviderLoop.noteClusterPairLocalUse(_:)inProviderLoop+ClusterPairLocal.swift. It is called with.beganwhen a local request starts waiting for a lane, or takes one at once, before it can wait behind Darkbloom work. It is called with.endedexactly once: when the request leaves without a lane (429, 503, cancelled) or when its lane is released. Today it keepsclusterPairLocalLanes.inUse, and the tests prove the count returns to 0 on every path. L5b adds L1'snoteLocalUse(.start/.end)there.clusterMemberHeartbeat()(ClusterMemberSupervisionSetup.swift), which the member service calls every 5 s on the actor. Members run no idle or capacity monitor.Before and after
flowchart LR subgraph B["Before"] direction TB BD["Darkbloom request"] --> BH["handleInferenceRequest"] --> BS["Pair slot bridge"] BO["Owner's tool"] --> BX["No local API: every member refuses one"] BA["Local acquire on a member"] --> B5["Untyped error → 500"] BL["Lanes busy"] --> B4["429 at submit"] BW["Warm-up canary running"] --> BI["Local request slips in"] end subgraph A["After"] direction TB AD["Darkbloom request"] --> AH["handleInferenceRequest (unchanged)"] --> AS["Pair slot bridge (same lanes)"] AO["Owner's tool → leader's local API (key)"] --> AQ{"Slot live?"} AQ -- "no" --> A5["503"] AQ -- "yes" --> AF{"Admission open, lane free, nobody waiting?"} AF -- "yes" --> AS AF -- "no" --> AW["FIFO wait (parked)"] AW -- "woken on release" --> AF AW -- "full / ceiling / retired" --> AE["429 / 503"] end classDef old fill:#fde2e1,stroke:#c0392b,color:#1b1b1b classDef new fill:#dff3e4,stroke:#1e8449,color:#1b1b1b classDef same fill:#e8eef7,stroke:#2e5c8a,color:#1b1b1b class BX,B5,B4,BI old class AO,AQ,AF,AW,A5,AE new class BD,BH,BS,AD,AH,AS,BO,BA,BL,BW sameCode path (blue: unchanged; green: new or changed):
Test plan
All runs were CPU-only (no GPU), on Xcode 27.2 with
DARKBLOOM_RELEASE_ENVIRONMENT=prod(as CI), undernice -n 19andsandbox-execwith a profile that denies~/.darkbloom*. Each run had temporaryDARKBLOOM_STATE_FILE,DARKBLOOM_LOADED_MODELS_FILE,DARKBLOOM_VERIFIED_WEIGHTS_FILE,DARKBLOOM_LOCAL_DIRandCFFIXED_USER_HOME. Every local API in the tests binds127.0.0.1:0, and every coordinator is a loopbackMockCoordinatoron port 0.ed9681646c(tests plus the counts they read stubbed at 0):swift test --skip-build --no-parallel --filter ClusterPairLocalTestsran 11 tests and 11 failed, each for the gap it covers. The member refused the endpoint, so the 4 run() tests timed out on registration. The not-serving case threwClusterMemberControlError(500). Local acquires returned at once while lanes were busy or the canary ran. The 3-rank slot was refused by the 2-peer identity check.160c100ea2: the same filter passes, 11/11 in 4.7 s.aDrainRefusesWaitingLocalRequestsAtOncefails at96c040fcb9(with the periodic refresh off, the waiter is never told) and passes atdd04f86a43. At the head,f408ad86b8,ClusterPairLocalTestspasses 12/12 in 4.8 s.cluster localincluded:--filter 'ClusterPair|ClusterMember|DistributedLocalServer|DistributedHTTP|DistributedRequestQueue|ClusterAPIParity|ClusterAPIDecoration|LocalEndpointFile|DistributedCBv2|NativePairMember'passes (297 tests in 41 suites, plus 109 in 15).--filter 'AddonIPCTests|AddonHoldDrainOwnershipTests|AddonHoldStoreTests|AddonHoldLoopTests|AddonHoldServeLoopTests|AutopilotBusyReasonTests|LocalDrainHTTPTests|ProviderLifecycleTests|ServeLoopConnectionTests|ServingReadinessTests|UpdateDrainAwarenessTests|AppAttestUpdateLifecycleTests|ClusterPair|ClusterMember'passes (237 tests in 35 suites, plus 109 in 15).python3 scripts/changelog.py check,scripts/docs-check.shandscripts/docs-impact-check.py --base 9640170620all pass.f408ad86b8(CI (dev) run 42311207017): every required job passed, including Provider Unit Tests shards 1 and 2, where all 12 new tests ran and passed, and the Cluster Runtime, Focused and Release checks. The non-blocking cluster GPU shard 1 was still running when this was written.cluster localon pair-2.The tests (
provider-swift/Tests/ProviderCoreTests/ProviderLoop/ClusterPairLocalTests.swift):theLeaderServesItsPairOnItsLocalAPIlocal.jsonnames the bound port and the keyonlyTheSlotsHostRunsALocalAPIAndAlwaysWithAKeyaLocalRequestWhileThePairIsNotServingIs503aLocalRequestWaitsForALaneAndTakesItWhenItIsReleasedqueueExitedAt, the use countaFullQueueIs429AWaiterPastItsCeilingIs503AndACancelledWaiterLeavesaLocalRequestDuringTheWarmupCanaryWaitsForAdmissionaDrainRefusesWaitingLocalRequestsAtOnceretirementWhileQueuedIs503AndTheRequestInFlightEndsnothingKeysOnTwoRanksaLocalRequestWaitsBehindADarkbloomRequestAndRunsWhenItEndsaDarkbloomRequestSeesNoExtraWaitWhenNoLocalRequestIsQueuedstoppingTheLeaderWithALocalStreamDrainsItAndFreesThePortlocal.jsonIndependent review fixes (
b17cd364b0,c7b49d5e01)The review found two tests that passed with their code removed, and one overstated doc sentence. Tests, docs and comments only; no behaviour change.
clusterPairLaneFreeHere: red, the request takes the free lane during the canaryonCancelemptied inparkClusterPairWaiter: red in 1.6 s, no hang (the waiter keeps its place until the one ahead leaves)cluster local. That first write bounds the wasteClusterPairLocalTestspasses 12/12: three runs atb17cd364b0and one atc7b49d5e01(CPU only, prod identity, the same isolation as above).Components touched
Protocol / interface changes
localEndpoint;DistributedResidentIdentity.validatetakes two or more distinct peers;Documentation impact
docs/provider/direct-mode.md, "A pair's leader beside Darkbloom";docs/architecture/inference.md, "The pair's leader takes local requests beside Darkbloom".docs/provider/two-mac-cluster.mdstill says a pair served through Darkbloom has no local API. That is still true for users, because no command starts it yet; L5b changes it.Changelog
changelog.d/cluster-leader-local-api-beside-darkbloom.md. L5b updates it in place when the CLI starts the API.Notes for reviewers
Lane rule. A local request takes a lane only when two counts are both below
lanes:requestToModel);capacitySnapshot: active + admitting).The drain check (
throwIfRefusingNewLocalWork) andlocalReservations.reservehave no suspension between them, as on one Mac. So a stop or update drain waits for every granted local request.Shared mode is best effort. With no pause (before L5b), a Darkbloom dispatch can still take a freed lane ahead of a waiting local request. The local request then keeps waiting until its ceiling. Once L5b wires the pause, the pause begins at queue entry.
Cache partition. Local requests keep the local app's own partition (
local-native-…): no tenant salt, never a coordinator scope (test 1).Refactor. The waiter is not shared with
DistributedLocalServer.waitForTurn. That one polls every 10 ms and binds to session generations; extracting a common waiter would changecluster local, which this PR keeps unchanged. Its only edit is a named constant for the identical "Distributed session is unavailable" text.Two-Mac assumptions this PR leaves in place (spike S5 appendix, not L5a's):
NativePairMemberInstallation(peers.count == 2, ranks 0…1);ClusterWorkerPair([start.endpoint, peer]);ClusterLocalServing.sharedPorttakes one peer.Limitations and gates
Start.validatestill refuses--cluster-member --local-endpoint. That is L5b, with the pair key, the port helper and the "Both, me first" screen.