Skip to content

provider(ssd-cache): queue up to six SSD prefix-cache writes - #1584

Merged
Gajesh2007 merged 2 commits into
masterfrom
provider/ssd-write-queue-six-jobs
Oct 24, 2026
Merged

Gajesh2007 merged 2 commits into
masterfrom
provider/ssd-write-queue-six-jobs

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Summary

The provider's two SSD prefix-cache writers each held only 2 donations before dropping new ones as write_queue_full. The public cache status (GET /v1/cache/status, totals since the coordinator's last restart) showed 53,283 write_queue_full drops against 141,723 donations written. Each drop is a prefix that a later request has to recompute instead of restoring.

This raises the limit to 6 jobs (SSDPrefixCachePolicy.writeQueueMaxJobs = 6, was 2) for both writers:

  • Attention blocks (SSDWriteBehind, built in SSDPrefixCache.init).
  • Complete checkpoints (SSDHybridCheckpointStore). Its literal 2 and its 1-slot writer buffer now both use the same constant.

The byte caps and memory-ledger charges are unchanged.

Linked issue

None. The repository owner asked for this after reviewing production cache-routing telemetry.

Test plan

  • swift build --build-tests (provider-swift).
  • Focused suites, run with the runner's state isolation and skip list (--no-parallel): SSDHybridCheckpointStoreTests, SSDCheckpointFleetWritePriorityTests, SSDSharedProcessCheckpointTests, SSDPrefixCacheTests, SSDPrefixCacheDonationGateTests and SSDPrefixCacheTelemetryTests. Result: 136 tests in 18 suites passed, 0 failures. ../scripts/run-nested-suite.sh stageDelta --no-parallel also passed.
  • Every suite under Tests/ProviderCoreTests/KVCacheSSD/ (both passes): 385 tests in 68 suites passed, plus the runner-isolated SSDShorterNativeBlockRestoreTests, SSDNativeCheckpointOracleTests and stageDelta. One env-gated skip (realDonationHashPreparation()), the same as the baseline.
  • The new tests catch the bug.
    • With only the three source files reverted to master, all five regression tests fail.
    • With the store's buffer set to writeQueueMaxJobs - 1, only bufferAcceptsJobAdmittedDuringSettlement fails, which is the window it targets.
    • The new and changed tests passed 15 of 15 repeated runs.
  • Full scripts/run-provider-tests.sh, first pass. Every failure came from MiMo fixtures being absent (unset MIMO_*). With the documented MiMo fixtures prepared, those classes ran 111 tests with 0 failures. Everything else passed, including the exclusive GPU test.
  • make docs-check (196 files OK).
  • make docs-impact-check BASE=origin/master (11 changed files, coverage OK).
  • make changelog-check and make changelog-preview.
  • Not run: MiMo native/audio lanes, live-model or weights qualification, and a release build.

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. Donation outcome strings, telemetry, config keys and CLI flags are unchanged.
  • Yes — described above and matching side updated

Documentation impact

  • Canonical documentation updated: docs/reference/ssd-kv-cache.md now has one row per write queue, with its limit, its memory bound and the stream-end effect.
  • No documentation needed — reason:

Changelog

  • Added this PR's unique changelog.d/ssd-write-queue-six-jobs.md fragment and ran make changelog-check.
  • No user-visible change, or an explicitly authorized release/history change.

Notes for reviewers

Memory bounds. The job count was never the only memory bound, so neither path's worst-case memory grows without limit.

  • Attention blocks: queued host bytes must still fit max(writeQueueMaxBytes, maxStageBytes + writeQueueSlackBytes), which is 1,280 MiB at the default stage cap.
    • At typical prompt sizes the job count binds before the byte cap. For example, a 3.2k-token Gemma 4 donation is about 63 MB, so six take about 377 MB.
    • Typical queued host RAM under backlog can therefore grow up to 3×, never past the cap.
  • Complete checkpoints: a queued job holds donor state that stays charged to the engine admission ledger until the donor's checkpoints settle.
    • Process-memory-owner and diffusion donors also reserve 20 MiB of host I/O first. Up to 6 such reservations now means 120 MiB instead of 40 MiB.
    • When the ledger is full, a donation settles host_memory_unavailable; a new test covers this.

Writer buffer capacity changed from 1 to writeQueueMaxJobs. A buffered job keeps its writing entry, so a buffer as deep as the prepareWriteJob gate never drops a job that gate admitted. The old 1-slot buffer could drop an admitted job in one window: after the writer had settled one job but before it dequeued the next. The refactor pass confirmed the reasoning against BoundedSingleConsumerPipeline: the consumer dequeues before it awaits consume, and settle is the only remover. The post-submit write_queue_full branch is now a defensive fallback; closeAndQueue still exercises it with a 1-slot test pipeline.

Trade-offs, in order of how much they matter:

  1. Stream-end latency under backlog. A complete-checkpoint donor ends its stream only after all of its checkpoints settle. Each checkpoint can now wait behind 5 other writes instead of 1.
    • A measured 464 MB write took 112.3 ms, so this is roughly 0.11 s becoming about 0.56 s at that size.
    • Large-memory Macs can stage checkpoints of up to 7 GiB, so the tail can be much longer under sustained backlog. This is not measured.
  2. Longer-held KV. Up to 6 donors (was 2) can keep their KV and admission scratch charged while they wait. That lowers free KV and token budgets for new requests during a backlog; the ledger still bounds it.
  3. More SSD writes. More successful donations spend SSD endurance and the daily write budget faster, so write_rate_limited and write_priority_limited may appear sooner.

Follow-ups to consider after rollout:

  • Confirm that write_queue_full falls in production telemetry.
  • Watch stream-end latency for complete-checkpoint models.
  • If that tail matters, give complete checkpoints a separate, smaller bound.

Before And After

Behavior

flowchart LR
  subgraph Before
    A1["request finishes; its prefix is donated"] --> Q1{"fewer than 2 jobs waiting?"}
    Q1 -- yes --> W1["written to SSD, so a later request restores it"]
    Q1 -- no --> X1["dropped as write_queue_full, so a later request recomputes the prompt"]
  end
  subgraph After
    A2["request finishes; its prefix is donated"] --> Q2{"fewer than 6 jobs waiting? (attention jobs also need byte-cap room)"}
    Q2 -- yes --> W2["written to SSD, so a later request restores it"]
    Q2 -- no --> X2["dropped as write_queue_full"]
    W2 -. "complete-checkpoint donor" .-> L2["stream end and KV release wait for its checkpoints: up to 5 writes ahead instead of 1"]
  end
Loading

Code

flowchart TB
  subgraph Before
    P1["SSDPrefixCachePolicy.writeQueueMaxJobs = 2"] --> WB1["SSDPrefixCache.init: SSDWriteBehind maxJobs = 2, byte cap 1,280 MiB"]
    G1["SSDHybridCheckpointStore+Write prepareWriteJob: literal 2-job gate"] --> B1["SSDHybridCheckpointStore.init: BoundedSingleConsumerPipeline capacity 1"]
  end
  subgraph After
    P2["SSDPrefixCachePolicy.writeQueueMaxJobs = 6"] --> WB2["SSDPrefixCache.init: SSDWriteBehind maxJobs = 6, byte cap unchanged"]
    P2 --> G2["prepareWriteJob: gate uses writeQueueMaxJobs"]
    P2 --> B2["SSDHybridCheckpointStore.init: pipeline capacity writeQueueMaxJobs"]
  end
Loading

Refactor Pass

A dedicated, independent refactor reviewer read the first version (657406eaf) and added one signed commit (78c904a42). No source logic changed.

  • Confirmed that the buffer must be exactly as deep as the gate, not one less, from the code.
  • Added bufferAcceptsJobAdmittedDuringSettlement. It holds the settle-to-dequeue window open and fails with a writeQueueMaxJobs - 1 buffer. No earlier test covered that window.
  • Replaced two near-identical local donation helpers with one shared SSDHybridCheckpointTestFixture.startDonation; every assertion is unchanged.
  • Corrected two comments: a donor waits for all of its checkpoints, and releases its KV only after they settle.
  • Added the held-KV limitation to the changelog.
  • Kept, with reasons: the helper extraction in SSDPrefixCacheTests.swift (two callers, inside its suite), the docs rows, and the changelog format.

