Skip to content

feat(cbv2): per-request timing and step counters (Darkbloom production pin c4089870) - #136

Closed
davidtai wants to merge 6 commits into
mainfrom
feat/cbv2-request-timing
Closed

davidtai wants to merge 6 commits into
mainfrom
feat/cbv2-request-timing

Conversation

@davidtai

@davidtai davidtai commented Sep 5, 2026 •

Copy link
Copy Markdown

Lands the branch Darkbloom production has served since 2026-09-02. Layr-Labs/d-inference pins libs/mlx-swift-lm at c408987, the tip of this branch, which is 6 commits ahead of main and was never merged: per-request CBv2RequestTiming, cumulative step counters, step signposts, host-sync counting, and their fixes. Commits and authorship are unchanged (Gajesh).

Why now: every runner-stack branch (#131 scaffold, #133 runner, #134 n-gram, #135 loader seam, #132 audit) is off main, so Darkbloom cannot compile against them (EngineV2Bridge+Profile.swift constructs CBv2RequestTiming; docs-check cites CBv2RequestTiming+Stamps.swift). Main must contain every production pin. This PR merges FIRST in the contract's order, ahead of #132 and #135.

Already merged into feat/qwen4exp-ngram-table at a5d51f4 to unblock the Darkbloom lane; the one conflict (EngineLoopV2+MTPFinalize.swift, timing block vs round-audit record at the same finalize point) was resolved by keeping both, and the runner, n-gram, loader-filter and round-audit suites pass there (62 tests, 0 failures).

🤖 Generated with Claude Code

Dependencies

This PR: Land feat/cbv2-request-timing on main (Darkbloom production pin).

Depends on: nothing. It can merge first..

Needed by: mlx-swift-lm #134, d-inference #836.

Merge order in this repository: #136, #132, #135, #130, #131, #133, #134, #137.

Program map: see work/darkbloom-runner-contract.md section 16 (Runner Program) in the layr-labs workspace.

Export `CBv2RequestTiming` on the terminal `CBv2Usage` (numerics only:
nanosecond offsets from the engine enqueue instant plus step-participation,
prefill-chunk, MTP, pause, detok-delay and prefix-cache counters), stamped
on `CBv2ScheduledRequest` from the step's existing clock reads:

- enqueue: one `DispatchTime` read is the origin of every offset
- launch (`executeMixed` / `executeMTPRound`): admission, KV allocation
  and prefill-chunk stamps reuse `wallStartedNanos`; one-token prompts are
  decode-shaped but still counted as the row's prefill chunk
- finalize: ONE new unconditional read (readback-done) serves every
  per-row stamp (first token / prompt computed, batch rows, step latency,
  decode steps), the MTP accept walk, `finishedNanos` for finishes driven
  by that finalize, and the cumulative `stepWallNanosTotal`
- markAdmitted counts re-admissions; ensureKVState counts capacity
  requeues; setPaused accumulates paused time on the injectable clock
- prefix lookup is timed on the submit thread and rides `CBv2PrefixLookup`
  into enqueue; `applyAdoption` is timed once per adoption
- first-token detok delay is measured inside `CBv2OutputStream`'s own lock
  (armed by `reserveEmission`, read by the deferred `emit`) and folded into
  the usage at terminal delivery; the scheduler record is never written
  from the detokenization queue

`CBv2CapacitySnapshot` gains monotonic `stepWallNanosTotal` and
`decodeRowsTotal`, published under the existing gauges lock. `engineStep`
is wrapped in an `OSSignposter` "step" interval guarded by `isEnabled`.

`CBv2Usage.timing` is stored boxed: the Swift 6.3 runtime frees `async let`
result buffers above a size threshold out of order ("freed pointer was not
the last allocation"), reproduced on the unmodified engine by padding a
test result struct; keeping `CBv2Usage` one pointer larger avoids it.

No new locks, evals or per-row clock reads on the step path; hostSyncs
unchanged. Tests: `CBv2RequestTimingTests` (B=1, B=4, chunked/striped
prefill, stop-string path, preemption, backpressure, prefix hit, monotonic
counters, Equatable + numeric-only shape).
… clock read, one timing box per request, exact hasSpans
@davidtai

davidtai commented Sep 5, 2026

Copy link
Copy Markdown
Author

Superseded by #140 (David 2026-09-05: all fork PRs for the runner program collapse into one). Every commit of this PR is contained in #140's branch feat/qwen38-flash-next-runner at 394ffdb. Closing; the branch stays for reference.

@davidtai davidtai closed this Sep 5, 2026
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.

2 participants