Skip to content

Provider: prompt preparation holds a share of the whole-Mac serving allowance - #2613

Merged
jonathan308 merged 3 commits into
devfrom
fix/prompt-preparation-share
Nov 24, 2026
Merged

jonathan308 merged 3 commits into
devfrom
fix/prompt-preparation-share

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A text request's prompt was rendered and tokenized before the request took its share of the whole-Mac serving allowance, so any number of prompts could be in preparation at once on a Mac whose serving width was already full, each using CPU and memory before being refused at submission.

Now a text request takes one serving share (WholeMacServiceBudget.acquirePreparation, via EngineV2Bridge.acquirePromptPreparation) before its prompt is rendered and tokenized, under the same owner ID its submission uses:

  • A full Mac refuses the request as capacity (the same retriable refusal as at submission) before preparing its prompt.
  • Prompts being prepared at the same time count against the serving width, so preparation is bounded by it.
  • At submission, acquire takes the share over in place, so an admitted request cannot lose its place between preparation and submission and is never counted twice. A share not taken over is returned when preparation ends, on every exit path (defer).
  • Preparation shares count only toward admission: reported usage, deadline work, calibration and idle state still start at submission.
  • The owner's own local requests, which already wait for room at submission (OwnerMemoryWait), take no preparation share. Coordinator and pair requests always do.

Planned follow-up (separate PR): let the owner's local requests wait for a preparation share as well, so their preparation is bounded the same way.

Tests-only control (expected to fail on dev at the new tests): #2612

Behavior

flowchart LR
  subgraph Before
    A1[Text request] --> P1[Render + tokenize prompt]
    P1 --> S1{Serving share free?}
    S1 -- yes --> G1[Serve]
    S1 -- no --> R1[Refuse as capacity, after the work]
  end
  subgraph After
    A2[Text request] --> S2{Serving share free?}
    S2 -- no --> R2[Refuse as capacity, before any work]
    S2 -- yes --> H2[Hold the share]
    H2 --> P2[Render + tokenize prompt]
    P2 --> G2[Submission takes the share over, serve]
    P2 -- fails --> E2[Share returned]
  end
Loading

Code

flowchart TD
  subgraph Before
    PC1[MultiModelBatchSchedulerEngine.prepareCompletion] --> TM1[tokenizeMeasured]
    TM1 --> SUB1[submitTokenized]
    SUB1 --> AC1["WholeMacServiceBudget.acquire(ownerID)"]
  end
  subgraph After
    PC2[MultiModelBatchSchedulerEngine.prepareCompletion] --> AP2["EngineV2Bridge.acquirePromptPreparation(requestID)"]
    AP2 --> PR2["WholeMacServiceBudget.acquirePreparation(ownerID): charges + other preparations + share ≤ 1"]
    PR2 --> TM2[tokenizeMeasured]
    TM2 --> SUB2[submitTokenized]
    SUB2 --> AC2["acquire(ownerID): counts other preparations, converts its own in place"]
    PC2 -. defer .-> END2["PromptPreparationShare.end(): releasePreparation if not taken over"]
  end
Loading

Validation

  • New tests: PromptPreparationAdmissionTests (a full Mac refuses before rendering; a prompt being prepared holds the last share against another request; a prompt prepared on the last share is served on it; a failed render returns its share) and WholeMacPreparationShareTests (occupancy, in-place takeover, once per owner, reporting still starting at acquire, recovery next to another preparation).
  • Red control Red control for prompt preparation share: tests without the change (do not merge) #2612 carries only PromptPreparationAdmissionTests.swift on the same base, using only existing APIs; the first two tests are expected to fail there on behavior, the last two are guards that pass on both.
  • Red/green proof is this PR's CI and the red control's CI (run-ci); no full provider build was run locally.
  • Changelog: changelog.d/prompt-preparation-serving-share.md. Docs: docs/architecture/inference.md, docs/architecture/hardware-support.md.
  • Merges cleanly onto current dev (c579589b3).

Known effects, accepted: a request that fails preparation (bad template, over the window) briefly holds a share; on a full Mac a request whose first-content deadline already passed now gets the capacity refusal instead of the deadline refusal (both retriable 503s).

Refactor pass

Independent refactor pass on this head: no change warranted; locking, in-place takeover, release on every exit path, and the owner-local exemption checked.

Changelog

changelog.d/prompt-preparation-serving-share.md


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

A full Mac refuses a text request as capacity before rendering its
prompt, a prompt being prepared holds the last serving share against
another request, a prompt prepared on the last share is served on it,
and a failed render returns its share.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A text request now takes one serving share before its prompt is
rendered and tokenized, under the owner ID its submission uses. A full
Mac refuses the request as capacity before that work, and prompts being
prepared at the same time count against the serving width. The bridge's
allowance takes the share over in place at submission, so the request
cannot lose its place between preparation and admission; a share not
taken over is returned when preparation ends, on every exit path.

Preparation shares count only toward admission: reported usage,
deadline work and calibration evidence still start at submission. The
owner's local requests, which wait for room at submission, take none.

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

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
d-inference-landing Ready Ready Preview Nov 24, 2026 5:38am UTC
darkbloom-status Ready Ready Preview Nov 24, 2026 5:38am UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 24, 2026 5:38am UTC

Request Review

@jonathan308 jonathan308 added the run-ci Trigger one-shot PR CI run (auto-removed when run starts) label Nov 24, 2026
@github-actions github-actions Bot removed the run-ci Trigger one-shot PR CI run (auto-removed when run starts) label Nov 24, 2026
@jonathan308 jonathan308 added the run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) label Nov 24, 2026
@github-actions github-actions Bot removed the run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) label Nov 24, 2026
@jonathan308 jonathan308 added the run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) label Nov 24, 2026
@github-actions github-actions Bot removed the run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) label Nov 24, 2026
…shes

The preparation admission tests now use a local engine that answers each
request with one token and a stop terminal, so a served request ends
without a stream error and the tests check that it was served.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan308 jonathan308 added run-ci Trigger one-shot PR CI run (auto-removed when run starts) run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) labels Nov 24, 2026
jonathan308 pushed a commit that referenced this pull request Nov 24, 2026
…rve prompt preparation tests on an engine that finishes
@github-actions github-actions Bot removed run-ci Trigger one-shot PR CI run (auto-removed when run starts) run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) labels Nov 24, 2026
@jonathan308 jonathan308 added the run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) label Nov 24, 2026
@github-actions github-actions Bot removed the run-release-ci One-shot: run SDK 27 release and qualification on this PR (removed when the run starts) label Nov 24, 2026
jonathan308 added a commit that referenced this pull request Nov 24, 2026
@jonathan308
jonathan308 merged commit be8e8ea into dev Nov 24, 2026
57 of 61 checks passed

This branch was successfully deployed

3 active deployments
Preview – eigen-homepages-darkbloom — 4b76a0d0 Deployed Nov 24, 2026 by vercel[bot]
Preview – d-inference-landing — 4b76a0d0 Deployed Nov 24, 2026 by vercel[bot]
Preview – darkbloom-status — 4b76a0d0 Deployed Nov 24, 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