After the refactor commit, the final validation in the test plan was rerun on 78c904a42: build, focused suites, isolated stageDelta, docs and changelog checks.

🤖 Generated with Claude Code


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

Gajesh2007 and others added 2 commits October 23, 2026 21:57
Both SSD prefix-cache write queues refused new donations as
write_queue_full at two jobs, so busy providers dropped prefixes they
could otherwise have reused. Raise SSDPrefixCachePolicy.writeQueueMaxJobs
from 2 to 6 and make the complete-checkpoint store use it instead of
literals: its writer gate admits six unsettled jobs, the one being
written included, and its pipeline buffer is as deep as that gate, so
the gate is the only queue refusal. Previously the one-job buffer could
refuse a job the gate had admitted after the writer settled one job and
before it took the next.

The memory bounds are unchanged. Attention-block jobs must still fit the
queued-byte cap (1,280 MiB at the default stage cap), and the job being
written still leaves both counts. A queued complete checkpoint holds only
donor state that stays charged to the engine admission ledger and I/O
scratch reserved before queueing. Because the engine delivers a donor's
terminal after its checkpoints settle, a write backlog now delays stream
end by up to five earlier writes per checkpoint instead of dropping it.

Tests: the attention cache queues six donations behind a blocked writer
and settles the seventh as write_queue_full; at the production limits the
queued-byte cap still refuses a job while a job slot is free; the fleet
demand test now fills the six-job bound; and queued complete writes keep
their host reservations, so the process ledger refuses before the job
bound. The SSD KV cache reference documents both queues, with a changelog
fragment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refactor-pass follow-up to the six-job SSD write queue.

The complete-checkpoint pipeline buffer is as deep as the writer gate so
that a job the gate admits after the writer settles one job, but before
it dequeues the next, is buffered rather than dropped. No test held that
window open: the six-job fleet test still passes with a buffer one
shallower than the gate. Add one that blocks the first job's completion
callback, which runs after settle frees its writing entry, and checks
that the sixth admitted job is buffered and written.

Share the queued-donation helper that the six-job and host-ledger tests
each defined locally as SSDHybridCheckpointTestFixture.startDonation,
which the new test also uses. Name the gate and the window in the
pipeline comment, and note in the policy comment and the changelog that
a donor's stream end and KV release wait for all of its checkpoints, so
up to six waiting donors (was two) can hold KV memory at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Gajesh2007 Gajesh2007 added area:provider Provider (Rust, runs on Apple Silicon) area:docs Documentation work specific to a component or feature labels Oct 24, 2026
@vercel

vercel Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
d-inference Ready Ready Preview Oct 24, 2026 5:34am UTC
d-inference-console-ui-dev Ready Ready Preview Oct 24, 2026 5:34am UTC
d-inference-landing Ready Ready Preview Oct 24, 2026 5:34am UTC
darkbloom-status Ready Ready Preview Oct 24, 2026 5:34am UTC
eigen-homepages-darkbloom Ready Ready Preview Oct 24, 2026 5:34am UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T05:36:00.537679Z 78c904a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head 78c904a427c4 against base 9034a5a0f352.

Reviewers: anthropic/claude-sonnet-5.5: first pass completed; anthropic/claude-opus-5.5: selected depth completed (1 batches); openai/gpt-6.1-sol: not needed by escalation policy

No actionable findings in the reviewed text. This is not a security approval.

Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging.

Scan completed.

Coverage: 59/59 source units; cross-file integration complete. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned.

Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 0 reused batch(es), 0 provider cache-hit tokens.

Saved findings and earlier report · Historical findings are not confirmed resolved.

Bedrock: 16 request(s), 775997 uncached + 0 cache-read + 0 cache-write input / 12324 output tokens; 0 request(s) with unknown usage. OpenRouter backup used 0 time(s). Dollar amounts above cover OpenRouter only; AWS billing is reconciled separately.
Workload allowance: 17 native request(s), including one shared response repair; 500 emergency ceiling. Selected depth and integration rounds are admitted as their scope becomes known.

jonathan308 added a commit that referenced this pull request Oct 24, 2026
…features

Queue up to six SSD prefix-cache writes (SSDPrefixCachePolicy.
writeQueueMaxJobs = 6, was 2) for both writers: attention blocks
(SSDWriteBehind) and complete checkpoints (SSDHybridCheckpointStore,
whose gate and writer buffer now both use the constant). Approved head
78c904a.

Owner decision: one shared write-queue depth for every model. #1589's
GLM-only depth is folded into #1584's constant:
- SSDHybridCheckpointStore+Write.swift (conflict): the prepareWriteJob
  gate is #1584's writing.count < writeQueueMaxJobs (six unsettled jobs,
  the one being written included), not #1589's per-store
  writing.count <= config.writeQueueJobs.
- SSDHybridCheckpointStore.swift (conflict): #1590's stage-cost
  initializer, then #1584's comment and writer buffer
  (capacity: writeQueueMaxJobs). #1589's Config.writeQueueJobs is removed.
- SSDHybridCheckpointStoreFactory.swift / SSDPrefixCachePolicy.swift:
  #1589's GLM override (glm5NextCompleteCheckpointWriteQueueJobs = 8,
  completeCheckpointWriteQueueJobs(backendLayout:)) and its MLXLMCommon
  import are removed.
- docs/reference/ssd-kv-cache.md (conflict): #1584's attention and
  complete-checkpoint queue rows; #1589's GLM-only row is dropped.
- changelog.d/glm-capture-under-load.md: the eight-deep GLM queue bullet
  is dropped (ssd-write-queue-six-jobs.md states the shared depth).
- Tests: #1589's SSDCheckpointWriteQueueTests (GLM 8 / others 1 and a
  three-deep store) is removed; #1584's fleet-priority and
  writer-buffer tests cover the shared bound. The fixture loses #1589's
  writeQueueJobs parameter, and GLM5NextProtectedFactoryTests now checks
  that the GLM store's writer buffer is the shared writeQueueMaxJobs.

