docs/internal/agenthub-records.md

AgentHub signed public records v1

The records package defines the signed public facts used by authority and endpoint admission. It contains no private invitation material.

Encoding

A record is a U32BE length followed by a closed v1 core and its fixed-width signatures. The core starts with version byte 1 and a record-kind byte. The seven current kinds cover the public record families: hub genesis, authority transition, endpoint identity, hosting binding, publication, revocation list, and pairing approval. Each family has a typed Go content value, an explicit dependency set, a digest, and a role-specific signature domain. Ed25519 signatures are fixed 64-byte values; P-384 signatures are fixed 96-byte, low-S values. Record verification checks canonical key encoding, signer role, signer identity, dependency kind, lineage, generations, revisions, and resource limits before a record becomes eligible.

Authority and endpoint facts

A genesis establishes an authority. A transition advances exactly one consecutive generation and proves both the old authority and new possession. Endpoint identity and hosting binding identify an endpoint and its authority origin. Publication selects one exact binding and revision. Revocation lists are complete replacements, not unions; client recognition of an observed tag is separate state. Public records exclude friendly names, application types, local paths, client keys, ACLs, claimant locks, JOIN WORDS, and revocation secrets — the private-field exclusion that pairing, the local catalog, directory and routing work must preserve.

Pairing approval signs a separately encoded ceremony commitment. The commitment contains the request, participants, generations, nonces, exporter value, mode, and deadline. It is not an invitation request and one approval does not activate a peer. The reviewed pairing-handshake contract composes both signer slots. Pairing creates durable eligibility from both approvals; the normal-peer link establishes the required fresh connection. The local catalog selects those exact approval frames and ceremony for each active relationship. Its directory verifier checks signatures under the ceremony's historical signer keys and generations, confirms those keys remain in each current retained lineage, and does not recheck expired approval deadlines. The store alone selects active Peer trust matched to active Pairing state; pending proposals and removed relationships do not become catalog evidence.

Pairing transfers complete canonical genesis-to-current authority bundles, not bare generation claims. Claim carries the joining bundle; fresh and recovered Context carry the target bundle; Completion repeats the target bundle. The pairing envelope contains existing signed record frames only. VerifyAuthorityLineage remains the signature, predecessor, generation, and key-possession authority. Pairing must stage both verified lineages and the canonical Ceremony before Verifier checks either Approval. CompareSignedRecords uses the typed canonical-core digest to classify exact frames, equivalent signature variants, and different signed content. For equivalent verified variants it chooses the byte-lexicographically least exact frame; it does not bypass signature or dependency checks. TLS proves the current authority key and operational chain, while signed records prove its generation and stable genesis.

Verification boundary

The records owner shares mechanics through closed content policy, not a runtime role selector. Signing and verification use the same allocation-free signer-slot lookup for each of the seven typed families. Dependency adapters resolve only the keys for those slots; they do not repeat slot names, signer IDs or signature-domain roles. The lookup rejects indexes outside the family's exact slot count. Verification checks the complete resolved key count and each slot's signer ID before processing signature bytes, producing signature metadata or consuming verification work. Adapter key order cannot substitute for this check. Core encoding, typed digests, signature inputs and verification work remain the existing v1 implementations.

SelectionPolicy supplies ordinary comparison keys, signed revisions and replaceability to learned selection and directory witness selection. Binding generation, publication origin revision and access revision remain different counters. Publication history is keyed by endpoint, not by binding. Endpoint identity and each ceremony's approval slot are immutable. Value and nonnil pointer content return identical policy without allocation. Nil, typed-nil and unsupported content return an explicit error. Authority records also return an error because predecessor and fork policy is separate, not an ordinary zero-key selection. The returned metadata alone verifies nothing and does not replace codec validation of scalar fields.

The operation-local SignedFrameSelection.Select shares witness-index lookup and least-exact-frame selection with catalog admission and canonical aggregation. There is no separate exported raw selector. It returns an aliased candidate or existing frame without mutating or growing the caller's index. The caller checks its existing count and byte limits before inserting new content. Current contributions may deliberately override a retained repair representative, but must still agree in typed content. Every input variant must undergo scoped verification before it becomes evidence; parsing or choosing a representative cannot substitute for that verification.

Raw comparison and selection parse each distinct input once per call; exact-byte equality is used only after a full successful parse, including signature-tail validation. SignedFrameSelection reuses those same mechanics within one caller-owned operation. Its exact-byte LRU retains at most 256 entries and one MiB of copied frame/core bytes, plus bounded entry metadata. Hits reuse only strict parse metadata, never signature verification or dependency/authorization results. Caller mutation changes the lookup key and must parse again. Eviction only causes another parse; it adds no admission limit. Directory build, canonicalization, outbound bundle selection and compact scope lookup use local instances. No global cache or lock is involved. Typed digest and core equality are both checked before choosing a signature variant.

Verification uses explicitly supplied dependencies and bounded traversal. A complete authority bundle shares one verification context, including memoized predecessors and aggregate dependency/signature limits, across its at most 64 transitions. It never looks up an invitation selector, root, proof, or secret. Equal revisions with different content are conflicts; a later valid revision is an explicit replacement. Lineage and current eligibility are distinct checks.

Dependency policies retain their diagnostic and work distinctions. A typed digest dependency checks all candidate cores before trying variants and may stop at its first valid signature. Endpoint identity and authority-head lookup verify all admitted candidates to detect ambiguity, with their respective endpoint and root/path checks. These are not interchangeable searches. Exact-frame dependency admission, verification memoization, cryptographic-success caching, verified-graph interning and semantic witness deduplication have different keys and ownership. Conflict byte budgets and directory table bounds remain with their current owners; sharing signed-content identity does not combine those budgets or install trust.

Store, invitation, pairing and transport consumers continue to use Sign, Verifier and VerifyAuthorityLineage at their existing verification boundaries. No ceremony caller needs a new signer-role switch or a second canonicalizer. Exact durable retry/response matching remains ceremony policy, not semantic witness equality. Historical directory approval evidence does not apply fresh pairing activation's current-generation, bilateral-approval or deadline gates.

NormalizeAuthorityWitnesses is the shared lineage observation boundary for public transfers, learned-directory Peer staging, and both durable proposal owners. It verifies the entire incoming and retained bundles before comparing overlaps by typed canonical digest and exact core. Equivalent overlap records become owned copies of the exact retained witnesses, not the least frame in a changing directory contribution set. Different content stays distinct; an equal digest with an unequal core fails. Invalid overlapping or trailing signatures cannot be hidden by normalization or immediate-successor selection. All output records are copied, including the unseen suffix.

Ingress still requires an extension of the accepted prefix. Proposal handling also normalizes overlapping successor witnesses to the first pending, denied, or collision evidence before duplicate and fork classification. Neither step rewrites installed Trust, changes local resolutions, or authorizes a successor. Durable replay and administrator decisions retain exact-byte binding. The shared current-algorithm test cases exercise exact Ed25519 delivery and distinct valid P-384 witnesses without an algorithm-specific production comparison path. The maximum-lineage regression measures complete verification and normalization at 65 records, including the 38,261-byte P-384 public transfer. With GC disabled for the measured operation, incremental heap growth includes all transient allocations and copied output, providing a conservative live-peak upper bound. Its 32 MiB regression ceiling is test headroom, not a new protocol limit or a directory working-memory reservation.

Fixtures and tests

records.json is generated by records/main.go and independently checked by check-records.rb, verify-records.rb, and check-public.rb. The generator uses the same v1 domains as the production record codec but the Ruby checker performs its own Ed25519 and P-384 verification. The fixture includes positive families, typed dependency cases, signed mutations, truncations, conflict scenarios, and pairing commitments.

The current records are part of an unreleased implementation. Claimant locks are private invitation state, never public records. Shared signed-lineage verification also governs store trust and invitation lineage transfer.

VerificationWork is a caller-owned, nonconcurrent verification batch with a context, finite signature-check budget, and a bounded cache of successful cryptographic checks. NewVerifierWithWork and VerifyAuthorityLineageWithWork retain all scoped dependency resolution and per-verification limits. Only the exact SPKI, domain-separated signed input, and signature identify a cached success. Failed checks consume work but are not cached. Exhausting the batch returns CodeResourceLimit; cancellation remains discoverable with errors.Is and neither condition is classified as CodeInvalidSignature. Cancellation is checked during record traversal and before each signature check, including cache hits. The directory uses one batch per build; there is no global cache or reuse of trust decisions across dependency scopes.

Learned selection freshness and accounting

LearnedState retains one publication high-water selection per endpoint, across hosting-binding changes. Lower signed origin revisions are stale; an equal revision with different canonical content is a conflict. A publication remains usable only when its binding digest matches the selected hosting binding. ComparisonKey.Binding may restrict a publication query to that exact binding; it does not create a separate revision history. Hosting bindings and publications must use the retained current origin authority head and generation for usability. Valid older-origin hosting signatures are stale even if their binding revisions are higher. Historical publication signatures still enter the endpoint-wide freshness selection, including when delivered after the authority advances; selection queries keep those publications unusable under the retired origin. This carries rollback evidence to a fresh downstream receiver without restoring old hosting eligibility. A retained higher old-origin publication can suppress discovery until a consistent newer publication arrives, not authorize access. Historical ceremony signing generations remain usable for pairing approvals. These learned checks do not approve a successor or mutate local trust.

Learned authority heads remain keyed by stable genesis root. If distinct roots have the same current head ID, both roots are quarantined and every selection that depends on either lineage is non-connectable. Identical endpoint bytes do not merge their verified lineage scopes. A hosting binding verified through both roots retains that bounded ambiguity even after one root advances and the current heads become distinct. Only a strictly higher binding, verified under one of those roots and consistent with its current head and generation, resets the binding to one stable root. An ordinary equal-revision hosting conflict likewise retains both verified witness roots; a higher binding from an unrelated third root cannot repair it. Roots that share only a historical key while their current heads differ remain valid and independent.

SelectedBindingOrigin projects the exact selected verified binding lineage as its stable root, current head and current authority generation. It returns no projection for stale, forked, resource-limited or ambiguous selection. Dynamic authority-ambiguity conflict presentation contains the bounded stable root IDs and role-correct checks. The already retained authority-head and binding state owns the verification evidence, so this presentation does not allocate or return synthetic uncharged signed-frame copies.

VerifiedPool interns storage only after independent scoped verification. Its transaction-local keys include exact signed frames, verified dependencies and lineage identities. It shares equivalent verified graphs, lineage/key storage and evidence bytes; it is not a dependency or trust-decision cache. The caller must not mutate records handed to the pool. Bytes covers its graph and indexes, and the pool has a finite record bound in addition to caller-owned byte budgets. Interning copies pointer metadata before rewriting dependencies or lineage key references. It can therefore import a predecessor's immutable graph without mutating storage still used by that predecessor. Fork acquires a predecessor reference only while that generation remains live. Final Close is terminal: a concurrent or later fork starts independently and cannot resurrect cleared evidence or repeat a reservation-release callback. Public close consumes one owner token exactly once; child detach releases only its private predecessor pin. Closed pools reject further interning, and imported storage also uses retain-if-live acquisition.

Clone gives the directory a transactional learned selection without weakening sealed dependency verification. CloneBytes charges new selection maps and copied conflict evidence, not the immutable graphs shared with the predecessor. RetainedBytes conservatively charges reachable verified records, parsed content, lineages, conflicts and map metadata, counting interned storage once. Replacing an ordinary selection releases its unreachable record graph, while high-water records for absent endpoints and bounded conflict evidence remain charged. The directory reserves verification and clone working space before allocation. Rehome moves an unpublished clone's roots to the candidate pool, preserving exact sealed dependencies, selection and conflict semantics. The directory then transfers the existing verification reservation to retained graph ownership instead of double-charging that graph. Old selection ownership remains live until publication; failed candidates leave it untouched. All of this state is RAM-only and resets with its daemon-lifetime owner.

VisitNewConflicts projects newly installed ordinary conflicts as a fixed-size ConflictNotice: record kind, endpoint identity, signed revision and two sorted canonical content digests. It compares the previous atomic selection, so duplicate witnesses do not generate repeat notices and repaired evidence need not be retained forever for deduplication. The directory calls the service audit sink only after successful atomic installation. No signature frame or private state enters this projection. Authority forks continue through their separate terminal Peer path.

Bounded verification runtime

The successful Ed25519 path uses Go's exact signature equation and canonical S check, plus the identity package's strict canonical, nonidentity, prime-order check for A. Go compares the canonical encoding of [S]B - [H(R || A || m)]A with the supplied R. With prime-order A, equality also proves canonical, prime-order R. The record verifier separately rejects identity R. This avoids redundant big-integer subgroup multiplications without changing the accepted signature set. Failures retain the detailed strict validator and its diagnostic precedence. Differential tests cover malformed points and scalars, mutated signatures, and a valid standard-library equation with forbidden identity R.

Sealed-record metadata validation re-encodes the public content and binds its kind, digest, core and signature bytes to the already verified frame seal. It does not reparse and allocate each ancestor's content a second time. This is immutability checking after verification, not a replacement for scoped candidate verification. Learned authority rollback journals only touched dependency entries; unrelated high-water maps are neither copied nor rewritten.