Skip to content

feat(cbv2-mtp): per-round acceptance/rollback audit journal - #132

Closed
davidtai wants to merge 1 commit into
mainfrom
feat/cbv2-round-audit
Closed

davidtai wants to merge 1 commit into
mainfrom
feat/cbv2-round-audit

Conversation

@davidtai

@davidtai davidtai commented Sep 5, 2026 •

Copy link
Copy Markdown

Upstreams the per-round MTP audit journal that the Qwen 3.8 125B engine has carried as a vendor-local patch since its ed55bee base and never sent back. Verbatim port: CBv2MTPRoundAuditRecord (requestID, k, draftTokens, targetTokens, accepted, confirmed, rejected, tokensCountAfter, numComputedAfter, generatedAfter, finishReason) and a bounded roundAudits on CBv2MTPMetrics (retainedRecordCap = 8192, oldest evicted first; a consumer that reconciles audits against committed streams refuses at the cap). Populated at the finalize host-sync boundary from values already on the host; no extra MLX evaluation.

Why now: a bench-worker free run must report per-round acceptance lengths and related audit counters from engine state, and fork main keeps only cumulative metrics. The runner scaffold (#131) will read roundAudits through its round-auditing seam once this lands.

Adaptations vs the vendor patch: one renamed local on main (committedAccepted -> observedAccepted) and a comment re-wrap. Diff +109/-2 over MTPContractsV2.swift, EngineLoopV2+MTPFinalize.swift, CBv2MTPRoundDriver.swift.

Tests (GPU-free, xcodebuild): CBv2MTPRoundAuditTests 2/2 (depth-2 free run over the deterministic fixture reconciles every record with the committed stream and the cumulative counters; cap evicts oldest-first) and CBv2MTPEngineParityTests 13/13 unchanged. Not covered: B>1 audits (requestID disambiguation) beyond the code path.

🤖 Generated with Claude Code

Dependencies

This PR: Per-round MTP audit journal.

Depends on: nothing. It can merge first..

Needed by: mlx-swift-lm #131.

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.

Add `CBv2MTPRoundAuditRecord` and `CBv2MTPMetrics.roundAudits`. Every
finalized VERIFY round now leaves one snapshot record built at the
existing finalize host-sync boundary from values already on the host:
the draft ids, the target argmaxes, the accept boundary, the rollback
width, and the row's post-round scheduler accounting. No extra MLX
evaluation and no new host readback.

Retention is bounded at 8192 records with oldest-first eviction. A
consumer that reconciles audits against committed streams refuses when
the count reaches the cap, because a truncated head cannot prove
coverage.

No consumer or seam is wired here.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
davidtai added a commit that referenced this pull request Sep 5, 2026
The bench-worker free-run audit reads that journal, so this branch builds on
it. No conflicts: #132 touches only the MTP finalize/driver seam and its own
tests.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
davidtai added a commit that referenced this pull request Sep 5, 2026
… bag

Wire the free-run audit to `CBv2MTPMetrics.roundAudits` (#132), so a
free_decode_run response states what the engine journaled rather than what
the worker could infer from the tokens it drained.

`FreeRunRoundAudit.assemble` groups the records — one per (row, round), in
finalize order — by row and reads them position-wise: a row's r-th record IS
its r-th round, and a row that stopped early simply has no record past its
last one, which is what makes `active_streams_by_round` non-increasing
without computing it from anything else. From that:

  acceptance_lengths   per-round committed width (rows must agree; a cohort
                       commits ONE common width, and disagreement refuses)
  drafted_total        sum of every record's k
  accepted_total       sum of min(accepted, confirmed) — the `observedAccepted`
                       the engine's own cumulative counter accumulates
  committed_total      the drained count, which the schema requires equal
                       tokens.len(); the journal's own sum EXCEEDING it
                       refuses, while under-counting is legitimate (a
                       target-only decode step commits without a round)
  rounds, natural_accepted_by_stream, active_streams_by_round
                       the v1.2 COHORT trio, emitted only in the cohort form
  depth_clamp_reasons  the controller's skip/fallback counts, windowed

`spec_decoder` and `verify_replay_disagreements` have no journal field at
this pin and stay ABSENT — naming the request's own mode back is not a
report, and absent is not 0.

A journal at its 8192-record cap REFUSES the response by name: a truncated
head cannot prove coverage of the window, mirroring the 125B worker's rule.
The window opens after the seed forward, so the seed's records are never
counted as the timed run's.

Also: bench-worker's runtime-worker gains a repeatable
`--resource <name>=<path>`. Each occurrence becomes an entry in
RunnerLoadOptions.resources. A name may appear once, the path must exist and
be a regular file or a directory, and both refusals fire BEFORE the load —
a bad path found after a multi-minute weight load has wasted the box's time
to report something argv already knew. Values pass through opaque; the
worker never opens them. `RunnerResources` and `RunnerError.resourceMissing`
are declared identically to #133 so that branch rebases cleanly.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@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.

1 participant