Repository navigation
test(qwen3.5-MTP): de-flake mid-cycle-cancel heal e2e + deterministic heal coverage - #84
Conversation
…stic heal coverage `cancel_midcycle_then_continue_mtp_matches_ar` was the sole failure on main CI for #83 (run 28691184880, `e2e qwen3_5-dense`); the byte-identical PR-head tree passed the same job — a flaky oracle, not a product regression. Two root causes (both found by running the code, not reasoning): 1. Racy committed count. The async `cancel()` commits a host-timing-dependent number of turn-1 tokens (the streaming loop pushes to `cached_token_history` before its cancel check, and a "cancelled" stop — unlike "length" — does not force the trailing-token drop). The old oracle guessed `n_mtp`. The committed count is not readable from the stream: `ChatStreamChunk.prompt_tokens` on the streaming delta path is hardcoded to the delta length for both the warm and the desync-heal arms, and `cached_tokens` is the full prior history either way, so neither distinguishes them. 2. AR is the wrong oracle. MTP-speculative and plain-AR pick different tokens on T=0 argmax near-ties, so an AR reference diverges from MTP regardless of the heal. Fix: - Add a read-only test hook `mtp_flat_state_for_test() -> (committed_len, flat_mtp_caches_desynced, full_reprefill_count)` so a test can read the ACTUAL committed history length path-independently. `#[doc(hidden)]`, not `#[napi]`. - Rewrite the cancel test (renamed `..._matches_uncancelled`): read the real committed history and length-match an UN-CANCELLED MTP reference's budget (b* = n_mtp + (h1_mtp − h1_ref0)) so both runs commit the identical greedy prefix; assert the follow-ups are byte-identical. Deterministic. The cancel test is still vacuous on a fast host (the async cancel always lands on a clean boundary, so turn 2 warm-continues), so add a deterministic companion `desync_heal_reprefills_to_uncancelled`: - The flat streaming MTP continue heal is deterministically reachable: on a flat (non-paged) model the rebuild gate in `chat_stream_tokens_delta_sync_inner` reduces to `flat_mtp_caches_desynced` alone. Add `force_flat_mtp_desync_for_test()` to arm it; the heal re-prefills from `cached_token_history` and discards the caches, so arming the flag on a clean session faithfully exercises it. - Add a monotonic `flat_full_reprefill_count`, incremented only in the streaming-delta rebuild branch, as the only observable proof the rebuild ran. The test forces the desync, asserts the counter incremented (heal actually ran), and asserts the healed reply equals a byte-identical un-cancelled MTP reference over the same committed history. Verified (M5, Qwen3.5-0.8B fresh `mlx convert -m qwen3_5`): both new tests 5/5 stable, full `qwen3_5_delta_chat` file 9/9, `mlx-core` lib 1930/0 (46 ignored), clippy `-D warnings` + fmt clean. Two codex adversarial-review rounds (needs-attention → approve). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_7ff8154d-23dc-4aa7-9b24-98397558865c) |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What & why
cancel_midcycle_then_continue_mtp_matches_arwas the only failure on mainCI for #83 (run 28691184880,
e2e qwen3_5-dense). Thebyte-identical PR-head tree (
e2190e36, tree6761d493) passed the same jobon #83's own CI — a flaky oracle, not a product regression. The RoPE/perf changes
in #83 only shifted the flake odds.
Two root causes, both found by running the code rather than reasoning:
Racy committed count. The async
handle.cancel()commits ahost-timing-dependent number of turn-1 tokens (the streaming emit loop pushes
each token to
cached_token_historybefore its cancel check, and a"cancelled"stop — unlike"length"— does not force the trailing-tokendrop in
engine/cache.rs). The old oracle guessedn_mtp. Worse, thecommitted count isn't observable from the stream:
ChatStreamChunk.prompt_tokenson the streaming delta path is hardcoded to the delta length for both the
warm and the desync-heal arms, and
cached_tokensis the full prior historyeither way — neither distinguishes them.
AR is the wrong oracle. MTP-speculative and plain-AR pick different tokens
on T=0 argmax near-ties, so an AR reference diverges from the MTP run regardless
of the heal (a sweep showed byte mismatches at longer budgets even with matched
committed length).
The fix
Flakiness — read the real state instead of guessing:
#[doc(hidden)]hookmtp_flat_state_for_test() -> (committed_len, flat_mtp_caches_desynced, full_reprefill_count)(not#[napi]).cancel_midcycle_then_continue_mtp_matches_uncancelled(renamed): reads theactual committed history and length-matches an un-cancelled MTP reference's
budget (
b* = n_mtp + (h1_mtp − h1_ref0)) so both runs commit the identicalgreedy prefix, then asserts the follow-ups are byte-identical. Same generation
path on both sides ⇒ equal committed length is an identical prefix.
Non-vacuous heal coverage — the cancel test is still vacuous on a fast host
(the cancel always lands on a clean boundary → turn 2 warm-continues), so add
desync_heal_reprefills_to_uncancelled:(non-paged) model the rebuild gate in
chat_stream_tokens_delta_sync_innerreduces to
flat_mtp_caches_desyncedalone. Newforce_flat_mtp_desync_for_test()arms it. The heal re-prefills from
cached_token_historyand discards the caches,so arming the flag on a clean session faithfully exercises it.
flat_full_reprefill_count(incremented only in the streaming-deltarebuild branch) is the only observable proof the rebuild ran. The test forces
the desync, asserts the counter incremented (heal actually took the re-prefill
path), and asserts the healed reply equals a byte-identical un-cancelled MTP
reference over the same committed history.
Testing
Verified on M5 (Qwen3.5-0.8B, fresh
mlx convert -m qwen3_5):cancel_midcycle_then_continue_mtp_matches_uncancelled— 5/5 stabledesync_heal_reprefills_to_uncancelled— 5/5 stable (healed=trueeach run)qwen3_5_delta_chatfile — 9/9mlx-corelib — 1930 passed; 0 failed (46 ignored)clippy -D warnings+cargo fmt --checkclean#[napi]), so noindex.d.ctsregenTwo Codex adversarial-review rounds: round 1
needs-attention(test could passwithout exercising the heal) → round 2 approve after the deterministic heal
test + counter.
model-e2elabel added so thee2e qwen3_5-densejob runs the fixed test on this PR.🤖 Generated with Claude Code
Note
Low Risk
Changes are
#[doc(hidden)]test hooks and e2e test logic only; no public NAPI surface and no alteration of heal behavior beyond counting reprefills for observability.Overview
Adds test-only introspection for flat MTP cache healing: a monotonic
flat_full_reprefill_count(incremented when the streaming delta path discards caches and re-prefills), plus#[doc(hidden)]model-thread commands and async helpersmtp_flat_state_for_test()andforce_flat_mtp_desync_for_test()to read committed history length, desync flag, and heal count, or to arm the heal deterministically.cancel_midcycle_then_continue_mtp_matches_uncancelledreplaces the AR oracle with an un-cancelled MTP reference whose turn-1 budget is adjusted from the realcached_token_historylength (fixing flaky guesses about cancel vs length stop).desync_heal_reprefills_to_uncancelledis new: forces desync, asserts the reprefill counter increased, and checks turn-2 text matches a warm MTP run over the same history.Reviewed by Cursor Bugbot for commit f4c4b21. Bugbot is set up for automated code reviews on this repo. Configure here.