can1357/oh-my-pi · error

Array length must be even (the weave action splits it in hal

Error message

Array length must be even (the weave action splits it in half), got ${length}

What it means

initialArray() additionally requires an even length because the weave benchmark action splits the array in half; an odd length would break that split. It throws this Error for any valid-range but odd length.

Source

Thrown at packages/coding-agent/src/if-bench/actions.ts:44

	| { kind: "odd-even" }
	| { kind: "reverse-blocks"; size: number }
	| { kind: "rotate-span"; first: number; last: number; amount: number }
	| { kind: "weave" };

/**
 * Opening state: `A..Z` truncated to `length` and shuffled by a fixed LCG.
 *
 * Scrambled on purpose — an alphabetical start lets a model reconstruct state
 * from memory instead of reading its own previous answer.
 *
 * @throws when `length` is odd or outside [{@link MIN_ARRAY_LENGTH}, {@link MAX_ARRAY_LENGTH}].
 */
export function initialArray(length: number): string {
	if (!Number.isInteger(length) || length < MIN_ARRAY_LENGTH || length > MAX_ARRAY_LENGTH) {
		throw new Error(`Array length must be an integer in [${MIN_ARRAY_LENGTH}, ${MAX_ARRAY_LENGTH}], got ${length}`);
	}
	if (length % 2 !== 0)
		throw new Error(`Array length must be even (the weave action splits it in half), got ${length}`);
	const chars = ALPHABET.slice(0, length).split("");
	let seed = 0x9e3779b9;
	for (let i = chars.length - 1; i > 0; i -= 1) {
		seed = (Math.imul(seed, 1103515245) + 12345) >>> 0;
		const j = seed % (i + 1);
		[chars[i], chars[j]] = [chars[j]!, chars[i]!];
	}
	return chars.join("");
}

/**
 * The `count` actions starting at absolute index `start`.
 *
 * The kind cycles every 10 indices so each turn mixes local edits (swap, move)
 * with whole-array permutations (weave, odd-even) that invalidate every
 * remembered position.
 */
export function makeActions(length: number, start: number, count: number): Action[] {

View on GitHub (pinned to 9690622007)

Solutions

  1. Use an even --length value
  2. When scripting, round to the nearest even number: length - (length % 2)
  3. Step by 2 in parameter sweep loops over array lengths

Example fix

// before
omp if-bench opus --length 15
// after
omp if-bench opus --length 16
Defensive patterns

Strategy: validation

Validate before calling

if (length % 2 !== 0) {
  throw new Error("--length must be even");
}

Try / catch

try {
  await runIfBenchCommand({ models, flags: { length } });
} catch (err) {
  if (err instanceof Error && err.message.includes("must be even")) {
    console.error("Round --length to the nearest even value");
    process.exitCode = 1;
  } else throw err;
}

Prevention

When it happens

Trigger: Calling `omp if-bench --length N` (or initialArray(N) directly) with an odd integer N within the allowed min/max range, e.g. 7, 15, 33.

Common situations: Users picking arbitrary sizes unaware of the even-length invariant; generated benchmark matrices iterating over every integer in the range.

Understand the failure class

Background: "must be positive", "Invalid value": how libraries reject invalid parameter values (ValueError, ArgumentError, INVALID_PARAMETER_VALUE) — this error's family across 28 libraries.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/ee50bd1862fc90ab. Report an issue: GitHub.