Skip to content

cluster: drop the model's file cache before a part starts and before a load reads it (MiMo on 128 GB Macs) - #1768

Merged
jonathan308 merged 4 commits into
devfrom
fix/cluster-drop-model-cache-before-load
Nov 4, 2026
Merged

jonathan308 merged 4 commits into
devfrom
fix/cluster-drop-model-cache-before-load

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This fixes the memory-gate loop that kept MiMo V2.6 Flash from ever serving on two 128 GB Macs. On 2026-11-01 a pair of
M4 Max 128 GB MacBook Pros running provider 0.10.6 was refused 680 times out of 680 starts over six hours, all
memory_gate_refused ("needs 25.79 GiB, has 0.09"). It served only once a background job on both Macs cleared MiMo's files
from the file cache every second. The same cause refused a 16 GB Qwen3.8 27B rank once on our 128 GB M5 Max (2026-11-03
23:48:44Z):

Tensor-parallel shard load needs 49.08 GiB of admissible memory and has 0.17 GiB: 0.17 GiB free plus no file cache:
515 MiB was compressed and 0 MiB swapped out since its first check (limits 512 and 64 MiB), so the kernel is taking anonymous memory

Cause.

  • The load gate counts free pages plus every file-backed page, and counts no cache once a load has compressed more than
    512 MiB.
  • Every part start, including every retry, read the whole model folder into the file cache (prefetchPagesInBackground,
    since db88e554c8): 161 GiB for MiMo.
  • A rank loading 76–82 GiB against a cache that is mostly its own model makes macOS free that cache page by page, which means
    compressing other memory. The guard fires and the start is refused. Then the part restarts, the prefetch refills the cache,
    and the cycle repeats.

