can1357/oh-my-pi · critical · Error

invalid compiled revision term in ${compiled.source}

Error message

invalid compiled revision term in ${compiled.source}

What it means

Thrown by buildRuleIndex while indexing a compiled compat cascade: a revision condition term compiled from KDL could not be parsed back into a valid RevisionTerm via parseRevision. This indicates the compiled rules.json (or hand-written cascade data) contains a revision string the parser doesn't recognize — i.e. corrupted or out-of-sync generated data, not user input at runtime.

Source

Thrown at packages/catalog/src/compat/cascade.ts:71

	const last = segments[segments.length - 1];
	return last === "" || remainder.endsWith(last);
}

interface IndexedRule {
	compiled: CompiledRule;
	revision?: RevisionTerm[];
	priority: number;
	dimensions: number;
	hasExactEffortsRule: boolean;
}

let ruleIndex: IndexedRule[] | undefined;

function buildRuleIndex(cascade: CompiledCascade): IndexedRule[] {
	return cascade.rules.map(compiled => {
		const revision = compiled.revision?.map(term => {
			const parsed = parseRevision(term.revision);
			if (!parsed) throw new Error(`invalid compiled revision term in ${compiled.source}`);
			return { op: term.op, revision: parsed } satisfies RevisionTerm;
		});
		const dimensions =
			Number(compiled.class !== undefined) +
			Number(compiled.providers !== undefined) +
			Number(compiled.family !== undefined) +
			Number(compiled.revision !== undefined) +
			Number(compiled.models !== undefined);
		return {
			compiled,
			revision,
			priority: compiled.priority ?? 0,
			dimensions,
			hasExactEffortsRule: compiled.thinking !== undefined && "efforts" in compiled.thinking,
		};
	});
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Find the offending rule via the `${compiled.source}` in the message and fix the revision selector in the KDL file under packages/catalog/src/compat/rules/.
  2. Run `bun run gen:compat` to regenerate rules.json and commit it with the KDL change.
  3. If rules.json was hand-edited, restore it from git and change the .kdl source instead.

Example fix

// before (rules/taxonomy.kdl)
revision "17.5"
// after — use the supported comparison/revision syntax, then regenerate
revision ">=17.5"
# then: bun run gen:compat
Defensive patterns

Strategy: validation

Validate before calling

null

Type guard

null

Try / catch

try {
  const policy = resolveModelPolicy(provider, model);
} catch (err) {
  if (err.message.includes("invalid compiled revision term")) {
    throw new Error(`rules.json out of sync with KDL: ${err.message} — run bun run gen:compat`);
  }
  throw err;
}

Prevention

When it happens

Trigger: getRuleIndex/resolveCascadeRules on a CompiledCascade whose rules contain a `revision` term with an unparseable revision string (typo in KDL, hand-edited rules.json, or stale rules.json after changing the revision grammar).

Common situations: Editing revision-parsing grammar in code without regenerating rules.json; hand-editing packages/catalog/src/compat/rules.json; adding a KDL rule with a malformed revision selector like `rev: 17.5x`.

Related errors


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