#1589's capture-boundary partition and GLM adopters' ordinary chunking
are unchanged.
@Gajesh2007
Gajesh2007 merged commit ca71b15 into master Oct 24, 2026
29 checks passed
@Gajesh2007
Gajesh2007 deleted the provider/ssd-write-queue-six-jobs branch October 24, 2026 19:35
jonathan308 added a commit that referenced this pull request Oct 24, 2026
Conflicts were the LanguageModel.prepare(state:prefill:) port that #1596 and this branch's a790a86 both made (formatted differently) and #1584's write-queue lines, which this branch already carries with its documented resolution. Kept this branch's side for the conflicting hunks; master's other hunks apply (MLXLLM.Gemma4 qualification, ThroughputSweep async throws, #1596's changelog fragment). libs/mlx-swift-lm moves to the final 0.10.2 SDK set aee6ebb6, which contains master's 476cb7c0 and the previous pin bc4e5f57 (library source identical). libs/mlx-swift eedca444 and libs/mlx ff4bb35b match master.
@jonathan308 jonathan308 mentioned this pull request Oct 24, 2026
6 of 10 tasks
jonathan308 added a commit that referenced this pull request Oct 25, 2026
Set ProviderCore.version to 0.10.2 and render the v0.10.2 changelog
entry from the 27 fragments added since v0.10.1, ordered by theme behind
an upgrade and rollout section: Nemotron 3.5 Super prefix caching
(#1586, #1588); GLM-5.3-Flash prefix caching (#1587, #1589, #1590);
4-bit SSD checkpoints and the SSD prefix cache on every model (#1592
(mlx-swift-lm#363), #1584, #1592); Logprobs on Nemotron 3.5 Super and
GLM-5.3-Flash (#1564); OpenRouter compatibility: GLM-5.3-Flash and
MiMo-V2.6-Flash requests no longer refused (#1585, #1592); Speed: MTP
and throughput (#1592 (mlx-swift-lm#360), #1593 (mlx-swift-lm#357),
#1595 (mlx-swift-lm#359), #1594, #1595, #1598 (mlx-swift-lm#362),
#1594); Provider diagnostics: refusal reasons and load memory (#1592,
#1603); MLX stack (#1596); Desktop release workflow (#1580). Apply 12
corrections reviewed against the code. #1580 is already in the v0.10.1
tag but merged after the 0.10.1 preparation, so its fragment is rendered
here.

Mark v0.10.1 as published on 2026-10-24. Record in the provider release
runbook the SDK pin check, the enablement order (darkbloom-platform#464
before any catalog logprobs change, the GLM allowlist tuple, then both
models' logprobs after the rollout and Super's tuple after a signed
restart check), the platform evidence and the published history. No tag,
registration, upload, deployment or enablement is performed.
jonathan308 added a commit that referenced this pull request Oct 25, 2026
Set ProviderCore.version to 0.10.2 and render the v0.10.2 changelog
entry from the 27 fragments added since v0.10.1, ordered by theme behind
an upgrade and rollout section: Nemotron 3.5 Super prefix caching
(#1586, #1588); GLM-5.3-Flash prefix caching (#1587, #1589, #1590);
4-bit SSD checkpoints and the SSD prefix cache on every model (#1592
(mlx-swift-lm#363), #1584, #1592); Logprobs on Nemotron 3.5 Super and
GLM-5.3-Flash (#1564); OpenRouter compatibility: GLM-5.3-Flash and
MiMo-V2.6-Flash requests no longer refused (#1585, #1592); Speed: MTP
and throughput (#1592 (mlx-swift-lm#360), #1593 (mlx-swift-lm#357),
#1595 (mlx-swift-lm#359), #1594, #1595, #1598 (mlx-swift-lm#362),
#1594); Provider diagnostics: refusal reasons and load memory (#1592,
#1603); MLX stack (#1596); Desktop release workflow (#1580). Apply 14
corrections reviewed against the code. #1580 is already in the v0.10.1
tag but merged after the 0.10.1 preparation, so its fragment is rendered
here.

Mark v0.10.1 as published on 2026-10-24. Record in the provider release
runbook the SDK pin check, the enablement order (darkbloom-platform#464
before any catalog logprobs change, the GLM allowlist tuple, then both
models' logprobs after the rollout and Super's tuple after a signed
restart check), the platform evidence and the published history. No tag,
registration, upload, deployment or enablement is performed.
Gajesh2007 pushed a commit that referenced this pull request Oct 25, 2026
Set ProviderCore.version to 0.10.2 and render the v0.10.2 changelog
entry from the 20 fragments added since v0.10.1, ordered by theme behind
an upgrade and rollout section: Nemotron 3.5 Super prefix caching
(#1586, #1588); GLM-5.3-Flash prefix caching (#1587, #1589, #1590);
4-bit SSD checkpoints and the SSD prefix cache on every model (#1592
(mlx-swift-lm#363), #1584, #1592); Logprobs on Nemotron 3.5 Super and
GLM-5.3-Flash (#1564); GLM-5.3-Flash OpenRouter request controls (#1585,
#1592); Speed: MTP and throughput (#1592 (mlx-swift-lm#360), #1593 (mlx-
swift-lm#357), #1595 (mlx-swift-lm#359), #1594, #1595, #1598 (mlx-swift-
lm#362), #1594); Provider diagnostics (#1592); MLX stack (#1596);
Desktop release workflow (#1580). Apply 12 corrections reviewed against
the code. #1580 is already in the v0.10.1 tag but merged after the
0.10.1 preparation, so its fragment is rendered here.

Mark v0.10.1 as published on 2026-10-24. Record in the provider release
runbook the SDK pin check, the enablement order (darkbloom-platform#464
before any catalog logprobs change, the GLM allowlist tuple, then both
models' logprobs after the rollout and Super's tuple after a signed
restart check), the platform evidence and the published history. No tag,
registration, upload, deployment or enablement is performed.

Co-authored-by: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com>

This branch was successfully deployed

5 active deployments
Preview – eigen-homepages-darkbloom — 78c904a4 Deployed Oct 24, 2026 by vercel[bot]
Preview – d-inference-landing — 78c904a4 Deployed Oct 24, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 78c904a4 Deployed Oct 24, 2026 by vercel[bot]
Preview – d-inference — 78c904a4 Deployed Oct 24, 2026 by vercel[bot]
Preview – darkbloom-status — 78c904a4 Deployed Oct 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Documentation work specific to a component or feature area:provider Provider (Rust, runs on Apple Silicon)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants