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

+9
View File
@@ -313,6 +313,15 @@ int Ctx::bind_ops() {
p.n_bands = (int32_t)oi.bands.size();
p.plan_off = (int32_t)issue_table_.size();
p.n_opd_schema = oi.schema ? (int32_t)oi.schema->n_operands : -1;
p.n_opd_required = -1;
if (oi.schema) {
/* One past the last required operand: everything after it is optional and may be
* omitted at issue. An optional operand before a required one is not omittable --
* that would shift positions, which is what the arity check guards. */
for (int o = 0; o < oi.schema->n_operands; ++o)
if (!oi.schema->operands[o].optional) p.n_opd_required = o + 1;
if (p.n_opd_required < 0) p.n_opd_required = 0; /* an all-optional schema */
}
/* Matched by name once here, not on the issue path; see OpPlan::billed. */
p.billed = (oi.op == "all_reduce");
p.collective = p.billed;
+8 -2
View File
@@ -76,8 +76,14 @@ struct OpPlan {
int32_t n_bands = 0;
int32_t plan_off = 0; /* into Ctx::issue_table_, band * RAD_N_DOMAINS + domain */
/* The schema's operand count, cached so the arity check avoids a cold OpInfo. -1 when the op
* has no schema. */
int32_t n_opd_schema = -1;
* has no schema. The arity check also stores here the count with the schema's *trailing*
* optional operands dropped (rad_abi.h: "an absent optional operand is a null
* RadTensor.data"): an issue may stop at n_opd_required and the shims -- r4d_opt(),
* rad_args_have(), libref's finish() -- already branch on exactly that. Only trailing
* optionals; an omitted optional before a required operand shifts positions and is the
* miscount the check exists to catch. */
int32_t n_opd_schema = -1;
int32_t n_opd_required = -1;
bool issued = false; /* did the run phase ever issue it (spec §16's graph dump) */
/* Whether issuing it puts bytes on the interconnect. Set at bind from the resolved rows
* (rad_kernel_collective) and the conventional all_reduce. The weight stager's copies share
+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) {