drafter: a serial head that keeps no cache of its own

rad_drafter_shared_kv(b, pos_offset), an additive builder export: the
declared SERIAL head reads the trunk's K and V and writes none (Gemma 4's
assistant head has a query projection and nothing else per layer). A
plugin that does not call it drafts exactly as before; RAD_ABI_VERSION is
untouched (same pattern as rad_kv_group_zero).

For such a head the serial driver changes in two places:

- No history is owed. The history pass carries round 1 only: one row a
  drafting sequence, at the committed position, with the token the trunk
  chose after it and the trunk's hidden state there. A sequence that does
  not draft gets no row; a step with nothing to draft runs no pass.
- Every round runs at that same position, over the same context. seqused
  ends at the committed position: past it, the trunk's cache holds the K
  and V of drafts the verify rejected, or nothing.

`pos_offset` (0 or 1) is where the rows sit for the rotary, relative to the
committed position; it moves nothing else.

Card side: ADV_HIST and ADV_ROUND take the shape from AdvanceArgs::shared_kv
and rot_shift, which the scheduler fills from the Program. Host side:
serial_begin/serial_batch stage one row and a constant ceiling.

Tests: build_test checks the export's refusals; sched_test stages one verify
step both ways (the old path pinned: five history rows, rounds stepping),
checks that a cacheless head runs no pass when nothing drafts, and runs the
card's advance rows directly for both shapes.
This commit is contained in:
keptn42 committed 2026-10-10 16:29:34 +00:00
1 parent d59e0bb003
commit 997e1ae05f
11 files changed
+376 -10

No files matched your search

+43
View File
@@ -1005,6 +1005,49 @@ TEST(the_drafter_name_survives_the_program_leaving_the_builder) {
CHECK_EQ(p.drafter.depth, 3);
}
/* A HEAD THAT KEEPS NO CACHE OF ITS OWN (rad_drafter_shared_kv) is a property of a declared SERIAL
* drafter. With none declared, with a block drafter, or at a position no head sits at, the call is
* refused at declare -- a head staged the wrong way round costs acceptance and says nothing. */
TEST(a_head_that_keeps_no_cache_of_its_own_is_a_serial_one) {
Registry reg;
{
Builder b(reg, make_meta(), make_ctx());
CHECK_EQ(rad_drafter_shared_kv(&b, 0), RAD_E_STATE); /* nothing declared */
}
{
Builder b(reg, make_meta(), make_ctx());
RadBufDecl bd{};
bd.dtype = RAD_I32; bd.rank = 2; bd.shape[0] = 256; bd.shape[1] = 4;
const rad_buf prop = rad_decl_buffer(&b, "prop", &bd);
RadDrafterDecl d{};
d.kind = RAD_DRAFT_BLOCK; d.name = "df"; d.depth = 4; d.mask_token = 5;
d.proposal = prop; d.proposal_pitch = 4;
CHECK_OK(rad_declare_drafter(&b, &d));
CHECK_EQ(rad_drafter_shared_kv(&b, 0), RAD_E_STATE); /* a block drafter */
CHECK(!b.program().drafter_shared_kv);
}
{
Builder b(reg, make_meta(), make_ctx());
RadDrafterDecl d{};
d.kind = RAD_DRAFT_SERIAL; d.name = "mtp"; d.depth = 4;
CHECK_OK(rad_declare_drafter(&b, &d));
CHECK_EQ(rad_drafter_shared_kv(&b, 2), RAD_E_INVAL); /* no position a head sits at */
CHECK(!b.program().drafter_shared_kv);
CHECK_OK(rad_drafter_shared_kv(&b, 1));
CHECK(b.program().drafter_shared_kv);
CHECK_EQ(b.program().drafter_pos_offset, 1);
}
{
/* Every drafter that does not ask keeps the old shape. */
Builder b(reg, make_meta(), make_ctx());
RadDrafterDecl d{};
d.kind = RAD_DRAFT_SERIAL; d.name = "mtp"; d.depth = 4;
CHECK_OK(rad_declare_drafter(&b, &d));
CHECK(!b.program().drafter_shared_kv);
CHECK_EQ(b.program().drafter_pos_offset, 0);
}
}
/* ================================================================== the enum name tables
*