Skip to content

npu: the live MTP loop fed the drafter a truncated stream (its cursor, not the commit) - #820

Merged
bong-water-water-bong merged 1 commit into
mainfrom
npu/mtp-deferred-commit
Nov 2, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
npu/mtp-deferred-commit

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

The live MTP draft loop was drafting against a truncated stream

The drafter keeps its own KV stream (the MTP layer attends over its own states — that is why priming it
position by position took offline acceptance from 3 % to 69 %). Its quality is therefore one number: how many
committed rows its cache holds, and that the row about to be appended belongs at that position. MtpDrafter
had that number as a loose int pos_, and it was wrong in three places, all in tools/mtp_acceptance.cpp:

site bug effect on the first live iteration (P=8, k=4)
prime() appended a row, never advanced the cursor cache holds 8 primed rows, cursor still 0
draft() opened with cache_.truncate(pos_) truncate(0): the whole primed prompt is deleted before the first chain
commit_rows() appended at pos_ without dropping the chain's provisional rows accepted rows land at rope have+nd…, not over the chain at have…

So every live draft was made against a stream of length 1–5 instead of 9–70: a drafter that sees only the
current chain, which is exactly the measured 69 %→14 % / 2.19→0.62 gap. The emitted text was never wrong (the
base path is untouched) — a bad draft only costs passes.

The fix

  • npu/mtp/draft.h: DraftStream — the cursor as a named, checkable object (at(pos), keep(),
    commit(pos, keep_rows)) with the two silent mistakes it exists to catch written down. Plus per-depth stats
    drafted_at[] / accepted_at[] / hit_at(d), and the loop now fails loudly if a base returns a partial
    batch hidden instead of silently skipping the drafter advance (that silence hid this for a day).
  • npu/mtp/mtp_head.{h,cpp}: MtpDrafter moved out of the measurement tool into the library — the serve route
    needs the same class, and the cursor has to be testable without the 1.6 GiB head. prime() advances the
    cursor; draft() cuts back to the committed prefix and counts a chain opened at the wrong position;
    commit_rows() cuts back to the committed prefix before appending the accepted rows.
  • npu/forward/src/q4nx_forward.cpp (the one engine-side touch, 7 additive lines):
    commit_verify_rows() truncates last_hidden_rows_ to the accepted prefix. Without it the draft loop's own
    size check failed on every partial accept and the drafter advance was skipped silently. It touches verify state
    only, so plain decode cannot move. Reviewed and confirmed correct by the owner of that file
    (TBONSAI-SPEED-STATE.md, 2026-11-02 09:40).
  • tools/mtp_acceptance.cpp: thin MtpDrafter wiring, --live prints committed rows + cursor mismatches per
    prompt and a per-depth acceptance table, so "live vs offline per depth" is one run; stdout line-buffered so
    a killed run still says how far it got.

Red / green (host, no weights, no device)

Toy head that only knows the truth when its cache is the base model's stream; same loop, same options, k=4,
tau=0, 24 tokens over a 4-token prompt:

drafter cursor committed rows mismatches accepted/drafted passes/token
primed (prime() advances) 28 = prompt+emitted 0 20/20 0.417
legacy_prime (old path, kept in the test) 24 24 0/96 2.000

Text identical to plain decode in both. ctest -R mtp_draft → 1/1 passed (the pre-existing checks + 7 new
ones) in a Release build with ONEBIT_NPU=ON, gcc-16.

Device confirmation: NOT yet claimed

The real-model per-depth comparison (8 prompts × 64 tokens, k=4, --offline vs --live) is the remaining
deliverable number and is not in this PR yet. Measured this session, as the in-session baseline:

--offline, prompts 0–1, 64 tokens, k=4: draft 1–4 = 58.5 / 47.9 / 36.2 / 15.4 %, 2.58 expected tokens/pass
(the 8-prompt aggregate bar from the 2026-11-02 06:15 window is 69.4 / 58.2 / 49.6 / 41.4, 3.19). The
--live run on the same prompts was killed by the 3-minute ticket limit on an array TDR (aie2_legacy_tdr_detect,
09:48:51, Context IDs 6 and 8) that coincides exactly with another lane's NPU gate unit running on the GPU
token (09:48:13–09:49:41): two processes on the array at once. Nothing here blames that run for this patch — it
blames a claim-discipline collision — and no live acceptance number is claimed until the array can be held
alone. The window rule this lane runs under: one npu-hold ticket at a time, ≤ 3 min, sealed M=16 pb16i ELFs,
amdxdna counter checked after every ticket, :18097 never touched.

…ainst a truncated stream

The live speculative loop measured 0.62-0.70 accept-len against the offline protocol's 2.19 on the same
prompts, with identical text.  The commit was never the problem; the drafter's own stream was.  Three
bookkeeping faults in the drafter's cursor, all silent:

  * prime() appended a row and left the cursor at 0, so the 8 primed prompt rows had no position;
  * draft() opened the chain with cache.truncate(cursor) -- truncate(0) on the first iteration, deleting the
    whole primed stream before the first chain;
  * commit_rows() appended the accepted rows after the chain's provisional rows instead of over them, at rope
    positions have+nd..., so from iteration 2 the cache was a mixture of rejected drafts and double-numbered
    positions.

Plus one engine-side half: commit_verify_rows() left all verify rows in last_hidden_rows(), so the loop's own
size check failed and it skipped the drafter advance without a word -- the accepted prefix is the only thing a
drafter may advance over, and now that is what it gets.

The cursor is now a named object (DraftStream) the loop can check instead of a loose int, the drafter lives in
npu/mtp/mtp_head.{h,cpp} behind a next_row() seam (the serve route needs the class, and the cursor has to be
testable without the 1.6 GiB head), and Stats carries per-depth acceptance so "live equals offline" can be
reported the way the offline protocol reports it.

Host check (tests/mtp_draft_test.cpp section [8], no weights, no device): a toy head that knows the truth
exactly when its cache is the base model's stream.
  primed (fixed):        rows 28 == prompt+emitted, 0 mismatches, 20/20 drafts accepted, passes/token 0.417
  legacy_prime (the old path, kept in the test so the bug stays stated): 24 mismatches, 0/96 accepted,
                          passes/token 2.000, still text-identical
Real-model numbers need the device run (TMTPLOOP-STATE, step 3).
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Stream Cursor Mismanagement

The MtpDrafter class previously used a loose int pos_ to track its stream cursor, which led to three silent bugs in prime(), draft(), and commit_rows() functions. These bugs caused the drafter to draft against a truncated or incorrect stream, leading to a significant drop in acceptance rate from 69% to 14%. The fix introduces a DraftStream struct to manage the cursor more explicitly and safely, ensuring that drafts are made against the correct stream.

bool MtpDrafter::prime(const std::vector<float>& hidden, int token, int pos) {
    if ((int)hidden.size() != hidden_) return false;
    cache_.truncate(stream_.keep());
    if (!stream_.at(pos)) { mismatches_++; return false; }
    std::vector<float> next, lg;
    if (!next_row(hidden.data(), token, pos, next, lg)) return false;
    stream_.commit(pos, 1);
    return true;
}

int MtpDrafter::draft(const std::vector<float>& hidden, int last_token, int pos, int k, std::vector<int>& out,
                      std::vector<float>* conf) {
    out.clear();
    if (conf) conf->clear();
    if ((int)hidden.size() != hidden_ || k <= 0) return 0;
    // Open the chain: the committed prefix stays, the previous chain's provisional rows go.  A `pos` that is not
    // where the committed stream ends means the loop and the drafter are out of step -- count it and chain from the
    // cursor, because drafting from an inconsistent cache is worse than drafting from a consistent one that lags.
    cache_.truncate(stream_.keep());
    if (!stream_.at(pos)) mismatches_++;
    std::vector<float> h = hidden, next, logits;
    int tok = last_token, p = stream_.keep();
    for (int i = 0; i < k; i++) {
        if (!next_row(h.data(), tok, p, next, logits)) break;
        float prob = 1.0f;
        const int t = argmax_prob(logits, conf ? &prob : nullptr);
        if (t < 0) break;
        out.push_back(t);
        if (conf) conf->push_back(prob);
        if (tau_ > 0.0f && prob < tau_) break;   // the loop still verifies this draft, it just stops chaining
        tok = t;
        h = next;
        p++;
    }
    return (int)out.size();
}

