Skip to content

perf(session): poll the cancel token before the decode forward, not after — one wasted forward per cancelled request (0.69.4) #4325

Closed

Description

@noahgift

Found by the gemini lane in the #4309 batch quorum (M2b, 15c3032).

In realizar::session::Session::generate, a mid-decode cancel costs one decode forward pass whose logits are thrown away. With CancelToken::with_budget(8), the session emits 8 tokens and runs 8 decode passes (FALSIFY-SERVE-CANCEL-009, crates/aprender-serve/src/api/tests/apr_q4k_cancel_2465.rs). Before M2b, q4k_decode polled at the top of the loop body: its 8 passes produced 9 tokens and none was wasted. The old test documented this as the reason to poll at the top: "the latter costs one wasted forward pass per cancelled request, and on a 7B Q4K model that is not free".

The same change applies to every arch that goes through Session, not just Q4K.

Done when:

  • A cancelled run performs exactly emitted - 1 decode passes (the first token comes from prefill). CANCEL-009's prediction is updated to match.
  • A mutant that moves the poll after the forward turns the test RED.
  • The uncancelled token identity is unchanged, covered by the G1 cells.

Not a blocker for 0.69.3: the cost is at most one forward per cancelled request, and it is declared in contracts/apr-serve-cancellation-v1.yaml.

Activity

  1. added this to the 0.69.4 milestone on Sep 24, 2026
  2. noahgift commented on Sep 24, 2026

    @noahgift
    MemberAuthor

    Fix on branch PMAT-4325-cancel-poll-before-forward (db61dd8, based on rc/0.69.3-rc.2; Session is not on main/#4318 yet). Session::generate now polls the cancel token before each decode forward, so a cancelled turn computes no discarded token. FALSIFY-SERVE-CANCEL-009 now requires emitted-1 forwards (7 for 8 emitted). Reverting the fix turns it RED (tested). Cancel and session lib tests green; clippy -D warnings clean.

  3. noahgift commented on Sep 25, 2026

    @noahgift
    MemberAuthor

    Verified on batch/0.69.4-epic-4249 (e573ed6 and later; aprender-ont): the cancel poll sits before the decode forward in Session::generate. Cancel tests 9/9 pass. Moving the poll after the forward turns FALSIFY-SERVE-CANCEL-009 RED (8 tokens need 7 decode passes); source restored and porcelain clean. Not independently measured: the G1 uncancelled-output identity. Issue stays open until the batch merges.

  4. modified the milestones: 0.69.4, 0.69.5 on Sep 25, 2026
  5. added 3 commits that reference this issue on Sep 25, 2026
  6. modified the milestones: 0.69.5, 0.71.0 on Oct 4, 2026
  7. noahgift commented on Oct 12, 2026

    @noahgift
    MemberAuthor

    evidence for close: #4655 / 989cb01 (on main), how checked:

  8. noahgift commented on Oct 12, 2026

    @noahgift
    MemberAuthor

    Cop batch close (FLOW-004 drain, ≤43/d): fix verified on main — merged #4655 ; ancestor of origin/main: 989cb01 . Evidence: #4325 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High priorityowner:la-0.71Owned by the 0.71 look-ahead slotsize:MK̂ 3-4 h

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions