earendil-works/pi · error · TypeError

Eval input must not contain circular references.

Error message

Eval input must not contain circular references.

What it means

canonicalizeJson tracks ancestors to keep the canonical form finite; a circular reference in the eval input makes JSON serialization impossible, so it is rejected instead of hanging or throwing later.

Solutions

  1. Break the cycle by removing self- or mutual references in the eval input
  2. Use ids/strings to reference repeated structures instead of direct object links
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/evals/src/vitest-evals/harness-table.ts:73 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/7282a82085ea6c17. Report an issue: GitHub.

Appendix: source

Thrown at packages/evals/src/vitest-evals/harness-table.ts:73

		typeof harness !== "string" ||
		typeof baseline !== "string" ||
		!Array.isArray(candidates) ||
		!candidates.every((name): name is string => typeof name === "string") ||
		typeof repetition !== "number"
	) {
		return undefined;
	}
	return { schemaVersion, evalSet, groupKey, harness, baseline, candidates, repetition };
}

function canonicalizeJson(value: unknown, ancestors: WeakSet<object>): JsonValue {
	if (value === null || typeof value === "string" || typeof value === "boolean") return value;
	if (typeof value === "number") {
		if (!Number.isFinite(value)) throw new TypeError("Eval input must contain only finite numbers.");
		return value;
	}
	if (typeof value !== "object") throw new TypeError("Eval input must be JSON-serializable.");
	if (ancestors.has(value)) throw new TypeError("Eval input must not contain circular references.");

	ancestors.add(value);
	try {
		if (Array.isArray(value)) {
			const result: JsonValue[] = [];
			for (let index = 0; index < value.length; index += 1) {
				if (!Object.hasOwn(value, index)) throw new TypeError("Eval input arrays must not be sparse.");
				result.push(canonicalizeJson(value[index], ancestors));
			}
			return result;
		}
		const prototype = Object.getPrototypeOf(value);
		if (prototype !== Object.prototype && prototype !== null) {
			throw new TypeError("Eval input must contain only plain objects and arrays.");
		}
		const entries: Array<[string, unknown]> = Object.entries(value);
		return Object.fromEntries(
			entries

View on GitHub (pinned to 4af9d21d3b)