runtime: an issue may omit trailing optional operands

e28cf86 made timestep_embed's curve `table` an optional WEIGHT operand but left the
arity check demanding exact equality with the schema, so every sinusoidal issuer —
qwenimage21, minimaxh3's full-form path — died at step 0: engine_e2e_test has been red
since that commit. The check now accepts a count at or above the last REQUIRED operand
and nulls the dropped schema slots, which is what rad_abi.h promises ("an absent
optional operand is a null RadTensor.data") and what every shim already branches on
(r4d_opt(), rad_args_have(), libref's finish(); the curve kernel still requires the
table when curve > 0). Only TRAILING optionals: an omitted optional before a required
operand would shift positions, which is the miscount the check exists to catch.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
gearwave00001andClaude committed 2026-10-22 00:57:42 -05:00
1 parent d480a47bef
commit 80b13b49d8
3 files changed
+31 -6

No files matched your search

+14 -4
View File
@@ -549,13 +549,23 @@ int Ctx::issue_body(rad_op h, const RadOperand* opd, int n_opd, int64_t n) {
return abort_step_msg(h, RAD_E_INVAL,
fmt("issued with %d operands; the runtime carries at most %d",
n_opd, MAX_OPERANDS));
if (p.n_opd_schema >= 0 && n_opd != p.n_opd_schema)
/* A count below the schema is legal only when every dropped slot is a *trailing optional*
* operand (rad_abi.h: "an absent optional operand is a null RadTensor.data" -- the shims
* branch on exactly that: r4d_opt(), rad_args_have(), libref's finish()). A count below the
* required floor shifts positions or drops a required operand, and operands are positional,
* so a miscount is silent numerical garbage. */
if (p.n_opd_schema >= 0 && (n_opd > p.n_opd_schema || n_opd < p.n_opd_required))
return abort_step_msg(h, RAD_E_SCHEMA,
fmt("issued with %d operands; the op's schema declares %d. Operands "
"are positional, so a miscount is silent numerical garbage",
n_opd, (int)p.n_opd_schema));
fmt("issued with %d operands; the op's schema declares %d "
"(%d required, only trailing optional operands may be omitted). "
"Operands are positional, so a miscount is silent numerical "
"garbage",
n_opd, (int)p.n_opd_schema, (int)p.n_opd_required));
RadTensor* t = tbuf_;
/* The schema slots the issue stopped short of: null tensors, never stale ones. Nothing is
* supposed to read past args.n_t -- this keeps a stray read a null deref, not old bytes. */
for (int i = n_opd; i < p.n_opd_schema; ++i) t[i] = RadTensor{};
bool touches_host = false; /* a host-domain buffer among the operands; see host_touch_ev_ */
for (int i = 0; i < n_opd; ++i) {