void MtpDrafter::commit_rows(const std::vector<int>& tokens, const std::vector<float>& hidden_rows, int M) {
    // The chain's provisional rows are not part of the stream, and an accepted row is never appended after them:
    // cut back to the committed prefix first, then write the accepted rows from there.
    cache_.truncate(stream_.keep());
    const int from = stream_.keep();
    std::vector<float> next, lg;
    int at = from;
    for (int m = 0; m < M; m++) {
        if ((int)tokens.size() <= m || hidden_rows.size() < (size_t)(m + 1) * (size_t)hidden_) break;
        if (!next_row(&hidden_rows[(size_t)m * (size_t)hidden_], tokens[(size_t)m], at, next, lg)) break;
        at++;
    }
    stream_.commit(from, at - from);
}
Per-Depth Statistics Tracking

The Stats struct now includes per-depth tracking for drafted and accepted tokens, which allows for more granular analysis of draft performance. This is important for verifying that live and offline draft acceptance rates match, as required by the PR description.

static constexpr int kMaxDepth = 16;
int iterations = 0;        // speculative iterations (each = one step + one batch)
int steps = 0;             // single-token passes
int batches = 0;           // batched verification passes
int rows_verified = 0;     // draft rows fed to the base model
int emitted = 0;
int drafted = 0;
int accepted = 0;
int first_reject = 0;      // iterations where the very first draft was refused
// Per draft depth: rows offered at depth d, and how many of them the base model agreed with.  This is the
// shape the offline protocol reports, and the only form in which "live equals offline" can be checked.
int drafted_at[kMaxDepth] = {0}, accepted_at[kMaxDepth] = {0};
double hit_at(int d) const {
    return (d >= 0 && d < kMaxDepth && drafted_at[d]) ? double(accepted_at[d]) / double(drafted_at[d]) : 0.0;
}
Stream Mismatch Detection

The test suite now includes a StreamDrafter class that explicitly tests the drafter's stream cursor behavior. It demonstrates the difference between the fixed and legacy paths, showing that a primed drafter correctly maintains its stream while a legacy drafter does not, leading to incorrect draft acceptance rates.

class StreamDrafter : public onebit::npu::mtp::MtpDrafter {
public:
    StreamDrafter()
        : onebit::npu::mtp::MtpDrafter(
              g_no_weights, [](int, std::vector<float>& e) { e.assign(1, 0.0f); return true; }, nullptr, 1) {
        set_tau(0.0f);          // measure every depth, like the offline protocol
        set_lm_head(false);
    }

    // The old live path, reproduced: rows land in the cache but the cursor is not advanced.  Kept so the check below
    // states the bug instead of assuming it (npu/mtp/mtp_head.cpp prime() is the fixed version).
    void legacy_prime(int pos) {
        cache_.k.resize((size_t)pos + 1, 0.0f);
        cache_.v.resize((size_t)pos + 1, 0.0f);
        cache_.t = pos + 1;
    }
    int cache_rows() const { return cache_.t; }

protected:
    bool next_row(const float* hidden, int, int pos, std::vector<float>& next, std::vector<float>& logits) override {
        const int rows = cache_.t + 1;                 // this row lands at index cache_.t
        cache_.k.resize((size_t)rows, 0.0f);
        cache_.v.resize((size_t)rows, 0.0f);
        cache_.t = rows;
        logits.assign((size_t)V, 0.0f);
        // The toy reads two things a real head needs and a broken loop gets wrong: which position this row predicts
        // (the base's own hidden says it) and whether the cache it attends over is the complete stream up to here.
        const int pred = (int)hidden[0];
        const int t = truth(pred);
        (void)pos;
        logits[(size_t)(rows == pred + 1 ? t : (t + 1) % V)] = 1.0f;   // right only if the stream is complete
        next.assign(1, (float)(pred + 1));
        return true;
    }
};

@bong-water-water-bong bong-water-water-bong added the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 2, 2026

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at bfea12e (tprs-ready applied)

Built the target and ran it on this box — ONEBIT_NPU=ON -DONEBIT_NPU_RUNTIME=own -DONEBIT_NPU_RT_DIR=…, gcc-16,
Release, under thermal-run.sh, 0 warnings in the whole build, mtp_draft_test compiles clean at this head.

$ ./build/mtp_draft_test            -> all checks passed          rc 0
$ ctest -R mtp_draft                -> 1/1 tests passed            rc 0

