Open Policy Agent 1.21 is a release about the tax you pay for policy breadth — and about two silent behavior changes that will bite anyone who upgrades without reading. We downloaded the actual v1.20.0, v1.21.0, and v1.21.1 binaries (sha256-verified against the release assets), ran the same probes against all three, and measured what the headline claim — a rewritten rule index — actually does to a policy that looks like production code. The honest summary: the indexer work is real and large, the YAML 1.2 core schema switch is a breaking change with no compile-time warning, the empty-literal type checker breaks previously-compiling policies, and the release shipped with a compiler bug so bad it panicked on valid Rego — patched five days later in v1.21.1. If you take one thing from this analysis: read the YAML section before you upgrade, and do not run 1.21.0 anywhere — start at 1.21.1.

The Pain: Linear Scans Over Policies That Grew Like Kudzu

Rego policies at platform scale do not look like the docs' examples. A Kubernetes admission policy library like Gatekeeper constraint templates, or a Terraform plan policy (the same OPA-in-CI pattern we mapped in our OpenTofu vs. Terraform comparison), accumulates hundreds or thousands of rule bodies under a single decision path, most of them guarded by string prefix tests. Before 1.21, OPA's rule index only indexed a narrow set of shapes: ground == comparisons and a couple of others. Everything else — every startswith guard, every reference rooted at a local variable, every lookup into base data — meant the evaluator fell back to linear evaluation over all candidate bodies on every query. On a warm server taking thousands of authz calls a second, that is the difference between an index lookup and a scan.

That is the industry pain the 1.21 index rewrite targets, and it is why the changelog's dry line — "improved rule indexing" — undersells the work. The rewrite makes the index handle shapes it previously could not:

  • startswith and endswith, plus strings.any_prefix_match / strings.any_suffix_match, are now indexable when the base strings are known at compile time (PR #9161, #9164).
  • References rooted at a local variable (x := input; x.foo == "a") now index like the direct form (PR #9081).
  • A lookup into base data (data.groups.admins.members[input.subject]) indexes by asking the object for the key (PR #9235) — such rulesets used to leave every body a candidate.
  • The trie is smaller (unconstrained refs kept out of it, paths stop at the last constrained level), and candidate lookup collects candidates in a bitset (PR #9190, #9244).
            query: data.perf.allow  (input.path = "/other/thing")

  ┌──────────────────────────── OPA v1.20.0 ────────────────────────────┐
  │  rule index: only ground == shapes indexed                          │
  │     startswith(input.path, "/svc0000")   ── not indexable ──┐       │
  │     startswith(input.path, "/svc0001")   ── not indexable ──┤       │
  │     ...                                                          ├─▶ all 5,001
  │     startswith(input.path, "/svc4999")   ── not indexable ──┘     │
  │     input.path == "/nothing"             ── indexed (1 body)       │
  │                                                                    │
  │  result: linear scan → timer_rego_query_eval_ns = 13,200,083      │
  └────────────────────────────────────────────────────────────────────┘

  ┌──────────────────────────── OPA v1.21.x ───────────────────────────┐
  │  rewritten index: ground prefixes of startswith/endswith indexed   │
  │     trie:  "/svc0000" ──▶ body #1      (ground prefix lookup)      │
  │             ...                                                    │
  │            "/svc4999" ──▶ body #5001                                │
  │     "/other/thing" matches nothing in the trie → 0 candidates      │
  │                                                                    │
  │  result: trie lookup → timer_rego_query_eval_ns = 19,834           │
  └────────────────────────────────────────────────────────────────────┘