docs/internal/agenthub-invitation.md

AgentHub invitation contract

AgentHub invitations authorize one claimant-locked admission, endpoint grant, or future pairing ceremony. They are private state, not public records. The direct-handshake review owns operator ordering; this page owns invitation state and security boundaries.

Secret and request

Five uniform JOIN WORDS derive a typed private root and selector. The owner must first record the intended claimant's four-word KEY CHECK plus check byte, or an exact fingerprint. That lock is immutable. Words, indices, root, selector, proofs, and recovery credentials never enter public records, logs, or remote diagnostics.

Admission and Endpoint use their existing StaticContext encodings. Pairing uses the same derivation with purpose 3, Authority subject and claimant roles, empty profile, and explicit Direct 1 or Routed 2 mode. The subject is the inviting authority current ID. NewPairingStaticContext is derivation-only: Pairing cannot enter the client invitation Request or Context codec. Exact J bytes and derivation literals live in the pairing fixture.

The claimant stores one durable request before transmission. A retry reuses that request; it never creates fresh words, a new root, or a new request ID. Exact message fields and derivation bytes are checked by invitation.json and check-invitation.rb.

Authenticated carrier

Admission uses checked entry-hub TLS; endpoint authorization uses exact endpoint TLS; pairing retains its dedicated authority TLS role. Proofs bind subject and claimant identities and roles, request, nonces, operation context, and the role-specific TLS exporter. Exporters and roles are not interchangeable. Routed endpoint authorization composes the existing endpoint invitation engine over production routed endpoint TLS. Direct and routed claims use identical request, continuation, durable ACK and result policies. A verification connection uses only the existing pre-claim Cancel; it cannot consume or prepare an invitation. See the client ordering contract.

Unavailable selectors, malformed or invalid proofs, expired or terminal rows, and valid proofs from outside the claimant lock return the same remote failure shape and close behavior. Remote errors reveal no invitation existence, state, lock mode, claimant identity, or owner-notification outcome.

Durable lifecycle

StateEntered whenWhat remains possible
UnclaimedOwner creates claimant-locked wordsOne matching first claim
ClaimedMatching key proves the rootDurable client credential, then ACK
ACKedClient commits credential and acknowledgesOwner approval or terminal transition
ApprovedOwner commits exact admission/ACLAuthenticated result recovery and ordinary use
LinkedApproved key completes ordinary useStatus only; authorization is unchanged
Compromised / ConflictedOutside-lock proof or competing claimant/request winsNothing; create a fresh invitation

That ACK-bearing path applies only to Admission and Endpoint invitations. The pairing model adds the pairing-purpose PairingClaimed: a valid authority Claim moves Unclaimed directly to that pairing-specific phase, and final target approval moves it atomically to Approved with Pairing activation. Pairing never uses client Unacked/Acked, an authority ACK, client recovery ACK semantics, or circuit DATA ACK semantics.

The first valid proof from a key satisfying the lock claims the invitation for that key and request. The authenticated claimed response supplies server-owned context and a narrow recovery credential. The client must validate and durably store both before ACK. Owner approval is unavailable before that ACK.

ACK erases the server's secret-bearing claimed response and continuation manifest. A same-key, same-request retry after ACK may receive only the bounded non-grant acknowledgement hint while approval remains pending. It never returns a recovery secret, approval result, or authorization.

Approval atomically commits the admission or ACL, terminal invitation state, and claimant-protected result. The claimant recovers that result with its narrow credential, validates it, and installs local state before reporting success. Linked records the first ordinary authenticated use; it is status, not a new grant.

Claim, ACK, compromise, conflict, cancellation, expiry, and approval serialize through revision-checked store operations. Approval committed first is immutable; a terminal transition committed first prevents approval. Retries and restarts never extend deadlines.

Compromise, conflict, and erasure

A valid root proof from a key outside the immutable claimant lock proves that the secret escaped or the lock was wrong. The store atomically marks the invitation Compromised, erases recoverable secrets, creates no approval row, emits only a bounded local notice, and returns generic failure remotely.

A different key satisfying a short lock, or the same key using a different request before approval, makes the invitation Conflicted and revokes the pending claim. Invalid attempts do not mutate state. Approved or Linked rows never change through invitation traffic. Compromised and Conflicted rows cannot be rebound, repaired, or approved; the owner verifies again and creates fresh words.

Terminal rows retain only bounded nonsecret evidence and their already existing absolute retention deadline. Purge occurs at equality. The storage contract owns exact durable shapes and atomic cleanup.

Closed ceremony hooks and common progression

Admission and endpoint clients select NewAdmissionServerSession or NewEndpointServerSession, the corresponding client-session hook, and the corresponding recovery-session hook before parsing peer input. A wrong subject, claimant, or request purpose fails before nonce generation or exporter access. PrepareAdmission and PrepareEndpoint retain the same durable-before-send boundary. There is no purpose-inferred session constructor or adapter factory. Invitation creation uses CreateAdmission, CreateEndpoint, or CreatePairing; only the pairing input carries a pairing mode and requires an authority lock.

The client sessionCore owns binding, exchange counters, exact replay bytes, verified-response confirmation and terminal erasure for the two client flows. The shared scheduler's Attempt.BeginProcessing owns one dispatched worker's deadline context and joined, idempotent finish for client and pairing work. Cancellation alone does not release a running worker; its actual owner joins transport cancellation before finishing. No shared worker loop or global ceremony lock serializes connections. Store transactions own exact revisions, durability, uncertain persistence and durable erasure. Protocol owners disclose only after their applicable transaction succeeds.

Invitation queue accounting uses AttemptOwnedBytes. It charges the exact retained frame copy plus 4,096 bytes for the bounded attempt, lane, queue and map ownership before AdmissionController clones the frame. Rejected reservations create no attempt. Cancellation of queued work releases the charge once; running work retains it until Finish observes actual worker retirement. This is owned-storage accounting, not a claim about Go allocator or goroutine stack use.

service.StagingAccounting supplies the process aggregate for invitation TLS. The generic public pre-TLS owner transfers atomically to StagingInvitation through hoptls.Lifecycle.Transfer and OwnershipTransferTarget. The role charge is TLS record and canonical identity staging plus the maximum invitation attempt ownership above. The same canonical claimant SPKI contributes to one cross-role aggregate. A failed transfer leaves the pre-TLS owner live until its serving worker retires. Production service pairs PreTLSOwner with AuthenticatedTransferTarget in entry and endpoint reservation callbacks; neither helper replaces the existing coarse budget lease. Established endpoint-access tunnel frames use a finite control-class pool plus the outer client's shared SPKI charge. They never disable allocation admission to escape application DATA pressure.

Pairing reuses nonce generation, scheduler processing ownership and joined cancellation mechanics. Its graceful close action, nonzero nonce check, request and exporter transcript, bilateral approvals, held decision connection, exact-Q poll-first recovery and seven-day cutoff remain separate. It never enters the client's replay cache, status-key recovery or ACK progression.

Pairing runtime

internal/agenthub/pairing reads and writes only pairingwire frames over hoptls.InitialPairingConn or exact-pinned hoptls.PairingConn. It never constructs an invitation client session or passes pairing TLS to a gateway. The obsolete authority callback adapter was removed. Pairing takes a ChallengeLease from the pairing scheduler and calls QueuePairing for each operation. The service supplies a Dispatch callback for that exact attempt. Claim and recovery operations use the per-subject Pairing claim lane and pairing worker/queue reserves, not client ACK/poll capacity or invitation worker/queue reserves. HoldPairingDecision retains the pairing connection budget for the five-minute decision window after the first worker finishes. Closing the lease or cancelling an attempt releases its budgets once; transport loss is not a protocol Cancel.

The default public service calls Engine.ServePublic after pairing TLS for both initial Claim and authenticated inbound recovery. Preconfigured carriers may call ServeInitial or ServeRecovery separately. Each path closes its connection and lease; none may receive a normal-peer socket. The joining service checks the independently supplied authority checks in InitialPairingClient before calling JoinInitial(ctx, conn, input, decisions). JoinInput contains only administrator-supplied JOIN indices, mode and the optional local direct address. Its Prepared callback gets the nonsecret exact request before Claim, so a lost response can be resumed without creating a new request. Its caller-owned typed Accepted channel receives that request only after Context and lineage have committed. The five-minute decision deadline starts then, caps at the ceremony's approval deadline, and includes any blocked handoff. The engine selects the send alongside cancellation and the same absolute timer; it starts no accepted-callback goroutine. The local-control owner calls ApproveJoining before signaling DecisionApprove. RecoverJoining uses a fresh exact-pinned TLS connection for each poll, approval retry or Cancel retry. For a locally approved row the service polls Status first; only a matching recovered Context authorizes resending the same durable approval on a second connection. Prepared recovery pins the saved exact target key without trusting generation until signed Context verifies it. JoinCancelPending means local cancellation committed but delivery or the terminal response was lost; retry the same exact Cancel with RecoveryCancel. JoinCancelled means the remote returned and closed after generic Failure. Even after a confirmed Cancel, a final approval already committed at the target cannot be undone by pairing traffic. The service's revision-checked FinalizeTargetPairing transaction commits the inviting administrator's last approval and atomic activation.

An uncertain pairing transaction notifies the service owner immediately so it stops accepting new work; remote failures stay generic. store.PairingRuntimeView and PairingRuntimeByID omit retry secrets; PairingRetryView returns only the prepared root and selector and requires Close to erase them. These are local private reads, never remote status. Cancelled rows can supply an exact-pinned pairing TLS credential solely for retrying Cancel. A row with accepted Context uses its exact approval deadline. A prepared-origin row that lost Context has no target-clock deadline, so local cancellation remains durable but the sender transmits no Cancel. The runtime answers every other operation with generic Failure. Terminal Context and Completion must close cleanly before the joining store commits them. The wire-facing pending recovery path uses PairingStatus with both TLS authorities and exact request. No half-paired state is a peer credential. The normal-peer link owns the fresh normal-peer connection after bilateral activation. Pairing uses its own TLS role and exporter and never invokes the client gateway adapter. The same ceremony may be carried over a restricted routed pairing connection; relays do not interpret its private context.

Authority and checks

  • Wire, cryptography and bounded Unix-second arithmetic: internal/agenthub/invitationwire and fixture literals. Ceremony and store callers share the time bounds; the store keeps its own arithmetic-error diagnostic.
  • Session lifecycle and erasure: internal/agenthub/invitation tests.
  • Durable transitions: storage.
  • Direct operator transcript: direct handshake.
  • Current first-merge ownership: contract inventory.

Claimed-content, result installation and owner approval select closed admission or endpoint hooks too. ClientSession.PersistClaimed uses the session's immutable policy and exact request, never the purpose asserted by received content. It retains persist-before-ACK. Explicit client installers and owner-outcome hooks reject the other role before installing a recovery credential, disclosing an approved replay or mutating trust. The common client progression performs exact content/receipt validation, while policy hooks retain admission lineage/address installation and endpoint descriptor/secret installation separately.

Static context construction also has closed NewAdmissionContext and NewEndpointContext hooks; runtime dispatch is private codec parsing only. The invitation TLS scheduler is endpoint-only, through QueueEndpointTLS and AcquireEndpointTLS. The public admission/pairing TLS worker remains owned by the existing generic entry scheduler. Shipped pairing reserves its challenge after mutual TLS, then sends Challenge before selector/proof. No unused pairing TLS-lane variant or test-only composition remains.

DisplaySecret.Close erases the structured word/indices combination. TakeString consumes it into the one display copy. Admin closes the returned holder on all presentation errors and consumes it before returning a card. The origin closes each generated copy on success, collision retry and error. This erases mutable structured owners, not immutable returned strings or public word-list storage. Pairing's pointer-owned JOIN input consumes and clears the caller array at entry; the service clears its parse owner before launching a separately owned worker holder, which is cleared on every exit.

Typed local administration boundary

Typed private administration dispatches concrete ezhubapi.CreateInvitationRequest, approval, rejection, cancellation and revoke/regrant requests to the existing closed manager/store hooks. Immutable claimant locks, persist-before-ACK, exact revisions, security time and committed effects are unchanged. One-time cards use owned Secret bytes and require client ReleaseResult even after failed display; ordinary formatting is redacted. Persistence uncertainty is a typed local error with no success effect or success audit. This changes neither invitation frames nor durable records. See private administration.