Skip to content

ADR 0009 — Public ids: UUIDs on every surface, integer keys internal, Wagtail's and Django's rows excepted

The owner's decision P-D6: a platform row is named on every surface by a UUID public id and never by its integer key; agent runs and suggestions moved to theirs in one change across REST, GraphQL, MCP, events, the studio and the extension; Wagtail's and Django's own rows keep their integer ids as a recorded exception.

  • Status: accepted 2026-10-28 (the owner's decision P-D6, taken as PLAN proposed it); lands with the pull request that adds this file.
  • Inputs: TARGET.md § Rules that keep models and views manageable ("Public ids are UUIDs; integer keys stay internal. No prefixed string keys."); the P4 review, which found the studio's routes and shapes on integer keys; PLAN § 7's proposal for P-D6, which said "before G10" — G10, the extension on the studio's stack, had merged by the time it was decided, so the extension moved in the same change.
  • Where: content/agents/models.py (AgentRun.public_id, AgentRun.links) and content/suggestions/models.py (Suggestion.public_id) with migrations agents 0002–0005 and suggestions 0002–0004; content/api/ (views.py, review.py, serializers.py, urls.py, graphql.py), content/ai/serializers.py (RunRefSerializer, every app's run reference) and the tools that answer with a run or a suggestion; schemas/events/ (agent.run.completed and content.suggestion.created v2); the committed OpenAPI document and GraphQL schema, and web/packages/api; web/packages/ui and web/studio; the extension's bridge tests; content/tests/api/test_public_ids.py.

Context

Since G8 the rows that the AI layer and the apps after it added, and that a surface names, have had a UUID public_id, serialized as id, and the API addressed them by that alone. Two older rows did not: AgentRun and Suggestion, the two that every app points at, exposed their integer keys through the REST endpoints, GraphQL and MCP from before P4 — and then through the studio, its routes (/ai/runs/<id>, /review?run=<id>) and every app's run reference. Wagtail's and Django's rows (pages, revisions, sites, users) have integer keys that Wagtail's own APIs, admin and rich text (<a linktype="page" id="…">) use; giving them a second id would put two ids on one row and translate between them on every surface. The extension persists no id, so moving runs and suggestions was one change in @zer0/ui and the platform, not a migration of clients.

Decisions

# Decision Mechanism that enforces it
1 A model the platform adds (from G8 on, in the decision's words) carries a UUID public_id from its first migration — UUIDField(default=uuid.uuid4, unique=True, editable=False); one added to a table with rows is three migrations, nullable, filled, unique (agents 0002–0004) — and that is the only id a surface gives or takes: a serializer's id, a path's lookup, a tool's argument or answer, an event's field. The integer key stays internal: foreign keys, a worker's task argument, the stored keys no surface reads. content/tests/api/test_public_ids.py: every platform model has one, or is named in WITHOUT with how it is reached instead; an entry that gains one fails the test too.
2 Agent runs and suggestions moved to theirs in one change, with no compatibility shim. REST paths, bodies and answers (/api/v2/agent-runs/<public_id>/, its stream, suggestions/<public_id>/<decision>/, the review inbox and review/runs/<run_id>/accept/, every app's RunRef), Idempotency-Key replays, GraphQL (UUID arguments and fields), MCP tool answers (run_id, suggestion_id, stream), Wagtail's log entries and admin views, the studio's routes and the extension. An integer id of either is a 404 on REST and an error on GraphQL. The tests of content/tests/api/ (test_review.py, test_graphql.py), the apps' API tests that read an id from an answer, web/packages/ui/test/; the committed OpenAPI document (npm run check:api) and GraphQL schema (test_the_committed_graphql_schema_has_not_drifted).
3 Wagtail- and Django-owned rows keep their integer ids, a recorded exception: pages and every page type, revisions, sites, users, groups, images, documents and renditions, workflow tasks and their states, log entries and comments. They are addressed by Wagtail's id on every surface, as Wagtail's own APIs do. test_public_ids.py recognises them by their Wagtail base classes; the rest of the platform's rows must have a public id.
4 An event names a run or a suggestion by its public id, in agent.run.completed v2 and content.suggestion.created v2 (a narrowed type is a new version). The v1 schemas stay, so an envelope already in a stream validates; every consumer of either type is in this repository and moved with the change. content/tests/outbox/test_contracts.py (test_runs_and_suggestions_are_announced_by_their_public_ids), emit's schema check at write time.
5 Stored JSON holds public ids where a client reads it back, and migration agents 0005 rewrote what was stored: a step's tool answer and a person's decision, a run's suggestions, a pipeline's steps and an MCP call's result, fact-check findings, automation outcomes, replayable answers and the run a suggestion's log entry names; backwards it writes the integer keys again. newsroom.Story.ai keeps integer keys, because only its serializer reads it and gives the runs' public ids; the outbox's events keep theirs, because each is the record of what was announced under the v1 schema its envelope names. The migration, checked forwards, backwards and forwards again over rows of every kind it rewrites, on SQLite and Postgres.
6 A screen names a run by its first eight characters (shortId in @zer0/ui), as a short commit hash names a commit, with the whole id in its title; every address — a route, a path, a link — uses the whole id. web/packages/ui/test/runs.test.tsx, review.test.tsx.
7 The audit's one mechanical fix: graph.upsert_edge answered with the edge's integer key, which no surface takes back; an edge is named by what it joins, so the key went. content/tests/graph/test_graph.py.

Consequences

  • A client that stored a run's or a suggestion's integer id holds an id that no longer resolves; none in this repository did (the extension persists no id, and the studio holds ids only in its routes).
  • A replayed answer, a step's result, a fact-check's findings and an automation's outcomes read after the migration carry public ids; an id whose row was gone became null.
  • A long UUID is shown short; a person who copies the short form has a label, not an address.
  • 44 of the platform's 77 models have a public id. The other 33 are listed in test_public_ids.py: most are reached through a parent (a pipeline's step by position, a job's line by index, a story's bylines by author), by a natural key (an agent definition by slug) or by no surface at all; four are exposed today and are the open questions below. Ten of the 33 were added from G8 on without one, none of them exposed: ai.PipelineStep, ai.IdempotencyKey, ideas.Vote, newsroom.StoryEvent, newsroom.Byline, newsroom.FrontSlot, newsroom.IssueStory, newsroom.IssueDelivery, books.LibraryFile, importers.ImportedRecord (PLAN § 7, P-D6, records them as the remaining work).

Open — the owner's decisions

  1. graph.Entity's node key. The graph API (/api/v2/graph/neighbors/, path/), the MCP graph tools' NODE pattern, GraphQL's EntityType.id and an edge suggestion's payload.dst name an entity entity:<integer>, in one format with page: and image:, which keep Wagtail's ids. Proposed: entity:<public id> after a public id by this recipe, with existing edge suggestions' payloads migrated; the alternative is entity:<slug>.
  2. Snippets in the studio and in Grapple. The studio's category field takes and gives cms.Category integer keys (its field spec's choices, fields.categories), and Grapple gives every snippet type it generates (Category, BrandRules) and ArticlePageTag in its search union an id: ID. Proposed: a public id on Category and the field's choices by it, and Grapple's generated ids recorded with Wagtail's as part of the exception, since Grapple reads them from Wagtail's snippet registry.
  3. Rows added from G8 on without a public id (the ten above). The decision says from their first migration; none is on a surface. Proposed: give each one by this recipe when a surface first names it, and record a row reached only through its parent as part of the exception until then.