Fix.

  • The part start drops instead of prefetching. Before the part starts, the service drops the model folder's cached
    pages, including one folder down (MiMo's audio_tokenizer/) and never through a link. The prefetch is removed.
  • Each load drops what it is about to read. VerifiedCheckpoint.bypassTensorPayloadCache() drops each weight file's
    cached pages through its pinned descriptor. That covers MiMo, Qwen, Gemma and GPT-OSS, pipeline and tensor parallel.
    GLM's prepared load is unchanged on purpose.
  • Observability only. The worker writes one darkbloom-load-memory-v1 line per load gate: the rule, the figures and the
    compression since the first sample. The next refusal explains itself.
  • Unchanged: the gate's rules, the 512 MiB limit and the placement. There is no purge or sudo, the files are never
    changed, and only the model's own files are dropped.

Linked issue

None filed. Field report: Dylan's MiMo pair, 2026-11-01. Our M5 Max refusal: pair 2 validation, 2026-11-03.

Test plan

  • Red on dev with only the tests added (4b1c5be34b), green with the fix (a7dbb1f870):

    • ClusterServicePartStartCacheTests runs the real service loop, with the follower's part as /usr/bin/true. Its model
      folder (a 64 MiB weight file and a 32 MiB file in audio_tokenizer/) is read into the cache first. On dev, both
      files are 100 % in the file cache when the part starts
      ; with the fix, under 10 %, with their bytes unchanged. 5 of 5
      repeats.
    • CheckpointChecks/run.sh and CheckpointPayloadCacheTests check what happens after bypassTensorPayloadCache. On dev
      the weight file stays 100 % resident. With the fix it is under 10 %, config.json keeps its page, checkUnchanged()
      passes, and the aligned read returns the original bytes.
    • ClusterModelProvisioningChecks/run.sh: the drop covers one folder down, no link and nothing deeper (dev: the
      subfolder's file was not dropped).
    • StageLoadFileCacheGuardTests covers the log line's rule and figures, including the M5 Max refusal shape.
  • Green before and after:

    • ObservabilityChecks: 212, now including a check that the new line in a worker tail is never classified as a failure;
    • ClusterServiceRecoveryTests: 7 of 7;
    • the gate suites StageLoadFileCacheAdmissionTests, StageLoadFileCacheGuardTests and StageLoadMeasurementModeTests:
      35 of 35;
    • the provisioning download cache check: 4 of 4.
  • The provider build of every product and test passes, and the worker module typechecks against it.

  • make docs-check, make docs-impact-check BASE=origin/dev and make changelog-check pass, and
    git diff --check is clean.

  • Hardware, in progress (0.10.8 candidate on the owner's pairs; this fix ships together with cluster: judge a Mac's memory by the load gate's rule and the GPU limit (MiMo on 128 GB Macs, mixed pairs) #1767):

    • pair 2: Qwen 27B tensor parallel, public and local plans, 10 starts each with the folder pre-cached, plus Gemma
      pipeline;
    • MiMo 24/24 on a 128 GB pair with the evict job unloaded.
      The numbers to watch are in the candidate's plan: residency to about 0 at the part start, the "Compressions" delta under
      32,768 pages, and refused=0.
  • Validator fix d036b3f970: parallel test isolation. Run in one test process beside the new
    ClusterServicePartStartCacheTests, ClusterServiceRecoveryTests counted the other suite's power assertions
    (macOS keeps them per process). CI runs the suites serially, so it was green. Each suite's service now uses its
    own assertion name (ClusterService(powerAssertionReason:), default unchanged). Both suites pass together in
    parallel 5 of 5 (failed at 2e768bffd5); each alone 7/7 and 1/1; ClusterServicePowerAssertionTests 5/5.

Components touched

  • provider-swift (Swift CLI): ClusterService, ClusterModelProvisioning
  • native runtime / MLX: VerifiedCheckpoint, QwenDenseStageLoadAdmissionSummary, the worker's WorkerMain
  • landing (Next.js)
  • enclave (Swift)
  • CI / provider release
  • docs

Protocol / interface changes

  • No protocol/interface changes. The worker log gains one line format, darkbloom-load-memory-v1.

Documentation impact

  • Canonical documentation updated: docs/architecture/inference.md, docs/provider/two-mac-cluster.md,
    docs/developer/test.md.

Changelog

  • Added changelog.d/cluster-drop-model-cache-before-load.md and ran make changelog-check.

Notes for reviewers

  • Load time. A load now reads its weights from the SSD, so small models take +1–3 s. A warm GLM tensor-parallel restart
    on 256 GB Ultras loses the warm folder (about 12–14 s becomes 19–22 s, by db88e554c8's estimate). Not starting at all
    cost more.
  • Remaining risk. The gate still counts other programs' cache. A busy Mac can still trip the guard reclaiming that, and
    the refusal is now self-explaining. Counting only the cache above the kernel minimum is a later policy change, and it must
    not land before this one.
  • The room-making pass (QwenDenseStageLoadReclaim) has not been able to run since 58d7371a. It is documented as
    such and left for removal with the model-fit branch, whose files cite it.
  • Merge order. Land with fix/cluster-model-memory-fit. Its at-rest change offers MiMo on 2× 128 GB, and without this
    fix that offer loops.

Before And After

Behavior, before:

flowchart TD
    A["Part starts (first start or a retry)"] --> B["Prefetch reads the whole model folder into the file cache (161 GiB for MiMo)"]
    B --> C["Worker hashes uncached, then loads its 76-82 GiB share"]
    C --> D["macOS frees the cache page by page and compresses other memory"]
    D --> E["Compressed more than 512 MiB since the first check"]
    E --> F["Gate counts no file cache: needs 25.79 GiB, has 0.09 GiB"]
    F --> G["memory_gate_refused: the part ends"]
    G --> A
Loading

Behavior, after:

flowchart TD
    A["Part starts"] --> B["Service drops the model folder's cached pages (folder and one folder down)"]
    B --> C["Worker hashes uncached; the load drops each weight file's pages before its uncached reads"]
    C --> D["Share loads from the SSD into free pages; nothing to compress"]
    D --> E["Gate admits every decision"]
    E --> F["worker.log: darkbloom-load-memory-v1 ... refused=0 ... compressed_since_first small"]
    F --> G["Rank ready; the pair serves"]
Loading

Code flow, before:

flowchart LR
    S["ClusterService.supervise"] --> P["ClusterModelStore.prefetchPagesInBackground"]
    P --> T["Thread: prefetchPages, 4 readers of 8 MiB preads"]
    S --> R["Process.run"]
    W["Worker stage or TP load"] --> V["VerifiedCheckpoint.bypassTensorPayloadCache"]
    V --> N["F_NOCACHE and F_RDAHEAD only: cached pages still serve the reads"]
    W --> X["Refusal: only the error sentence reaches worker.log"]
Loading

Code flow, after:

flowchart LR
    S["ClusterService.supervise"] --> D["ClusterModelStore.dropCachedPages: openat with O_NOFOLLOW, mmap and msync(MS_INVALIDATE)"]
    D --> H["beforePartStart"]
    H --> R["Process.run"]
    W["Worker stage or TP load"] --> V["VerifiedCheckpoint.bypassTensorPayloadCache"]
    V --> N["F_NOCACHE and F_RDAHEAD, then File.dropCachedPages on the pinned descriptor"]
    M["WorkerMain after the load or at its failure"] --> L["WorkerLoadMemory.write: one logLine per load gate"]
Loading

Refactor Pass

A dedicated refactor subagent reviewed the finished fix (2e768bffd5, one signed commit, 5 files, +14/−20). The
changes are behavior-preserving: no rule, limit, log format, test or assertion changed, and the same system calls run on
the same files in the same order.

  • Removed dead return values. VerifiedCheckpoint.File.dropCachedPages() and bypassTensorPayloadCache() no
    longer return a byte count. Every caller and test discarded it, so bypassTensorPayloadCache() keeps dev's
    signature.
  • Named the file helper. The private one-file helper is now ClusterModelStore.dropCachedPages(ofFile:in:), so its
    call sites no longer read like the folder overload.
  • Corrected a comment. The part-start comment in ClusterService said every load reads uncached. GLM's
    tensor-parallel load reads through the cache on purpose (its prepared path), as the architecture doc already says.
  • Precise references. logLine's doc names the classifier type ClusterFailureClassifier. The test guide's run line
    for ClusterServicePartStartCacheTests no longer points to a sandbox profile that is not in the repository.

Reviewed and left unchanged:

  • The folder-drop structure. One walker and one helper, folder plus one level, O_NOFOLLOW at every open, nothing
    deeper.
  • File.dropCachedPages()'s handling of edge cases: zero-length files, mapping failure and truncation.
  • The darkbloom-load-memory-v1 field set. Its rules follow QwenDenseStageLoadPolicy.decide's order; it is pinned
    byte for byte by two tests and matches no incident rule.
  • The doc sentence on the dead QwenDenseStageLoadReclaim pass. It is accurate; the pass stays for removal after
    fix/cluster-model-memory-fit lands.

Rerun after the pass:

  • Provider: ClusterServicePartStartCacheTests (5 of 5 repeats) and ClusterServiceRecoveryTests (7 of 7), both
    sandboxed.
  • Checkpoint and provisioning: CheckpointChecks (4 groups), ClusterModelProvisioningChecks (148 plus the
    download cache check's 4).
  • Gate and classifier: ObservabilityChecks (212), the gate suites (35 of 35) and CheckpointPayloadCacheTests
    (1 of 1), the last two through scratch harnesses.
  • Build and docs: the provider build, make docs-check, make docs-impact-check, make changelog-check and
    git diff --check.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

jonathan308 and others added 3 commits November 3, 2026 16:51
…the file cache

Checks that go red on dev (0f99ddb):

- ClusterServicePartStartCacheTests: the actual service loop starts the
  follower's part with its model folder (a 64 MiB weight file and a 32 MiB
  file in audio_tokenizer/) read into the file cache. At beforePartStart
  both must be under 10 % resident, and their bytes unchanged. On dev
  both are 100 % resident: the part-start prefetch keeps them cached.
- ClusterModelProvisioningChecks: dropCachedPages drops regular files one
  folder down too, never through a link, nothing deeper. The prefetch
  checks go with the prefetch.
- CheckpointPayloadCacheCheck, run by CheckpointChecks/run.sh and by
  CheckpointPayloadCacheTests in the runtime tests: after
  bypassTensorPayloadCache a weight file read into the cache is under
  10 % resident, config.json keeps its page, checkUnchanged passes and
  the uncached aligned read returns the original bytes. On dev the
  weight file stays 100 % resident.
- StageLoadFileCacheGuardTests: the darkbloom-load-memory-v1 line names
  the rule that settled a load gate and the figures of the decision it
  rests on (the 2026-11-03 M5 Max refusal: 515 MiB compressed).
  ObservabilityChecks: that line in a worker's tail is never read as a
  failure (green before and after).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fore a load reads it

MiMo V2.6 Flash never served on two 128 GB M4 Max Macs: 680 of 680
starts were refused by the load gate ("needs 25.79 GiB, has 0.09"). A
16 GB Qwen 27B rank was refused once on a 128 GB M5 Max ("0.17 GiB free
plus no file cache: 515 MiB was compressed ... limits 512 and 64 MiB").

The gate counts free pages plus every file-backed page, and counts no
cache once a load has compressed more than 512 MiB. Every part start
(and every retry) read the whole model folder into the file cache
(prefetchPagesInBackground, db88e55). Loading a share against a
cache that is mostly its own model makes macOS free it page by page by
compressing other memory, so the guard fired, the start was refused,
the part restarted, the prefetch refilled the cache, and so on.

- A. ClusterService.supervise drops the model folder's cached pages,
  synchronously, before this Mac's part starts, instead of reading them
  in. ClusterModelStore.dropCachedPages also drops regular files one
  folder down (MiMo's audio_tokenizer/), opened through the folder's
  descriptor, never through a link. prefetchPages,
  prefetchPagesInBackground and ClusterModelPrefetchFolders go: nothing
  else used them. The comments that said the gate can count that cache
  are corrected.
- B. VerifiedCheckpoint.bypassTensorPayloadCache drops each weight
  file's cached pages through its pinned descriptor when it turns the
  payload reads uncached. The MiMo, Qwen, Gemma and GPT-OSS pipeline and
  tensor-parallel loads take this path; GLM's prepared load still reads
  through the cache on purpose.
- C. Observability only: QwenDenseStageLoadAdmissionSummary.logLine,
  and the worker writes one darkbloom-load-memory-v1 line per load gate
  after the load or before the failure that ended it (rule, required,
  admissible, free, file-backed, counted, kernel minimum, compression
  and swap-out since the first sample). Its words match no incident
  rule. The dead room-making pass stays, for the reasons in the report.

Both drops use msync(MS_INVALIDATE) over a read-only shared mapping: no
privileges, no purge, the files' bytes and identity unchanged, and only
the model's own files. The gate's rules, its 512 MiB limit and the
placement are unchanged. A load now reads its weights from the SSD, a
few seconds more on a warm restart.

Docs: inference.md (the gate), two-mac-cluster.md, test.md. Changelog:
cluster-drop-model-cache-before-load.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Behavior-preserving cleanup of the cache-drop fix (the required refactor
pass). The same system calls run on the same files, in the same order.

- VerifiedCheckpoint: File.dropCachedPages() and
  bypassTensorPayloadCache() no longer return a byte count. Every caller
  and test discarded it, so bypassTensorPayloadCache() is back to dev's
  signature. The drop is still mmap(PROT_READ, MAP_SHARED),
  msync(MS_INVALIDATE) and munmap on the pinned descriptor, best effort.
- ClusterModelStore: the private one-file helper is now
  dropCachedPages(ofFile:in:), so the call sites say which file and
  which directory, and it no longer reads like the folder overload.
- Comments and docs:
  - ClusterService: the part-start comment said every load reads
    uncached. GLM's tensor-parallel load reads through the cache on
    purpose (keepFileCache on the product's prepared path), as
    docs/architecture/inference.md already says.
  - logLine's doc comment names the classifier type,
    ClusterFailureClassifier; ClusterIncidentGuidance is its file.
  - docs/developer/test.md: the run line for
    ClusterServicePartStartCacheTests pointed to a sandbox profile that
    is not in the repository. It now reads like its neighbours.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan308
jonathan308 requested a review from davidtai November 4, 2026 01:09
@vercel

vercel Bot commented Nov 4, 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 4, 2026 2:38am UTC
d-inference-console-ui-dev Error Error Nov 4, 2026 2:38am UTC
d-inference-landing Ready Ready Preview Nov 4, 2026 2:38am UTC
darkbloom-status Ready Ready Preview Nov 4, 2026 2:38am UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 4, 2026 2:38am UTC

Request Review

Run in one test process in parallel (local `swift test`'s default),
ClusterServiceRecoveryTests failed every time beside the new
ClusterServicePartStartCacheTests (validator, 3 of 3). Both run the real
service loop. While serving, each service holds IOKit assertions named
"Darkbloom cluster: serving deployment". The recovery test counts this
process's assertions by that name. macOS keeps assertions per process, so
it saw the other suite's too: `serviceAssertionTypes() == held` and
`.isEmpty` failed (:150, :155). Each suite already had its own home,
paths, pairing, part process and temporary folders. The assertions were
the only state they shared, and they are process-wide.

- ClusterService takes the assertions' name as an internal init parameter
  (`powerAssertionReason`). The default is
  ClusterServicePowerAssertions.servingReason, the unchanged production
  name.
- The recovery lifetimes test gives its service a name of its own and
  counts only that name. The part-start test names its service apart too,
  as ClusterServicePowerAssertionTests already do. No .serialized is
  needed across suites.

Both suites together in parallel: 5 of 5 pass (red before: 2 issues).
Each alone: 7/7 and 1/1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan308
jonathan308 merged commit 4ada265 into dev Nov 4, 2026
24 of 26 checks passed
jonathan308 added a commit that referenced this pull request Nov 4, 2026
Brings #1763, #1765, #1764, #1770, #1772, #1767, #1768, #1769 and #1766 from dev. One conflict, in
docs/provider/two-mac-cluster.md (2 hunks): before "## Undo", #1774's "Stopping and starting again",
then #1770's "Pairing again"; Undo keeps #1770's opening, #1774's --service sentences, the Uninstall
link, and #1772's "## Uninstall" section as written. Resolution verified in a dry run (tree 4737f00).

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

# Conflicts:
#	docs/provider/two-mac-cluster.md

This branch had an error being deployed

2 failed and 3 active deployments
Preview – eigen-homepages-darkbloom — d036b3f9 Deployed Nov 4, 2026 by vercel[bot]
Preview – d-inference-landing — d036b3f9 Deployed Nov 4, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — d036b3f9 Deployed Nov 4, 2026 by vercel[bot]
Preview – d-inference — d036b3f9 Deployed Nov 4, 2026 by vercel[bot]
Preview – darkbloom-status — d036b3f9 Deployed Nov 4, 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