And the red/green table in the body reproduces digit for digit (the numbers are the test's own INFO lines):

INFO stream primed k=4: rows=28, mismatches=0, accepted 20/20, passes/token 0.417
INFO stream legacy k=4: rows=24, mismatches=24, accepted 0/96, passes/token 2.000

so the cursor is what moves a live draft from 0/96 to 20/20 here, and the legacy path is reported out of step
rather than silently bad. All eight stream: assertions pass, including the drafter's committed rows == prompt +
emitted
(28 = 4-token prompt + 24 emitted) and per-depth counters add up to the totals. The pre-existing checks
(k=8 perfect 0.250, half head 12/24, garbage 2.000, tau gate, rollback) are unchanged and green.

Read, and correct as far as I can see:

  • prime() truncates to keep(), then checks at(pos) and advances only on a match — the primed-prompt-then-
    truncate(0) bug cannot recur.
  • draft() cuts back to the committed prefix before opening a chain, and chains from stream_.keep(), so the chain
    never lands after the previous chain's provisional rows.
  • commit_rows() cuts back to keep() and appends the accepted rows from there — accepted rows replace the chain.
  • mtp_head.cpp's q4nx_forward.cpp half (+7): stride = last_hidden_rows_.size() / verify_rows_ is H on this path
    (last_hidden_rows_ = norm_all is M*H with M == verify_rows_), guarded by verify_rows_ > 0, and an empty
    result is legal (nothing accepted ⇒ no drafter advance) while a partial batch now fails loudly — which is the
    silence that hid this for a day.
  • the owner-of-that-file cross-check is real, not cited: TBONSAI-SPEED-STATE.md:5842-5860 reviews the same
    commit_verify_rows truncation and reaches the same stride conclusion.

One nit, not a blocker: a pos the cursor disagrees with is counted (mismatches_) and drafting continues from the
lagging cursor. That is the right choice for a measurement tool, but the serve route this class is being moved for
should assert stream_mismatches() == 0 rather than inherit the tolerance — a one-line if at the call site when
#820's serve half lands.

Not verified, as the body says: the real-model per-depth acceptance (--offline vs --live, 8 prompts × 64 tokens).
That needs the array alone and the body already records why it was not held (aie2_legacy_tdr_detect at 09:48:51 while
another lane's gate unit had the GPU token — two processes on the array). Mine to note only because #820 gates the
owner's serve switch: the host half of that switch is now proven and the device half is still owed a clean window.

Apologies for the order — this was the first PR in my queue and it is the last verdict I could post: my first two build
attempts were killed by the box's thermal guard (88 °C with another lane's llama-bench on eight cores, then 93 °C
ABORT), and the third needed cmake --build because this box's cmake defaults to Unix Makefiles, not Ninja.

@bong-water-water-bong
bong-water-water-bong merged commit 1346398 into main Nov 2, 2026
10 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the npu/mtp-deferred-commit branch November 2, 2026 14:37

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at bfea12e (restated for the waiter: same head, verdict and tprs-ready already on it)

Gate state, checked now: state=OPEN, isDraft=false, headRefOid=bfea12ec02efa010c0e9b4be85ddc7d9427323c6
— unchanged since my review at 14:29:40Z, mergeStateStatus=CLEAN, label tprs-ready present, and the review's
commit_id is that same head.

Evidence was built and run here, not quoted: cmake --build build --target mtp_draft_test -j 2 (gcc-16, Release,
ONEBIT_NPU=ON, 0 warnings) → ./build/mtp_draft_test all checks passed, ctest -R mtp_draft 1/1, and the body's
red/green table reproduced digit for digit (primed rows=28, mismatches=0, accepted 20/20, passes/token 0.417 vs
legacy 24, 24, 0/96, 2.000).

Nothing has moved on this branch since that build, so the verdict applies as posted.

bong-water-water-bong pushed a commit that referenced this pull request Nov 5, 2026
The PR's own fix is "take the FIRST `accepted` rows of either documented shape", and nothing tested that. Measured,
by injecting into npu/mtp/draft.h at this head:

  * `head->commit_rows(accepted, rows, (int)got)` (hand over the whole batch, not the accepted prefix) -> 111 checks
    PASS, `all checks passed`;
  * `head->commit_rows(accepted, rows.end() - take*h, take)` (the batch's LAST `take` rows) -> same, green.

Both are exactly the #820/#1138 defect class -- a drafter that advances over rows the base rejected -- and both were
invisible for two structural reasons: [13] runs the whole-batch shape with a PERFECT drafter, so accepted == nd and
every slice of the rows looks identical; and [14]'s `RandomHead` has no rows to inspect, so it can only see text,
positions and base state.

[15] closes it with partial acceptance on the whole-batch shape and a drafter that records what it is asked to
commit: `StreamDrafter` gains an optional flub rate (a wrong draft now and then, so the chain is rejected at depth
2-3) and a `commit_rows` override that records the hidden row it is handed before delegating. The assertion is
shape-agnostic -- consecutive commits must be consecutive stream positions -- so it catches a wrong count AND a wrong
slice, and it does not depend on where in the stream the run started:

    PASS  prefix rows: the run completes with partial acceptance on the whole-batch shape
    PASS  prefix rows: text identical to plain decode
    PASS  prefix rows: acceptance really is partial (otherwise this case proves nothing)
    PASS  prefix rows: the drafter's stream advanced over the committed rows only
    PASS  prefix rows: every row the drafter committed is the next stream position (no gap, no reject)
    PASS  prefix rows: no chain opened off the cursor
    INFO prefix rows: stream 28 rows, committed 24, accepted 11/56

Red on both injections, at this head, with the same test file:

    INJ1 (whole batch): FAIL every row ... is the next stream position   (committed 46 for a 28-row stream)
    INJ2 (last rows):   FAIL every row ... is the next stream position   (committed 24, wrong positions)

Correct code: 113 checks pass, `ctest -R mtp_draft` 1/1, copyright clean. Test-only, no device.
bong-water-water-bong pushed a commit that referenced this pull request Nov 5, 2026
… instead of failing the run

BaseModel::last_hidden_rows() documents M rows (the whole verify batch); Q4nxNpuForward
truncates them to the accepted prefix in commit_verify_rows (#820).  run() demanded the
second shape exactly, so a base that keeps its batch buffer -- the shape the header's own
wording describes, and what a new target writes first -- failed the whole run at the first
partial accept, with an error naming a *partial* buffer it had not received.

Row m is the hidden after the token at start_pos+m in both shapes, so the loop now takes
the first `accepted` of either and fails loudly on any other count.
bong-water-water-bong pushed a commit that referenced this pull request Nov 5, 2026
The PR's own fix is "take the FIRST `accepted` rows of either documented shape", and nothing tested that. Measured,
by injecting into npu/mtp/draft.h at this head:

  * `head->commit_rows(accepted, rows, (int)got)` (hand over the whole batch, not the accepted prefix) -> 111 checks
    PASS, `all checks passed`;
  * `head->commit_rows(accepted, rows.end() - take*h, take)` (the batch's LAST `take` rows) -> same, green.

Both are exactly the #820/#1138 defect class -- a drafter that advances over rows the base rejected -- and both were
invisible for two structural reasons: [13] runs the whole-batch shape with a PERFECT drafter, so accepted == nd and
every slice of the rows looks identical; and [14]'s `RandomHead` has no rows to inspect, so it can only see text,
positions and base state.

[15] closes it with partial acceptance on the whole-batch shape and a drafter that records what it is asked to
commit: `StreamDrafter` gains an optional flub rate (a wrong draft now and then, so the chain is rejected at depth
2-3) and a `commit_rows` override that records the hidden row it is handed before delegating. The assertion is
shape-agnostic -- consecutive commits must be consecutive stream positions -- so it catches a wrong count AND a wrong
slice, and it does not depend on where in the stream the run started:

    PASS  prefix rows: the run completes with partial acceptance on the whole-batch shape
    PASS  prefix rows: text identical to plain decode
    PASS  prefix rows: acceptance really is partial (otherwise this case proves nothing)
    PASS  prefix rows: the drafter's stream advanced over the committed rows only
    PASS  prefix rows: every row the drafter committed is the next stream position (no gap, no reject)
    PASS  prefix rows: no chain opened off the cursor
    INFO prefix rows: stream 28 rows, committed 24, accepted 11/56

Red on both injections, at this head, with the same test file:

    INJ1 (whole batch): FAIL every row ... is the next stream position   (committed 46 for a 28-row stream)
    INJ2 (last rows):   FAIL every row ... is the next stream position   (committed 24, wrong positions)

Correct code: 113 checks pass, `ctest -R mtp_draft` 1/1, copyright clean. Test-only, no device.
bong-water-water-bong added a commit that referenced this pull request Nov 5, 2026
… instead of failing the run (#1138)

* npu: the draft loop advances over either documented hidden-row shape, instead of failing the run

BaseModel::last_hidden_rows() documents M rows (the whole verify batch); Q4nxNpuForward
truncates them to the accepted prefix in commit_verify_rows (#820).  run() demanded the
second shape exactly, so a base that keeps its batch buffer -- the shape the header's own
wording describes, and what a new target writes first -- failed the whole run at the first
partial accept, with an error naming a *partial* buffer it had not received.

Row m is the hidden after the token at start_pos+m in both shapes, so the loop now takes
the first `accepted` of either and fails loudly on any other count.

* tests: the draft loop's invariants over randomised inputs, which is how the row-shape defect was found

[1]-[13] are hand-picked shapes; the defects that survive them are the ones nobody chose.  [14] draws
600 deterministic cases over k, tau, budget, prompt, batch width, head accuracy and BOTH
last_hidden_rows() shapes, and asserts text identity with plain decode, exactly prompt+emitted
positions consumed, no chain wider than max_batch_rows, and no verify rows left uncommitted.

On main's draft.h it reports 147 of 600 violated (all the whole-batch-row cases, via the run
aborting); with the previous commit, 0 of 600.  Fixed seed, <0.1 s, so it costs CI nothing.

* tests: the sweep's toy base carries a recurrent state, so a wrong commit prefix cannot pass unnoticed

ToyBase modelled the position bookkeeping only: its logits come from the position, so a
commit_verify() that kept the WRONG rows left a state no test could see -- while on a real GDN
model that is exactly the deferred-commit contract (#805 P6) and exactly what a slip costs.

An opt-in recurrence (off by default: [1]-[13] pin shapes that assume the position-only
double) computes each batch row's state without applying it and applies only the accepted
prefix.  [14] now also asserts the loop leaves the same state plain decode does.

Failure mode proven by injection: committing the batch's LAST row instead of the accepted
prefix reports 306 of 600 violated; correctly, 0 of 600.

* tests: the suite can now see a drafter advanced over the wrong rows

The PR's own fix is "take the FIRST `accepted` rows of either documented shape", and nothing tested that. Measured,
by injecting into npu/mtp/draft.h at this head:

  * `head->commit_rows(accepted, rows, (int)got)` (hand over the whole batch, not the accepted prefix) -> 111 checks
    PASS, `all checks passed`;
  * `head->commit_rows(accepted, rows.end() - take*h, take)` (the batch's LAST `take` rows) -> same, green.

Both are exactly the #820/#1138 defect class -- a drafter that advances over rows the base rejected -- and both were
invisible for two structural reasons: [13] runs the whole-batch shape with a PERFECT drafter, so accepted == nd and
every slice of the rows looks identical; and [14]'s `RandomHead` has no rows to inspect, so it can only see text,
positions and base state.

[15] closes it with partial acceptance on the whole-batch shape and a drafter that records what it is asked to
commit: `StreamDrafter` gains an optional flub rate (a wrong draft now and then, so the chain is rejected at depth
2-3) and a `commit_rows` override that records the hidden row it is handed before delegating. The assertion is
shape-agnostic -- consecutive commits must be consecutive stream positions -- so it catches a wrong count AND a wrong
slice, and it does not depend on where in the stream the run started:

    PASS  prefix rows: the run completes with partial acceptance on the whole-batch shape
    PASS  prefix rows: text identical to plain decode
    PASS  prefix rows: acceptance really is partial (otherwise this case proves nothing)
    PASS  prefix rows: the drafter's stream advanced over the committed rows only
    PASS  prefix rows: every row the drafter committed is the next stream position (no gap, no reject)
    PASS  prefix rows: no chain opened off the cursor
    INFO prefix rows: stream 28 rows, committed 24, accepted 11/56

Red on both injections, at this head, with the same test file:

    INJ1 (whole batch): FAIL every row ... is the next stream position   (committed 46 for a 28-row stream)
    INJ2 (last rows):   FAIL every row ... is the next stream position   (committed 24, wrong positions)

Correct code: 113 checks pass, `ctest -R mtp_draft` 1/1, copyright clean. Test-only, no device.

---------

Co-authored-by: bong-water-water-bong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review effort 4/5 tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant