Skip to content
Draft
6 changes: 6 additions & 0 deletions changelog.d/deadline-refusal-streak-expiry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### A stale slow prefill estimate stops refusing after three deadline refusals

- A `deadline_unreachable` refusal admits nothing, so it measures nothing. An idle Mac whose only prefill measurement was slow and is now older than 120 seconds could go on refusing from it for up to 30 minutes. After three such refusals in a row with nothing admitted in between, the provider admits the next request of at most 1,024 prompt tokens that finds the Mac idle without a time projection, and that request's prefill replaces the estimate. A longer prompt is still refused until a small request has remeasured the Mac.
- Only refusals the Mac's own isolated prefill rate explains count: the Mac was idle and the projection priced nothing but that request's prompt. Refusals beside other work, refusals for memory or capacity, reviewed calibrations, native-media requests and native block engines (which keep their own recovery probe) are unchanged.
- A request whose deadline has already passed is still refused, and a measurement newer than 120 seconds still refuses as measured. A Mac that really is too slow admits one such small request per loaded model every 120 seconds; that request can miss its first-content deadline where it would have been refused at once.
- No wire field changes. `DARKBLOOM_TTFT_ADMISSION_FIXES=0` turns this off with the other estimator corrections.
14 changes: 11 additions & 3 deletions docs/architecture/hardware-support.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Hardware support and the provider memory model

> Last updated: 2026-11-09
> Last updated: 2026-11-10

What hardware the provider runs on and how it decides, in bytes, whether a
model may load and how much KV cache each resident model may use. Read this to
Expand Down Expand Up @@ -864,9 +864,17 @@ serving Mac, so the same request can project differently on other hardware:
(`provider-swift/Sources/ProviderCore/Inference/Performance/Deadline/AdmissionRateEstimators.swift`,
`IsolatedPrefillAdmissionRate.anchorFloorFraction`). Native engines keep
their recovery probe instead.
- Three consecutive refusals an ordinary engine made on an idle Mac from its
isolated prefill rate alone expire evidence older than 120 seconds
(`provider-swift/Sources/ProviderCore/Inference/Performance/Deadline/AdmissionRateEstimators.swift`,
`DeadlineRefusalStreak`). The next request of at most 1,024 prompt tokens
that finds the Mac idle is submitted without a time projection and
remeasures the rate on that Mac, at that power and thermal state. A longer
prompt is still refused. A refusal for physical capacity never counts.

The anchor and floor shape admission only. The published isolated rate,
capacity wire fields and the external platform's memory contract are unchanged.
The anchor, floor and refusal streak shape admission only. The published
isolated rate, capacity wire fields and the external platform's memory
contract are unchanged.

### Cross-repository agreement

Expand Down
35 changes: 33 additions & 2 deletions docs/architecture/inference.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Provider inference engine

> Last updated: 2026-11-09
> Last updated: 2026-11-10

How a chat-completion request is served inside the `darkbloom` provider
process: one in-process engine (`mlx-swift-lm`
Expand Down Expand Up @@ -2229,7 +2229,7 @@ This removes the previous doubling of projected processing time; an EWMA is a
point estimate and does not guarantee the next request's speed. Actual elapsed
deadline expiry, queue/cache projection and physical admission still apply.

Three estimator corrections shape those inputs;
Four estimator corrections shape those inputs;
`DARKBLOOM_TTFT_ADMISSION_FIXES=0` restores the previous estimators
(`provider-swift/Sources/ProviderCore/Inference/Performance/Deadline/AdmissionRateEstimators.swift`).

Expand Down Expand Up @@ -2289,6 +2289,37 @@ that floor, because the anchor comes from a short calibration cell
evidence expires after 120 seconds. The published isolated rate is unchanged.
A late older cold sample no longer restarts the combined prefill EWMA.

A refusal admits nothing, so it measures nothing: those idle rules are the
only way expired evidence that refuses is replaced, and with no anchor, with an
anchor that is itself slow, or off nominal posture they keep it for 30 minutes.
Ordinary engines therefore count consecutive `deadline_unreachable` refusals
that the isolated prefill rate alone explains
(`provider-swift/Sources/ProviderCore/Inference/Performance/Deadline/AdmissionRateEstimators.swift`,
`DeadlineRefusalStreak`;
`provider-swift/Sources/ProviderCore/Inference/Engine/Bridge/EngineV2Bridge+Admission.swift`,
`EngineV2Bridge.recordDeadlineRefusal`): the Mac was idle, the engine's bounded
projection priced only this request's own prompt, and the policy carried no
reviewed calibration and no native-media rate. A refusal beside other work or
from a fail-closed (unbounded) projection, physical capacity included, never
counts, and any engine admission ends the streak. After three, evidence older
than the 120-second freshness window stops blocking the next request of at
most 1,024 prompt tokens that finds the Mac idle
(`provider-swift/Sources/ProviderCore/Inference/Performance/PrefillEvidenceRecovery.swift`,
`PrefillEvidenceRecovery.maximumPromptTokens`, the native recovery probe's
limit). The bridge builds no projection policy for that request, so it is
submitted the way a request with no measured rate is. Absolute expiry still
applies, the decision profile reports `projection = not_attempted` with
`projection_reason = unmeasured_prefill`, and the request's isolated prefill
replaces the expired aggregate and its prompt-size bucket. A longer prompt is
still refused from the expired evidence and leaves the streak full:
unprojected, it could hold a slow Mac until its deadline. Fresh evidence, a
fresh prompt-size bucket for this prompt included, refuses as measured
however many requests it refuses. An admission that ends a full streak starts
a 120-second retry interval, so a loaded model on a Mac that really is too
slow admits one such small request per interval, even when that request ends
before its prompt completes. That request can miss its first-content deadline
where it would have been refused at once.

An independent reviewed deadline profile carries
`deadline_calibration`: prompt/context bands, actual cold/reused prefix
state, competing profile identities and work limits, phase rates, and a
Expand Down
10 changes: 7 additions & 3 deletions docs/developer/test.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Test Provider And Native Contracts

> Last updated: 2026-11-09
> Last updated: 2026-11-10

Run isolated Swift, native-resource, public-fixture and landing tests here.
Backend integration and cross-implementation qualification are platform-owned.
Expand Down Expand Up @@ -710,8 +710,12 @@ lockouts through the bridge and the real submission path, another model's
lease or device activity on a shared whole-Mac service budget, a fresh
long-prompt bucket below the floor, decode step-shape measurement and plumbing
(including the first-token step's rows), rate and shape kept coupled across
batch widths, the per-row charge kept for reviewed calibrations, and a late
older cold sample. In the SDK, the unit suite
batch widths, the per-row charge kept for reviewed calibrations, a late
older cold sample, and the refusal streak: three idle refusals over stale
evidence admit the next request of at most 1,024 prompt tokens, whose prefill
replaces the estimate, while a longer prompt, fresh evidence, an expired
absolute deadline, a busy Mac, the kill switch and the retry interval keep
refusing. In the SDK, the unit suite
`CBv2PerBatchDecodeChargeTests` pins per-step decode accounting, MTP-measured
shape conversion, the mirrored MTP depth gates (batch gate and automatic
envelope, with a driver check that the ceiling bounds every live plan depth)
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/configuration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configuration reference

> Last updated: 2026-11-08
> Last updated: 2026-11-10

Provider CLI and native-runtime environment variables, compiled defaults and reading symbols. Secrets are named, never valued. Unless specified otherwise, values are read at process start.

Expand Down Expand Up @@ -540,7 +540,7 @@ and rollback are defined in the [provider configuration reference](../provider/c
| `DARKBLOOM_MTP_VERIFICATION_MODE` | `rectangular`, `serial`, `serial_target`, `automatic` | `automatic` | `provider-swift/Sources/ProviderBenchmark/MTPProductionSession.swift` | MTP verification strategy (benchmark session). |
| `DARKBLOOM_MTP_ACCEPTANCE` | `exact`, `typical`, `typical:<delta>` (finite positive delta) | `exact` | `provider-swift/Sources/ProviderBenchmark/MTPProductionSession.swift`; `provider-swift/Sources/ProviderCore/Inference/MTP/MTPAcceptancePolicy.swift` (`benchmarkOverride`) | MTP draft acceptance rule (benchmark session only). An unrecognized value uses `exact`. Serving reads no environment variable for this rule; it reads `[backend] mtp_acceptance` and `mtp_acceptance_by_model` in [`provider.toml`](../provider/cli-reference.md#providertoml-keys-read-by-the-cli). |
| `DARKBLOOM_PREFILL_DEADLINE_MODE` | exactly `off` disables; any other value enforces | `enforce` | `provider-swift/Sources/ProviderCore/Inference/Engine/PrefillDeadlineMode.swift` (`PrefillDeadlineMode.resolve`) | Prefill-deadline admission on the provider. Read only when `[backend] prefill_deadline_mode` is absent from `provider.toml`; that key takes precedence. |
| `DARKBLOOM_TTFT_ADMISSION_FIXES` | `0`, `false`, `off`, `no` disable (trimmed, case-insensitive) | on | `provider-swift/Sources/ProviderCore/Inference/Performance/Deadline/AdmissionRateEstimators.swift` (`DeadlineAdmissionFixes`) | Deadline-admission estimator corrections: per-batch decode charging, anchored isolated-prefill rate, newest-observation freshness. Off restores the previous estimators. Forwarded to the launchd provider job. |
| `DARKBLOOM_TTFT_ADMISSION_FIXES` | `0`, `false`, `off`, `no` disable (trimmed, case-insensitive) | on | `provider-swift/Sources/ProviderCore/Inference/Performance/Deadline/AdmissionRateEstimators.swift` (`DeadlineAdmissionFixes`) | Deadline-admission estimator corrections: per-batch decode charging, anchored isolated-prefill rate, newest-observation freshness, refusal-streak expiry of stale isolated-prefill evidence. Off restores the previous estimators. Forwarded to the launchd provider job. |
| `DARKBLOOM_TTFT_SHAPE_WARMUP` | trimmed, case-insensitive `0`, `false`, `no`, `off` disable; `always` skips the probe | unset: probe-gated warmup | `provider-swift/Sources/ProviderCore/Inference/Performance/ModelCalibrationPolicy.swift` (`shapeWarmupMode`) | Excluded load-time [shape warmup](../architecture/inference.md#model-startup-calibration) for ordinary `EngineV2` slots: a 128-token shader-cache probe runs twice and only a cold cache runs the shape cells, within 20 seconds per engine. Trains no rate or counter. Forwarded to the LaunchAgent. |
| `DARKBLOOM_GEMMA4_PREFILL_CHUNK_EVAL` | integer layers | projected from `provider.toml` (`18`) | `provider-swift/Sources/ProviderCore/Config/GemmaOptimizationEnvironment.swift` | Gemma-4 prefill chunk-eval layers; the provider sets it for the engine, `scripts/install.sh` sets `18` for the smoke test. |
| `DARKBLOOM_TTFT_GDN_BLOCKED` | `0`, `false`, `no`, `off` keep the stock kernel; `packed` or `rows` force that kernel; unset or any other value probes. Case-insensitive; surrounding whitespace is ignored | probe | `libs/mlx-swift-lm/Libraries/MLXLMCommon/GatedDelta.swift` (`GatedDeltaPrefill.mode`, `GatedDeltaPrefill.kernel`) | Selects the Gated DeltaNet prompt-window kernel of `qwen3_5`, `qwen3_5_moe` and `prism_hadamard_qwen35` models ([mechanism](../architecture/inference.md#context)). The default probe keeps a four-row kernel only where it reproduces `gated_delta_step` bit for bit on the GPU; it does not compare speed, so `0` is the rollback where a kept kernel is slower. Forced kernels skip that check and are for A/B measurement only. Decode, MTP verification and masked updates always use the stock kernel. Read once per process. Forwarded to the LaunchAgent. |
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/prediction-decision-telemetry.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Prediction decision telemetry

> Last updated: 2026-10-22
> Last updated: 2026-11-10

Optional attempt records compare what the coordinator selected with what the
provider decided. They explain decisions; they do not establish whether a
Expand All @@ -18,7 +18,7 @@ terminal messages. Sources: [coordinator/protocol/profile_deadline.go](https://g
| `verdict` | `accepted`, `deadline_unreachable`, `expired_before_submit`, `cancelled`, `other`. `cancelled` without a returned verdict does not prove the engine never accepted. |
| `continuation` | `expired`, `cancelled`, `other`, or absent. Annotates a returned verdict when the bridge's immediate continuation is stopped; it does not replace the verdict. |
| `projection` | `bounded`, `unbounded`, `not_attempted`, `other`, or absent. Unbounded is distinct from a measured large duration. |
| `projection_reason` | No service-time prediction: `no_deadline`, `mode_off`, `unsupported_scheduler`, `multimodal`, `unmeasured_prefill`, `other`, or absent. Includes guarded native-media bootstrap; it does not describe an engine projection failure. |
| `projection_reason` | No service-time prediction: `no_deadline`, `mode_off`, `unsupported_scheduler`, `multimodal`, `unmeasured_prefill`, `other`, or absent. Includes guarded native-media bootstrap; it does not describe an engine projection failure. `unmeasured_prefill` also covers a measured rate the provider set aside as expired: idle expiry, or a full refusal streak over stale evidence ([deadlines](../architecture/inference.md#deadlines)). |
| `unbounded_reason` | Optional closed engine cause for `projection=unbounded`, listed below. Missing means the engine supplied no cause; it is never reconstructed from occupancy or remaining time. Unknown future values fold to `other`. |
| `observed_us` | Offset from the provider profile anchor when the bridge receives a verdict or observes pre-submit expiry. **Not the engine's atomic refusal time.** |
| `remaining_us` | Remaining deadline at that provider observation, clamped at zero. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,24 @@ extension EngineV2Bridge {
macIdle: macIdle(except: requestID),
nominalPosture: calibrationPosturePermitsWork())
}
if promptTokens > 0, let shapeRate = performanceMeasurements.freshIsolatedPrefillRate(promptTokens: promptTokens) {
prefillRate = prefillRate.map { min($0, shapeRate) } ?? shapeRate
}
let shapeRate = promptTokens > 0
? performanceMeasurements.freshIsolatedPrefillRate(promptTokens: promptTokens) : nil
if let shapeRate { prefillRate = prefillRate.map { min($0, shapeRate) } ?? shapeRate }
let calibration = requestID.flatMap {
calibratedDeadlinePolicy(requestID: $0, promptTokens: promptTokens, promptWork: promptWork)
}
if admissionFixes, !supportsPrefillRecoveryRetirement, calibration == nil, !nativeMedia,
promptTokens <= PrefillEvidenceRecovery.maximumPromptTokens,
deadlineRefusalStreak.expiresStaleEvidence(), isolatedPrefillEvidenceExpired(),
shapeRate == nil, macIdle(except: requestID) {
// Refusals measure nothing, so expired evidence that keeps refusing
// an idle Mac is treated like none: absolute expiry only, and this
// request's isolated prefill replaces it. A fresh prompt-size
// bucket is a current measurement and still refuses. As for the
// native recovery probe, only a small prompt runs unprojected: a
// long one could hold a slow Mac until its deadline.
return nil
}
guard prefillRate != nil || calibration != nil || nativeMedia else { return nil }
// The decode EWMA is a per-request rate: charge one measured step per
// projected batch step, not every row's tokens.
Expand All @@ -134,6 +146,22 @@ extension EngineV2Bridge {
return serviceBudget?.isIdle(except: requestID.map { serviceOwnerPrefix + ":" + $0 }) ?? true
}

/// Count a refusal toward `deadlineRefusalStreak` only when the isolated
/// prefill rate alone explains it: an ordinary engine on an idle Mac
/// priced nothing but this request's own prompt. Queue or decode work,
/// a reviewed calibration, native media and every fail-closed (unbounded)
/// projection are refusals a new prefill measurement would not change.
func recordDeadlineRefusal(
requestID: String, policy: CBv2FirstTokenDeadlineAdmission, work: CBv2FirstTokenProjectedWork
) {
guard admissionFixes, !supportsPrefillRecoveryRetirement,
policy.calibration == nil, policy.nativeTargetPrefill == nil,
case .bounded(let projected, _) = work, projected.decodeTokens == 0,
macIdle(except: requestID)
else { return }
deadlineRefusalStreak.recordRefusal()
}

/// Move post-commit cancellation cleanup out of the cancelling task. The
/// retained IDs block provider- and engine-ID reuse while the background
/// owner holds every pre-submit reservation through actual engine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ extension EngineV2Bridge {
switch result {
case .admitted(let stream, let projectedWork, let admittedAt, let retirement):
prefillEvidenceRecovery.admit(id)
deadlineRefusalStreak.recordAdmission()
profile?.observeDeadlineDecision(
.accepted, work: projectedWork, deadline: firstContentDeadline)
if Task.isCancelled || pendingCancellationIDs.contains(id) {
Expand Down Expand Up @@ -953,6 +954,7 @@ extension EngineV2Bridge {
case .deadlineUnreachable(let projectedWork):
profile?.observeDeadlineDecision(
.deadlineUnreachable, work: projectedWork, deadline: firstContentDeadline)
recordDeadlineRefusal(requestID: id, policy: admission, work: projectedWork)
if Task.isCancelled || pendingCancellationIDs.contains(id) {
profile?.stopDeadlineContinuation(.cancelled)
// Refused at admission after a latched cancel: nothing
Expand Down Expand Up @@ -995,6 +997,7 @@ extension EngineV2Bridge {
} else {
events = try engine.submit(engineRequest)
}
deadlineRefusalStreak.recordAdmission()
profile?.observeDeadlineDecision(.accepted, deadline: firstContentDeadline)
if prefillEvidenceRecovery.owner == id {
do {
Expand Down Expand Up @@ -1030,6 +1033,7 @@ extension EngineV2Bridge {
httpResponse?.applyPendingCancellation()
} catch let cancellation as CBv2FirstTokenAdmissionCancellation {
prefillEvidenceRecovery.admit(id)
deadlineRefusalStreak.recordAdmission()
// This exception proves acceptance but carries no projected work.
profile?.observeDeadlineDecision(
.accepted, deadline: firstContentDeadline, continuation: .cancelled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ public actor EngineV2Bridge {
/// Latest published calibration-cell isolated rate: measured idle at
/// nominal posture with caching off. Anchors admission's isolated rate.
var calibratedIsolatedPrefillTps: Double?
/// Deadline refusals since the last admission that only the isolated
/// prefill rate explains. A full streak expires stale evidence.
var deadlineRefusalStreak = DeadlineRefusalStreak()
/// Prompt samples faster than this are dropped, calibration cells
/// included. Equal to the coordinator's bound on published prefill rates.
/// Tests of toy-weight models, which prefill near it, remove it, so
Expand Down
Loading
Loading