Data model

Postgres schema, defined in src/lib/db/schema.ts with Drizzle and migrated by the SQL files in drizzle/. All timestamps are native Postgres timestamptz; the application reads and writes them as ISO-8601 strings (Drizzle mode: 'string'). JSON columns are jsonb.

This is a reference for operators querying the database directly and for anyone extending the schema. For the events that populate the derived tables, see events.md.

Tables

agents — registry

One row per enrolled agent.

ColumnTypeNotes
aidvarchar(512) PKAgent identity
display_namevarchar(256)
handshake_endpointtextAgent's p2p handshake URL
offered_capsjsonb string[]GIN-indexed for @> capability discovery
manifest_jsontextRaw signed ManifestEnvelope bytes (the CP's cached copy)
manifest_expires_attimestamptzManifest TTL; the expiry sweep flips status when it lapses
statusvarchar(32)active | expired | deregistered (inactive is a legacy synonym)
registered_attimestamptzSet once at first enrollment
last_enrolled_attimestamptzUpdated on every (re-)register
last_seen_attimestamptzSet to the ingest time whenever the AID appears as aidA/aidB of an event ingested via POST /api/events
org, cloudvarchar(128)Optional labels (not set by the current enroll path)
namespacevarchar(128)Tenant scope, default default
metadatajsonbOperator-provided blob

Indexes: status, registered_at, namespace, GIN on offered_caps.

handshake_sessions — sessions projection

Projected from handshake.* events. The CP never sees handshake traffic; this is a reconstruction.

ColumnTypeNotes
session_idvarchar(255) PK
aid_a, aid_bvarchar(512)Participants
statusvarchar(32)started | complete | failed
grantsjsonb string[]From the completion event
run_idvarchar(255)Trace correlation
boundaryvarchar(32)Derived from payload
errortextSet when failed
started_at, completed_at, created_at, updated_attimestamptz

Indexes: status, aid_a, aid_b, run_id.

audit_events — append-only event store

Every ingested or CP-emitted event. Backs /api/events/history. The SSE stream (/api/events/stream) is served from an in-memory bus and backlog, not from this table.

ColumnTypeNotes
iduuid PKAlways server-assigned. For an ingested event with a valid ts: a deterministic version-8 UUID from the event's content and the producer's API-key fingerprint (recipe v2), so a re-sent event hits this key and is not stored twice (ON CONFLICT DO NOTHING); otherwise (no valid ts, CP-emitted events) random. See events.md
typevarchar(128)e.g. handshake.complete
tstimestamptzEvent time
aid_a, aid_bvarchar(512)
session_id, run_idvarchar(255)
grantsjsonb string[]
payloadjsonbEvent-specific body
sourcevarchar(128)cp, playground, an agent AID, etc.
created_attimestamptz

Indexes: type, ts, session_id, run_id, aid_a. Aged out after AUDIT_EVENTS_TTL_DAYS.

issued_tcts — observed TCTs

Projected from tct.issued / handshake.complete payloads. The CP observes; it never issues.

ColumnTypeNotes
jtiuuid PK
issuer_aid, subject_aid, audience_aidvarchar(512)All indexed
grantsjsonb string[]GIN-indexed
binding_cnfvarchar(128)Opaque key-binding value: the cnf.jkt JWK thumbprint (RFC-AITP-0005 §3); older v0.1 reports stored binding.cnf here
issued_attimestamptz
expires_attimestamptz
session_idvarchar(255)Indexed
revoked, revoked_atboolean / timestamptzSet by any tct.revoked event — CP-emitted on POST /api/revocation/entries, or ingested. A row inserted after its revocation_entries row exists (a late tct.issued report) is inserted already revoked, with the entry's revoked_at
created_attimestamptzRow insert time

Indexes: issuer_aid, subject_aid, audience_aid, session_id, GIN on grants.

delegations — delegation chains

Parent→child TCT relationships — single-hop RFC-AITP-0006; multi-hop draft RFC-AITP-0011. ?root_jti= queries walk this tree via a recursive CTE.

ColumnTypeNotes
jtiuuid PKChild delegation
parent_jtiuuidIndexed; root of a chain walk
delegator_aid, delegatee_aidvarchar(512)Indexed
scopejsonb string[]Delegated capability subset
issued_at, expires_attimestamptz
revoked, revoked_atboolean / timestamptz
revoked_reasonvarchar(64)explicit | parent_revoked (cascade, or inserted under an already-revoked parent)
created_attimestamptzRow insert time

Indexes: parent_jti, delegator_aid, delegatee_aid. For how jti and parent_jti are derived from reported tokens, see events.md.

revocation_entries — revoked JTIs

Backs the per-issuer relay GET /api/revocations?iss= (api.md); each issuer signs its own entries into an RFC-AITP-0008 list, and the CP signs none. Adding a row via POST /api/revocation/entries emits tct.revoked, which flips issued_tcts.revoked. An ingested tct.revoked event flips issued_tcts.revoked but does not add a row here.

ColumnTypeNotes
jtiuuid PK
revoked_attimestamptzDefaults to now
reasontextOptional
issvarchar(512)AID of the TCT's issuer, the agent the entry is relayed to. Nullable: set by POST /api/revocation/entries (from issued_tcts, else the body), backfilled by 0009, and filled — never changed — by a later re-post. A row with iss IS NULL is relayed to nobody. Indexed (revocation_entries_iss_idx)
created_attimestamptz

webhooks — subscriptions

ColumnTypeNotes
iduuid PK
urltextSSRF-guarded at write time
eventsjsonb string[]Empty = all deliverable types
secretvarchar(255)HMAC-SHA256 signing key. Never written to admin_audit_log (a rotation is recorded as secretRotated: true)
activebooleanIndexed
created_at, updated_attimestamptz

webhook_deliveries — outbox

ColumnTypeNotes
iduuid PK
webhook_iduuid FKON DELETE CASCADE from webhooks
event_typevarchar(128)
payloadjsonbFull event envelope
bodytextCanonical bytes captured at enqueue for byte-stable retries
signaturevarchar(64)HMAC computed once at enqueue (survives secret rotation)
statusvarchar(32)pending | delivered | failed
attemptsintegerOptimistic-lock counter
status_code, errorinteger / textLast attempt result
delivered_at, next_retry_attimestamptzExponential backoff
created_attimestamptz

Indexes: webhook_id, status. Terminal rows aged out after WEBHOOK_DELIVERY_TTL_DAYS.

admin_audit_log — admin actions

Distinct from audit_events; records who hit the admin mutating endpoints.

ColumnTypeNotes
iduuid PK
actionvarchar(128)One of agent.register, agent.deregister, revocation.add, webhook.create, webhook.update, webhook.delete, webhook.unsubscribed (system: a receiver answered 410 Gone), webhook.circuit-breaker.reset, trust-anchor.create, trust-anchor.update, trust-anchor.delete, pinned-key.upsert, pinned-key.delete
actor_idvarchar(255)Indexed
target_idvarchar(512)Affected AID/JTI
detailsjsonbAction-specific context. Never contains a webhook secret: webhook.update records secretRotated: true instead (migration 0008 scrubbed rows written before that)
request_idvarchar(255)Correlation
created_attimestamptzIndexed; aged out after ADMIN_AUDIT_TTL_DAYS

trust_anchors — OIDC issuer allowlist

OIDC identity mode (RFC-AITP-0002). Unique on (namespace, issuer_url).

ColumnTypeNotes
iduuid PK
namespacevarchar(128)Indexed
issuer_urltextThe API caps it at 2048 characters and 2048 UTF-8 bytes (it is in the unique btree, whose row limit is in bytes)
jwks_urltextOptional override of issuer's jwks_uri; the API caps it at 2048 characters and stores an empty string as NULL
jwks_cache, jwks_cached_atjsonb / timestamptzIssuer keyset cached by the CP's background JWKS refresher; served by GET /api/trust-anchors/:id/jwks. List/detail responses expose only jwksCachedAt. Both are set to NULL by a PATCH that actually changes issuer_url or jwks_url (decided in the UPDATE itself), and the refresher only writes a keyset if the row still has the URLs it fetched from. See operations.md
label, added_byvarchar
created_at, updated_attimestamptz

pinned_keys — pinned-key allowlist

Pinned-key identity mode (RFC-AITP-0002). Composite PK (namespace, aid).

ColumnTypeNotes
namespacevarchar(128)PK part
aidvarchar(512)PK part; also indexed
pubkeyvarchar(128)Ed25519 public key, 43-char base64url (the only form the API accepts)
label, added_byvarchar
expires_attimestamptzOptional
created_at, updated_attimestamptz

idempotency_keys — request de-dupe

Caches the response of a mutating request keyed by (scope, key).

ColumnTypeNotes
scopevarchar(64)PK part — endpoint id: agents.register, events.ingest, pinned-keys.upsert, revocation.entries, trust-anchors.create, webhooks.create
keyvarchar(255)PK part — the client Idempotency-Key value
response_statusintegerCached HTTP status
response_bodyjsonbCached body
created_attimestamptzIndexed; aged out after IDEMPOTENCY_KEY_TTL_DAYS

enrollment_jtis — one-time-token enforcement

A consumed enrollment-token jti lands here, inserted in the same transaction as the agents upsert it authorizes (so a failed registration rolls it back); a replay conflicts on the PK.

ColumnTypeNotes
jtivarchar(64) PK
expires_attimestamptzToken TTL; indexed; row aged out after it
created_attimestamptz

Migrations

Applied in order by npm run db:migrate (drizzle-kit). Each push to main that changes the schema adds a new file; run migrations against the target database from a checkout (the runtime image does not bundle drizzle-kit). See drizzle/README.md for the migration workflow.

FileAdds
0000_init.sqlInitial schema: agents, handshake_sessions, audit_events, revocation_entries, webhooks, webhook_deliveries, admin_audit_log
0001_plan_v0_2.sqlBackfill legacy inactive → deregistered; add agents.last_enrolled_at, agents.namespace (NOT NULL default default) + agents_namespace_idx
0002_offered_caps_gin.sqlGIN index on agents.offered_caps
0003_webhook_delivery_body.sqlbody + signature on webhook_deliveries
0004_idempotency_keys.sqlidempotency_keys table
0005_aitp_depth.sqlissued_tcts, delegations, trust_anchors, pinned_keys tables + their indexes
0006_trust_anchors_uniq.sqlUnique (namespace, issuer_url)
0007_enrollment_jtis.sqlenrollment_jtis table + index on expires_at
0008_scrub_webhook_secret_audit.sqlData-only, no schema change: removes webhook secrets leaked into admin_audit_log.details by webhook.update rows (replaced with secretRotated: true). Idempotent
0009_revocation_iss.sqlrevocation_entries.iss + revocation_entries_iss_idx; backfills iss from issued_tcts.issuer_aid (unmatched rows stay NULL). Idempotent. Rollback: drizzle/manual/0009_revocation_iss.down.sql

drizzle/manual/0002_offered_caps_gin.concurrent.sql is a parallel, operator-applied variant of 0002 that builds the same GIN index with CREATE INDEX CONCURRENTLY (no write lock on a large live agents table). It is not run by npm run db:migrate; its header documents the procedure.

Retention note: revocation_entries, issued_tcts, delegations, trust_anchors, and pinned_keys are not swept — they're authoritative records, not telemetry. Only audit_events, webhook_deliveries, admin_audit_log, idempotency_keys, enrollment_jtis, and long-deregistered agents are aged out. See operations.md.