Skip to content

runtime::mtp: the MTP draft's card-free window policy moves from app, so a backend without the card engine can draft with it - #1148

Closed
midagedev wants to merge 1 commit into
mainfrom
runtime-mtp-policy
Closed

midagedev wants to merge 1 commit into
mainfrom
runtime-mtp-policy

Conversation

@midagedev

Copy link
Copy Markdown
Owner

MTP draft의 카드 없는 창 정책과 그 테스트를 crates/app에서 host 전용 runtime::mtp로 옮깁니다. Metal이 같은 정책으로 draft하기 위한 첫 단계(#1135의 R0a)이고, 동작과 커널은 바뀌지 않습니다.

What and why

The MTP window policy is card-free: Policy, Shape, Refresh, Chain, Call, Walk, Exec, Fail, Refused and SKIPS. It lived in crates/app, which links the card engine, so the Metal backend cannot use it. This PR moves it and its 21 tests to the host-only runtime crate, beside runtime::lookup and runtime::dspark.

The plain values it reads move too: Hidden and WalkMode from gpu::draft, and the Join and Parked structs from app::mtp. The old paths re-export everything.

The moved code is unchanged except:

  • visibility (pub(super) → pub);
  • use lines;
  • two doc links.

What names a card type stays where it is:

  • Feed (it holds gpu::media::CallRows);
  • DraftHead (check_opened returns GpuError);
  • From<StepMode> for WalkMode.

Parked's byte codec stays in app as the ParkedBytes trait (put/take/check, over gpu::checkpoint::bytes), with its two tests. Refresh::feed stays as a private app trait. The only caller edit is one use line in gpu-gates serve_seats/drafted.rs.

This is the first half of #1135. The second half moves MtpDraft itself behind a Host trait.

Release notes: internal — the MTP draft policy is shared code in runtime, ready for a second backend.

Code shape

  • No second copy. Moved, not copied. Parked stays one type, with the byte codec as an extension trait rather than a wrapper type.
  • Model code holds only architecture facts. No model code changed.
  • Dead code is gone.
  • No silent failure. Unchanged.
  • Comments state what is true now.
  • No relaxed gate. No test removed. There were 24 tests before (policy 23, app 1) and 24 after (runtime 21, app 3).
  • cargo fmt; just mac-lint ratchet 0.

Duplication found or removed: none. The app byte tests keep a small test-only Ar arena enum, since the runtime test module's is private.

What I ran

The move proof uses just narrow origin/main HEAD: --no-jit scans of the covering bin set on the box, base 99a6bfd, head c6e8c7c.

narrow: ptx-scan bloomery-serve: identical (JIT skipped: --no-jit both)
narrow: ptx-scan gate_gpu_device: identical
narrow: ptx-scan gate_kquant: identical
narrow: ptx-scan gate_swap: identical
affected: ... 144 of 242 gate-recipes selected (narrowed from 221 by ptx-scan)

The host files the move touches are linked by most bins, so 144 gates stay. They run as a fixture-tier batch; the result is below.

On the Mac:

cargo test -p bloomery-runtime            test result: ok. 336 passed; 0 failed   (21 of them the moved policy tests)
just mac-check                            combos rc 0; 86 shapes run, 0 red
just mac-lint                             ^warning: 0 = the ratchet 0
check-comments / check-arch / check-unsafe / fmt --check: ok

FAIL-first on a moved test: changing Policy::chain's ctx as usize - 1 - end to ctx as usize - end fails two tests, a_chain_takes_the_refresh_and_caps_its_own_walks and no_call_sequence_leaves_the_store_past_the_target_or_refuses (19 passed; 2 failed). The edit was reverted.

Box batch (fixture tier): pending, added below when it ends.

AI use: Claude Code wrote this change (a Sonnet round, reviewed by the lead session, which ran the box proof).

🤖 Generated with Claude Code

https://claude.ai/code/session_01CjHkkntc2L1xRN21xB39mj

… so a backend without the card engine can draft with it

The MTP window policy and its tests now live in the host-only runtime crate,
beside runtime::lookup and runtime::dspark. Metal will use them. It cannot
link crates/app, which links the card engine.

Moved, code unchanged except visibility, use lines and doc links:
- app mtp/policy.rs: Policy, Shape, Refresh, Chain, Call, Walk, Exec, Fail,
  Refused, SKIPS, and 21 policy tests.
- gpu draft.rs: Hidden and WalkMode.
- app mtp.rs: the Join and Parked structs, and WHAT.

The old paths re-export them. What names a card type stays:
- Feed (CallRows);
- DraftHead (check_opened returns GpuError);
- From<StepMode>.

Parked's byte codec (put/take/check, gpu::checkpoint::bytes) stays in app as
the ParkedBytes trait. Refresh::feed stays as a private app trait. Its two
byte tests stay in app. The only caller edit is drafted.rs's `use` line.

Tests 24 before (policy 23, app 1) and 24 after (runtime 21, app 3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CjHkkntc2L1xRN21xB39mj
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset needs-gpu Changes code a card must check, and carries no gate run on a card labels Nov 3, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: MUST_FIX: The moved codec test loses its saved-reason compatibility check.

Must fix

1. Keep the saved skip code tied to PROMPT_ARENA

crates/app/src/mtp.rs:1521 now selects SKIPS[3] from the same table the encoder searches. Swapping STORE_BEHIND and PROMPT_ARENA still produces code 4 for this fixture, so the assertion passes while saved codes 3 and 4 change meaning. The base fixture selected PROMPT_ARENA independently and caught this mutant.

This drops an existing compatibility clause without the dated reason required by the gate contract (kind B). Restore it in this move to keep later table edits from passing with changed saved-state meanings.

Replace skip: Some(SKIPS[3]), with the independent expected reason:

skip: Some(
    "the rows waiting for the draft sat in a prompt call's arena when the \
     sequence was parked, and a parked sequence keeps only the step's and \
     the verify's",
),

The existing code-4 assertion then rejects the table-swap mutant again.

Non-blocking

⚠ Complete the pending gate evidence: crates/app/src/mtp.rs:123. The PR supplies identical PTX scans but still lists the selected fixture batch as pending. Attach its just gate-* commands and output, card/driver line, both commits and model file. The move class needs no timed A/B.

Checked

Duplicates: 3 new adapter/test items checked; moved definitions and methods retain one owner. No dryer pairs were available.
Complexity: crapper unavailable; policy and codec bodies add no branches. The feed adapter has no branch.
Silent failure: 5 sites followed; optional window collection, two last-row substitutions and two chain caps preserve their defined contracts.
Tests: all 24 retained, split 21 runtime / 3 app. Static mutation review found the surviving table-swap mutant above; the other 23 test bodies match base. Rust tests were not executed.
Gates: no threshold moved; the saved-reason clause weakened as described in item 1.
Escape catalog: no C1–C4 pattern matched. Re-exports preserve type identity; codec method bodies match base after import normalization.

Notes

Dryer and crapper did not run because their Python modules were missing. GPU gates were not run during this review; the PR supplies no complete card gate evidence.

Card check: needs-gpu. This pull request changes crates/app/src/mtp.rs, crates/gpu-gates/src/bin/shared/serve_seats/drafted.rs, crates/gpu/src/draft.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@midagedev

Copy link
Copy Markdown
Owner Author

Superseded by #1155, which carries this commit and the second half (MtpDraft over a Host trait), rebased onto main after the uutils fix.

@midagedev midagedev closed this Nov 3, 2026
@midagedev
midagedev deleted the runtime-mtp-policy branch November 4, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant