Skip to content

feat(verification): per-major-version badge data model (#3524 stage 1)#3568

Merged
bokelley merged 3 commits intomainfrom
bokelley/per-version-badges-stage1
Apr 30, 2026
Merged

feat(verification): per-major-version badge data model (#3524 stage 1)#3568
bokelley merged 3 commits intomainfrom
bokelley/per-version-badges-stage1

Conversation

@bokelley
Copy link
Copy Markdown
Contributor

Summary

Stage 1 of #3524 — extends `agent_verification_badges` so an agent can hold parallel `(Spec)` / `(Live)` badges across AdCP minor versions (3.0, 3.1, 4.0…). The previous PK `(agent_url, role)` becomes `(agent_url, role, major_version)`.

No behavior change yet — the heartbeat still passes the default `'3.0'` to `processAgentBadges`. Stage 2 wires per-version fan-out, Stage 3 adds `/badge/{role}/{version}.svg`, Stage 4 splits panel rows by version, Stage 5 reshapes brand.json. This PR is purely the data-model groundwork.

The six WG-decision questions on #3524 were resolved in this comment before any code landed.

What this PR ships

  • Migration 457 — adds `major_version TEXT NOT NULL` to `agent_verification_badges` with a temporary default of `'3.0'` so the backfill is safe, parses existing `verified_protocol_version` (`X.Y.Z` → `X.Y`), rebuilds the PK, drops the default so future writes must specify the version, and adds an index on `(role, major_version, status)`.
  • DB layer — `AgentVerificationBadge` gains `major_version`. `upsertBadge` / `getActiveBadge` / `revokeBadge` / `degradeBadge` all take a `majorVersion` parameter. List queries order by `major_version DESC`.
  • `getHighestVersionActiveBadge()` — new helper that powers the legacy `/badge/{role}.svg` URL. Embedded badges in the wild auto-upgrade to the most recent version the agent has earned without changing the URL (Q3 of the resolved-decisions thread).
  • `processAgentBadges()` — accepts an optional `majorVersion` parameter (defaults to `DEFAULT_BADGE_MAJOR_VERSION = '3.0'`). Existing-badge lookups and writes are now scoped to that single version — a failing 3.1 run never touches a 3.0 badge and vice versa. This is the load-bearing isolation property.
  • 4 new tests covering version-isolation: only-touch-version-under-test, upsertBadge receives the version, default fallback when callers don't specify, and membership-lapse only affects the version under test.

What this PR does NOT change

  • The heartbeat job still calls `processAgentBadges()` without a `majorVersion` — defaults to `'3.0'`. Stage 2 wires per-version fan-out.
  • Storyboards have no `since:` field yet. Added in Stage 2.
  • Badge SVG labels still read "Media Buy Agent (Spec)" — version segment lands in Stage 3.
  • Verification panel still renders one row per role. Stage 4 splits into one row per (role, version).
  • brand.json enrichment shape unchanged. Stage 5 adds the `badges[]` array.

Test plan

  • 4 new unit tests for version-isolation
  • 89/89 existing verification + badge tests pass
  • Migration applies cleanly against Postgres (CI runs `Built migrations against Postgres`)
  • TypeScript typecheck clean
  • No behavior change — old callers of `processAgentBadges()` still hit the default version, and `/badge/{role}.svg` still serves what it did before (now via `getHighestVersionActiveBadge`)

Review focus

  • The migration's PK rebuild — pg holds the table-level write lock for the duration. `agent_verification_badges` is small (one row per badged agent, not one per request), so the lock window is brief, but worth a sanity check.
  • The `majorVersion` default in `processAgentBadges()` — confirming this preserves Stage 1's "no behavior change" promise.
  • Tests for the per-version filtering invariant — does the test surface miss any case where 3.0 and 3.1 should genuinely be touched together?

🤖 Generated with Claude Code

bokelley and others added 3 commits April 29, 2026 20:11
Extends agent_verification_badges so an agent can hold parallel
(Spec)/(Live) badges across AdCP minor versions (3.0, 3.1, 4.0…).
The previous PK (agent_url, role) becomes
(agent_url, role, major_version).

Migration 457: adds major_version TEXT NOT NULL with a temporary default
of '3.0' so the backfill is safe, parses existing verified_protocol_version
('X.Y.Z' → 'X.Y'), rebuilds the PK, drops the default so future writes
must specify the version, and adds an index on (role, major_version,
status) for the per-version listings later stages will need.

DB layer: AgentVerificationBadge gains major_version. upsertBadge,
getActiveBadge, revokeBadge, degradeBadge all take a majorVersion
parameter. getBadgesForAgent / bulkGetActiveBadges /
getVerifiedAgentsByRole order by major_version DESC.

New getHighestVersionActiveBadge() powers the legacy /badge/{role}.svg
URL — embedded badges in the wild auto-upgrade to the most recent
version without changing the URL (Q3 of #3524's resolved-decisions
thread).

processAgentBadges() accepts an optional majorVersion (defaults to
DEFAULT_BADGE_MAJOR_VERSION = '3.0' for Stage 1 callers). Existing-badge
lookups and writes are now scoped to that single version — a failing
3.1 run never touches a 3.0 badge and vice versa. This is the
load-bearing isolation property: it's what lets old-version badges
persist while new versions are evaluated independently.

4 new tests cover the version-isolation invariant: only-touch-version,
upsertBadge receives the version, default fallback when callers don't
specify, and membership-lapse only affects the version under test.

No behavior change yet — heartbeat still passes the default. Stage 2
wires per-version fan-out, Stage 3 adds /badge/role/version.svg, Stage
4 splits panel rows by version, Stage 5 reshapes brand.json.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The values stored are MAJOR.MINOR strings ('3.0', '3.1'), not just the
SemVer major number. major_version was misleading. adcp_version
describes exactly what it tracks (the AdCP release this badge was
issued against) and pairs cleanly with verified_protocol_version
(full semver, e.g. '3.0.0', kept as informational metadata).

Mechanical rename across:
- migration 457 column, constraint, and index names
- AgentVerificationBadge type field
- upsertBadge / getActiveBadge / revokeBadge / degradeBadge parameters
- processAgentBadges parameter (adcpVersion) and log fields
- DEFAULT_BADGE_MAJOR_VERSION → DEFAULT_BADGE_ADCP_VERSION
- test mock fields and assertions
- changeset description

No behavior change. 89/89 tests pass, typecheck clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Security review:
- Numeric version sort: ORDER BY adcp_version DESC was a TEXT compare
  ('10.0' < '3.0'), so when AdCP hits double-digit major or minor
  versions getHighestVersionActiveBadge would silently serve a stale
  older badge. Switched all four sort sites to
  split_part(adcp_version, '.', 1)::int DESC, split_part(...,'.',2)::int
  DESC. CHECK constraint guarantees both segments parse.
- Membership lapse is per-agent, not per-version. Previously a 3.0
  failing run with lapsed membership only revoked the 3.0 badge — the
  3.1 badge (and any other version) kept signaling "AAO Verified" until
  its own heartbeat landed 12-24h later. Now all versions revoke
  immediately on lapse. Updated the test that codified the buggy
  behavior to expect cross-version revocation.

Code review:
- brand.json + registry list enrichment dedupe: roles[] and
  verified_roles[] silently grew duplicates the moment Stage 2 writes
  parallel-version badges. Both sites now dedupe by role; modes_by_role
  uses the highest-version badge per role (Q3 framing).
- Backfill regex guard: ^[1-9][0-9]*\.[0-9]+ rejects leading-zero
  majors at the UPDATE so a hypothetical '0.x.y' row can't extract
  '0.x' and fail the CHECK constraint at step 5.
- Migration header: documented the ACCESS EXCLUSIVE lock window for
  next-reader context.
- Stale comment at the SVG handler: getActiveBadge → getHighestVersion-
  ActiveBadge.

New test: partial overlap — agent has media-buy@3.0 and creative@3.1,
a 3.0 run for creative-ad-server issues creative@3.0 without touching
the existing creative@3.1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant