Skip to content

cluster: the memory re-plan never starts a pair its owner just stopped - #1889

Merged
jonathan308 merged 7 commits into
devfrom
fix/memory-replan-keeps-an-owners-stop
Nov 8, 2026
Merged

jonathan308 merged 7 commits into
devfrom
fix/memory-replan-keeps-an-owners-stop

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Status: draft; not merged. Follow-up F4 from #1888's review: red 77fed7bd24, fix 93709ebc21. Refactor pass
done (ca6ac85380, overnight/refactor-1889.md). The gap it found is fixed here too: red 637b201b6b, fix
84c95a27a1 (the memory re-plan's own failed stop no longer leaves the pair stopped). The independent review
(overnight/review-1889.md, approve with nits) is addressed in red becc146028, fix 557632292f: an owner's stop no
longer uses up the re-plan's 10-minute slot, and its two untested paths are tested.

Summary

When this Mac's part of a pair is refused at load twice (memory_gate_refused), the control leader plans the model
again on the memory now (ClusterService.noteMemoryRefusal). That re-plan comes due when a part ends, so also right
after the owner stops the pair with darkbloom stop. It waited for the command lock that stop holds, then planned,
adopted and served without reading the pair's saved start again: its localServe saved the start again, and the pair
the owner had just stopped started. #1888 closed the same gap for the re-plan after an update and the approval change;
its re-review left this older one as F4 ("the memory re-plan can still restart a just-stopped pair", re-review §3).

With this PR the invariant holds for all three of the leader's automatic steps: a stop the owner issued is never
undone.

  • replanForMemory (the re-plan's body, moved out of noteMemoryRefusal's thread unchanged) acts, once it holds the
    command lock, only while this Mac still leads on a confirmed claim and the pair's start is still saved. It is the
    same guard as checkForUpdate's, so a hand-over that finished while it waited also stops it.
  • It takes the command lock as checkForUpdate and checkApproval now do: beside the service's own files (the same
    file as every cluster command's on a Mac; tests then never touch the default home). Since the refactor pass, both
    re-plans take it through one guard, commandLockIfStillStarted().
  • Its own failed stop keeps the pair started (found by the refactor pass, 84c95a27a1). The re-plan adopts through
    localAdopt, which on a serving pair stops both parts first; that stop clears the saved start, and its failure (the
    other Mac doesn't answer, this Mac's part doesn't release) returned with the start lost: the pair stayed stopped, and
    no memory re-plan acts on a stopped pair again. That is B6's shape, which cluster: a pair stays started when its automatic stop after an update fails #1888 fixed for its two steps. From the
    adoption on, every failure now puts the start back and drops the stop request a half-done stop keeps
    (restoreStart), under the command lock every stop of the pair holds, so it never undoes an owner's stop. The
    failure line ends "The pair stays started." (It still quotes the stop's own lines before that, as cluster: a pair stays started when its automatic stop after an update fails #1888's lines do:
    the review's nit 4, left as it is.)
  • An owner's stop gives the re-plan's slot back (the review's §4 and nit 3, 557632292f). The re-plan comes due on
    the end of a part the owner's stop ended, and does nothing; but its trigger had already set the next slot 10 minutes
    ahead. An owner who started the pair again within those minutes, with a split that still doesn't fit, got no
    re-plan: its parts kept being refused at load until the slot passed. A re-plan that finds the pair's start cleared
    now gives the slot back, so the owner's next start is re-planned at its next two refusals.

Not changed: the trigger (noteMemoryRefusal: two refusals, at most once per 600 s, gated on control.leads); a
failure before the adoption (nothing is stopped yet; it says why). A re-plan put off by a busy lock, ended by a failure,
or refused for a claim that isn't confirmed (or moved) keeps its slot: the next try needs two more refusals after
the 10 minutes pass. For an unconfirmed claim that means waiting out the slot, not just the next refusal; it is rare
(the leader's part runs only while its claim counts as confirmed) and safer (on a superseded claim the other Mac would
refuse the adoption's stop).

Linked issue

None. Follow-up F4 of #1888's review (overnight/review-1888.md, "Re-review", §3 "Residual 1").

Test plan

Xcode 27.2, prod identity, swift build --build-tests at nice -n 19, only ProviderCoreTests built (an uncommitted,
skip-worktree Package.swift gate). Tests ran with swift test --skip-build --no-parallel in a sandbox that denies
~/.darkbloom*, the GPU's user clients, ~/Library/LaunchAgents writes, and binds and connections on 8000 and
47420–47423, each run with its own state files and home.

  • Red at 77fed7bd24 (seams with the same behaviour on a Mac: replanForMemory(model:say:), the
    memoryReplan stand-in for its onboarding steps, the lock beside the service's files; plus the test).
    aMemoryReplanRightAfterAStopOrAHandOverDoesNothing: the owner's command holds the command lock as the re-plan comes
    due; the owner stops the pair (the real localStop) or control moves to the other Mac; the lock is released.
    • "the owner stopped the pair": the re-plan ran, and the pair's start was saved again (2 issues);
    • "control moved to the other Mac": the re-plan ran (1 issue);
    • the suite's other 15 tests pass there.
  • Green at 93709ebc21: ClusterServiceRestartingStopTests 16/16 (26 cases) at the time. Also passing:
    ClusterServiceRecoveryTests 7, ClusterServicePairingChangeTests 4, ClusterServicePartStartCacheTests 2,
    ClusterApprovalServiceStartTests 9, ClusterMemberServeLoopTests 11, ClusterLeaderFailoverFinishTests 14.
    ModelLoadRefusalTests needs Metal (it aborts in this GPU-less sandbox): for CI.
  • Mutants on 93709ebc21, each caught by the new test: the start read before the lock is taken (the owner's
    case: the re-plan ran and saved the start), and no claim re-check (the hand-over case).
  • docs-check (211 files), changelog.py check (38 fragments), docs-impact-check.py --base d17f62905f (5
    files), git diff --check: clean.
  • Refactor pass (ca6ac85380): one guard for both re-plans, same behaviour; 16 tests (26 cases) and 24
    related suites pass before and after; its mutants H1–H3, M and U are each caught (overnight/refactor-1889.md). CI
    (dev) run 42421246054 succeeded, all 21 jobs.
  • Red at 637b201b6b for the failed stop: aMemoryReplanWhoseStopFailsLeavesThePairStartedAndTriesAgain
    (adopt stands in for localAdopt on a serving pair with the real localStop):
    • "the other Mac does not answer": the start is lost, and the next memory re-plan does nothing (2 issues);
    • "this Mac's part does not release": the start is lost, the stop request stays, and the next re-plan does nothing
      (3 issues);
    • anOwnersStopWithoutTheCommandLockDuringAStepsFailingStopHolds gets a "memory re-plan" case: a
      releaseForSingleMac during the re-plan's failing stop must hold. It passes there and after the fix (the restore
      runs under the command lock that stop waits for).
  • Green at 84c95a27a1: ClusterServiceRestartingStopTests 17/17 (29 cases). Also passing:
    ClusterServiceRecoveryTests 7, ClusterServicePairingChangeTests 4, ClusterApprovalServiceStartTests 9,
    ClusterMemberServeLoopTests 11, ClusterLeaderFailoverFinishTests 14, ClusterInstallIsolationTests 22. Docs
    checks clean (docs-check 211, changelog.py check 38, docs-impact 5 files, git diff --check). It merges cleanly
    into today's dev ce9e92e030.
  • Red at becc146028 for the slot (seams, the same behaviour on a Mac: noteMemoryRefusal reads the
    incident log of the service's own home and is reachable from tests, as is memoryReplanInFlight; the restore goes
    through the steps' restoreStart, as UpdateReplan's does). aSkippedMemoryReplanGivesItsSlotBackOnlyForAnOwnersStop,
    the trigger as the service calls it at each part's end, with a recorded memory_gate_refused:
    • "the owner stopped the pair": refused, the owner's stop, the stopped part's end (the re-plan comes due, does
      nothing), a start within the 10 minutes, two more refusals: no re-plan there (1 issue); it must re-plan and serve;
    • "another command held the lock" (passes there and after): the re-plan put off by a busy lock keeps its slot.
    • The review's untested paths, passing there and after: a third case of
      aMemoryReplanWhoseStopFailsLeavesThePairStartedAndTriesAgain, "the parts do not start again" (the stop went
      through, the restart fails before it saves the start); and in every case the start is put back while the re-plan
      still holds the command lock, checked at the moment of the restore.
  • Green at 557632292f: ClusterServiceRestartingStopTests 18/18 (32 cases), and 8 related suites, 90 tests
    (ClusterService{Recovery,PairingChange,Descriptor}Tests, ClusterApproval{ServiceStart,Watch}Tests,
    ClusterMemberServeLoopTests, ClusterLeaderFailoverFinishTests, ClusterInstallIsolationTests).
  • Mutants on 557632292f, each caught by the suite: the review's Mx2 (a failed restart not restored) and Mx3
    (the lock let go before the restore: the check at the restore, 6 issues); the slot kept on an owner's stop; the slot
    given back for a busy lock too.
  • Docs checks clean (docs-check 211, changelog.py check 38, docs-impact 5 files, git diff --check); it merges
    cleanly into today's dev ce9e92e030.
  • CI (dev) on 557632292f: run 42431364789 succeeds on its first attempt, all 21 jobs; in Provider Unit Tests
    the suite passed with the slot test (2 cases) and the failed-stop test (3 cases).
  • CI (dev) on 84c95a27a1: run 42423259553 succeeds on its first attempt, all 21 jobs; in Provider Unit Tests
    the suite passed with the new test (2 cases) and the owner's-stop test (3 cases).
  • CI (dev) on 93709ebc21: run 42410918256 succeeds on its first attempt, all 21 jobs. The new test ran in
    Provider Unit Tests (2 cases), and so did ModelLoadRefusalTests ("Model load refusals and waits").
  • DevNet: not needed for the guard itself; a pair whose part is refused at load twice right after darkbloom stop
    should stay "■ Stopped".

Components touched

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

Protocol / interface changes

  • No protocol/interface changes. No wire field, CLI flag or config key changes.

Documentation impact

  • Canonical documentation updated: docs/architecture/inference.md (the automatic re-plan after memory refusals),
    and the invariants on ClusterService+RestartingStop.swift.

Changelog

  • Added changelog.d/memory-replan-keeps-an-owners-stop.md; python3 scripts/changelog.py check passes.

Refactor Pass

Done in ca6ac85380 by a dedicated pass (overnight/refactor-1889.md): commandLockIfStillStarted() is the one guard
both re-plans take the command lock through (the PR had copied checkForUpdate's four lines); the header gives the
memory re-plan a paragraph of its own; the memoryReplan stand-in sits with the other stored properties, and a doc that
named memoryReplan for the trigger names noteMemoryRefusal. Same behaviour, tests unchanged but for two doc
comments. Its note 1 (the failed stop) is fixed here (637b201b6b, 84c95a27a1). Its note 2 (a skipped re-plan uses
up its 10-minute slot) is fixed for an owner's stop (becc146028, 557632292f), the case the independent review
found hurts users. A busy lock, a failure, or an unconfirmed or moved claim still keeps the slot (the trigger still gates
on control.leads), so an unconfirmed claim waits out the slot, then two more refusals, before the next try.

jonathan308 and others added 2 commits November 7, 2026 12:09
Review of #1888 (F4, "older gap"): when this Mac's part of the pair is
refused at load twice (`memory_gate_refused`), the control leader plans
the model again on the memory now (`noteMemoryRefusal`). That re-plan
comes due when a part ends, so also right after the owner stops the
pair with `darkbloom stop`. It waits for the command lock the stop
holds, then plans, adopts and serves without reading the pair's saved
start again: `localServe` saves it again, and the pair the owner stopped
starts. It also acts on a claim that moved to the other Mac meanwhile.

Seams, the same behaviour on a Mac: the re-plan's body is
`replanForMemory(model:say:)`, its onboarding steps can be stood in for
(`memoryReplan`), and it takes the command lock beside the service's own
files, as `checkForUpdate` and `checkApproval` do (the same file on a
Mac).

New test, failing here: with the owner's command holding the lock as
the re-plan comes due, the owner stops the pair (the real `localStop`)
or control moves to the other Mac; once the lock is free the re-plan
must do nothing. Here it re-plans both times, and after the stop the
pair's start is saved again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of #1888 (F4). The memory re-plan (`replanForMemory`, due after
this Mac's part is refused at load twice) comes due when a part ends,
so also right after the owner's `darkbloom stop`, whose command lock it
then waits for. It planned, adopted and served without reading the
pair's saved start again, so its `localServe` started the pair the
owner had just stopped.

Once it holds the command lock it now acts only while this Mac still
leads on a confirmed claim and the pair's start is still saved: the
same guard as the re-plan after an update (`checkForUpdate`). A stop the
owner issued is never undone, by any of the leader's automatic steps.

Docs: architecture/inference.md, the extension's header; changelog
fragment memory-replan-keeps-an-owners-stop.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

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

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

Request Review

…ne guard

Same behaviour. No test expectation is removed or loosened; the test file
changes only in two doc comments.

- commandLockIfStillStarted (ClusterService+RestartingStop.swift) takes
  the control command lock beside the service's own files within 5 s and
  goes on only while, once it is held, the pair's start is still saved
  and this Mac leads on a confirmed claim. The re-plan after an update
  (checkForUpdate) and the memory re-plan (replanForMemory) both take the
  lock through it, so the guard that keeps an owner's stop from being
  undone is written once, with its reason on it; the PR had copied
  checkForUpdate's four lines. The approval change keeps its own lock and
  re-decision: it may change a stopped pair's approval, and it says a
  busy lock and tries again in a minute.
- The file's header gives the memory re-plan a paragraph of its own: it
  starts the pair too and takes the lock as the re-plan does, so it never
  starts a pair its owner stopped while it waited, nor acts on a claim
  that moved meanwhile. The two steps' three invariants read as before.
- The memoryReplan stand-in is declared with the service's other stored
  properties, beside the memory re-plan's state, instead of after init.
  The doc of that state pointed at "memoryReplan" for the trigger, which
  now named the stand-in: it names noteMemoryRefusal.
- Tests: the memory re-plan test's doc says what its localServe would do
  (it read as if the re-plan still started the stopped pair), and the
  command-lock helper's doc no longer says "both steps".

Checks (Xcode 27.2, prod identity, nice 19, CPU only, in a sandbox
without ~/.darkbloom*, LaunchAgents writes or ports 8000/47420-47423):
- ClusterServiceRestartingStopTests 16 tests (26 cases) and 24 related
  cluster suites (229 tests in all) pass, before and after, with the
  same build warnings in the touched files.
- Mutants on these sources are each caught: the guard without the start's
  re-read, without the claim's re-check, or checking before it takes the
  lock; either re-plan back on the bare lock.
- docs-check, docs-impact (base d17f629), changelog check and
  preview, diff --check: clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 and others added 2 commits November 7, 2026 14:55
Refactor pass of #1889 (note 1): the memory re-plan adopts its new split
through `OnboardingLive.localAdopt`, which on a serving pair stops both
parts first (`localStop` clears the pair's saved start before it stops
anything) and returns on a failure without putting the start back. The
pair then stays stopped, and no memory re-plan acts on a stopped pair
again: B6's shape, which #1888 fixed for the re-plan after an update and
the approval change.

New test, failing here: the memory re-plan's stop fails, because the
other Mac doesn't answer or this Mac's part doesn't release. The start
must be put back, the stop request a half-done stop keeps dropped, and
the next memory re-plan must run. Here the start is lost in both cases,
the request stays, and the next re-plan does nothing.

The test of an owner's stop that skips the command lock
(`releaseForSingleMac`) during a step's failing stop gets the memory
re-plan as a third case: the owner's stop must hold, whatever the
re-plan restores.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refactor pass of #1889 (note 1). The memory re-plan adopts through
`localAdopt`, which on a serving pair stops both parts first; that stop
clears the pair's saved start, and its failure (the other Mac doesn't
answer, this Mac's part doesn't release) returned with the start lost.
The pair then stayed stopped on both Macs, and no memory re-plan acts on
a stopped pair: B6's shape.

From the adoption on, every failure of the memory re-plan now puts the
start back and drops the stop request a half-done stop keeps
(`restoreStart`), as the re-plan after an update does from its stop on.
It does so under the command lock it holds, which every stop of the
pair holds too, so it never undoes an owner's stop. The failure line
says "The pair stays started."

Docs: architecture/inference.md, the extension's header; the changelog
fragment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 and others added 2 commits November 7, 2026 16:11
Review of #1889 (§4, nits 1-3). The memory re-plan comes due when a
part ends, so on the end of a part the owner's `darkbloom stop` stopped,
and it then does nothing: the pair is stopped. But its trigger had
already set the next slot 10 minutes ahead. An owner who starts the
pair again within those minutes, with a split that still doesn't fit,
gets no re-plan: the parts keep being refused at load until the slot
passes.

Seams, the same behaviour on a Mac: `noteMemoryRefusal` reads the
incident log of the service's own home (the default one on a Mac) and
is reachable from tests, as is `memoryReplanInFlight`; the memory
re-plan puts the start back through its steps (`restoreStart`, as
`UpdateReplan` does), so a test can see when it does.

New tests:
- failing here: a part refused, the owner's stop, the stopped part's
  end (the re-plan comes due and does nothing), a start within the 10
  minutes, two more refusals: the pair must be re-planned and served
  (and, passing, when another command held the lock instead, the slot
  is kept: re-plans stay at most one per 10 minutes);
- passing (the review's untested paths): a re-plan whose stop went
  through and whose parts then don't start again keeps the start; and
  in every case the start is put back while the re-plan still holds the
  command lock (checked at the moment of the restore).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of #1889 (§4, nit 3). The memory re-plan comes due when a part
ends, so also on the end of a part the owner's `darkbloom stop` stopped;
it then does nothing, but its trigger had set the next slot 10 minutes
ahead. An owner who started the pair again within those minutes, with a
split that still doesn't fit, got no re-plan: the parts kept being
refused at load until the slot passed.

When the re-plan finds the pair's start cleared (the owner stopped it),
it now gives its slot back: the owner's next start is re-planned at its
next two refusals. A re-plan put off by a busy lock or ended by a
failure keeps the slot, so re-plans stay at most one per 10 minutes.

The comment on the restore says why it stays before the command lock is
let go; the tests now check it there.

Docs: architecture/inference.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan308
jonathan308 marked this pull request as ready for review November 8, 2026 03:12
@jonathan308
jonathan308 merged commit ca93d05 into dev Nov 8, 2026
46 of 48 checks passed
jonathan308 added a commit that referenced this pull request Nov 8, 2026
…ruth

No conflicts. #1895 brings F2 (the following Mac's verdict), which this branch's
words (`start --solo` / `start` in `ClusterPairWatch.line`) sit beside;
#1896's one port per Mac and #1889's memory replan touch none of this branch's
decisions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Nov 8, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Nov 8, 2026
Brings #1896, #1889, #1895 and #1892 in, so the review's fixes for #1896's
new long-form line apply to today's code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Nov 8, 2026
…elay

One conflict, in ClusterService.swift: #1889's replanForMemory sits where relayTick's doc comment was. Both sides are
kept: #1889's function, then this branch's relayTick doc comment in place of dev's older one.

#1896's two pending LS-3 markers (one port per Mac for a pair's API, LocalAPIPort.thisMac) are left for the port
change that follows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch had an error being deployed

2 failed and 3 active deployments
Preview – d-inference-landing — 55763229 Deployed Nov 8, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — 55763229 Deployed Nov 8, 2026 by vercel[bot]
Preview – darkbloom-status — 55763229 Deployed Nov 8, 2026 by vercel[bot]
Preview – d-inference — 55763229 Deployed Nov 8, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 55763229 Deployed Nov 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant