Kina.ai

Specification

ADR: StoryLM-0 functional KV-cache append

Context

AGENTS.md step 4 asks for KV-cache update semantics after seeded sampling. llm_generate.kina doubles a fixed-shape matrix inside while; that is not an append. A while carry cannot change tensor shape. A fused cache primitive would invent mutability and a write index that Phase 0 does not define.

Phase 0 already specifies concat. Section 5 already specifies rank-4 matmul. StoryLM-0 attention already uses Kᵀ layout [B, H, Dh, S] and V layout [B, H, S, Dh].

Decision

Specify one decode-step cache update as the existing composition in 19-kv-cache.md: concat on the sequence axis, then q_new @ k_next and softmax @ v_next. No new operator. The host holds the returned cache and calls again. Do not grow S inside while. Do not add scatter-into-T_max.

Consequences