Skip to content

fix(registry): bind OAuth issuers and adopt SDK 15 - #7968

Merged
bokelley merged 9 commits into
mainfrom
bokelley/bootstrap-v9
Oct 9, 2026
Merged

bokelley merged 9 commits into
mainfrom
bokelley/bootstrap-v9

Conversation

@bokelley

@bokelley bokelley commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Saved owner OAuth credentials lacked issuer bindings, and SDK endpoint discovery could hide the resulting refusal as a generic connection failure. This change adopts the authenticated published SDK 15.0.0 and patched MCP dependencies, persists separate token/client issuer bindings, and gives owners an explicit recovery action before discovery obscures the error.

Fresh owner sign-in privately stages registration and replaces the client and grant only after authorization succeeds and an atomic, organization-scoped comparison confirms the captured credential state and owner generation. Disconnecting or replacing credentials invalidates pending completion, including an initially empty row. Ordinary sign-in retains a stamped client with its registered redirect. Existing unstamped grants require owner sign-in; their next background heartbeat can refuse authentication and affect status or notifications until the owner recovers; issuer trust is never inferred from discovery. A changed authorization server may still require independently trusted client configuration. These guards cannot undo an authorization-server request or coordinate refresh-token rotation across workers.

Registry and Addie owner discovery use the SDK's public, config-only provider methods to catch missing bindings before network activity. Finite plain AUTH_MISSING/AUTH_REQUIRED failures now map to AUTHENTICATION_REQUIRED and HTTP 401. Finite SDK owner errors select the existing recovery screen with an explicit fresh-sign-in click; ordinary 401 responses remain ordinary, and unknown codes provide no recovery link. Pending client secrets remain encrypted and tenant-bound. Public callbacks expose fixed messages instead of upstream descriptions. Pure failure classifications run outside request-controlled presentation branches while preserving mandatory browser-state binding and the provider-error return before token exchange. Trusted completion-page tests handle uppercase and mixed-case script tags using literal test-page replacements.

The cumulative change also pins hosted probes to the selected compliance target, clears stale static bearer material atomically when saving client credentials, and adds the ownership-scoped DELETE connection route with its generated OpenAPI operation. It retains the reviewed loopback fixture timeout correction, URL-key read-only audit, Sharp 0.35.5/native updates, proxy address trust correction, and targeted dependency repairs. Current main's governance floors, account rejection behavior, schema and tool-catalog corrections are preserved. C4 learner instructions, exact unit/integration compliance-runner provenance expectations, and current SDK guidance now use SDK 15.0.0, with their existing strict assertions retained. Six generic compiler outputs are synchronized to their TypeScript sources with a descriptive PATCH changeset; versioned release artifacts are unchanged.

Current candidate: bf6749d43087e0dfcef3d26c6619962f26cd45c4, refreshed against main 24b504a287e71dd9f8a53116e1fd1bf9d86911ec. Three SDK discovery conflicts were resolved through the existing hosted-capability options helper, retaining explicit pinned-target discovery and major-only discovery for unseeded targets. Two newly imported tests now expect the SDK 15 pinned-target auto envelope; the exact version pins and unseeded assertions remain strict. The original focused run's two assertion failures are retained; the two affected suites then passed all 26 cases after that correction.

The actual merge commit's stock hook passed 1,106 root tests and 12,356 server tests, with 31 existing optional skips; both type checks and normal guards passed. The installed official Changesets CLI reports a PATCH against current main. The actual feature push passed version sync, changeset policy, schema-link lint and all 49 navigation checks. Its first local advisory storyboard run completed /signals (54 clean, 123 passing steps) and was explicitly interrupted during sales because isolated case startup took about 30 seconds here. The partial logs and interruption are preserved. The subsequent push used the documented ADCP_SKIP_STORYBOARD_MATRIX=1 option; local current/compatibility matrices are incomplete, and every authoritative GitHub storyboard check remains required. No other hook was skipped. The lockfile, historical release artifacts and source after hooks remain exact.

Fresh CI, CodeQL, resolved review threads and formal non-author maintainer review on this new head are prerequisites for merge. The prior-head qualification below does not transfer service checks or review approval to this refresh. Migration 617/618 on this PR must land before the unpublished bylaws migration currently numbered 617 in #7984 is renumbered and qualified.

Prior-head qualification (3d32fcf170c96c5f607c80e2e7f1ea2c45832132, retained):

  • Official SDK archive integrity, source/workflow Sigstore identity, all 999 historical cached artifacts, and all 6,378 installed file hashes match the qualified publication.
  • Disposable PostgreSQL and actual SDK/local HTTP integration: 122 passed, including staged registration, bound non-DCR reuse, issuer-mismatch refusal and owner cancellation. Related runtime cases: 162 passed.
  • Identical final readiness controls fail twice on the original source, where HTTP 200 discovery masks the OAuth error; the patched seven related suites pass 67 cases, including zero network requests on missing-binding refusal. Earlier recovery regressions and fixture failures remain preserved.
  • Complete PostgreSQL route integration: original 63 passed / 5 failed becomes 68 passed after strict runner checkpoints and the positive fixture’s synthetic issuer binding are corrected. Actual TypeScript conformance probe dispatches 125 cases with the same protocol digest, counts and one existing schema finding; its baseline changes only SDK version. The normal conformance report still exits 1 for that finding. Python/Go historical entries are retained, with complete fresh multilingual CI required.
  • Actual type checks, build, canonical OpenAPI and candidate changeset classification pass. Seven fresh source reviews plus independent code, protocol and security reviews approve the final frozen tree 99a54002d6252661e05ddcd38e0493e2ccb62210. Codex source reviews used the supplied complete patch because the read-only shell was unavailable; they are not independent test executions.
  • Earlier full-hook failures from stale SDK checkpoint literals and the a58 CodeQL check’s three HIGH findings remain recorded. After strict checkpoint corrections, the a58 hook passed; the subsequent three-file CodeQL correction preserves all other 57 candidate entries and adds seven meaningful preservation/extraction cases. Identical new controls show original 51 passed / 2 extraction failures, then 53 passed with the correction. The final normal hook exits 0: root 72 files / 1,106 passed; full server 737 files / 12,339 passed / 31 existing optional skips; both type checks and guards pass, with no retry. Commit 3d32fcf170c96c5f607c80e2e7f1ea2c45832132 preserves reviewed tree 99a54002d6252661e05ddcd38e0493e2ccb62210. Normal push checks exit 0, including version sync and exact-base PATCH policy. The incremental three-file push legitimately skips docs and storyboard checks; the preceding cumulative push passed schema links and all 49 navigation checks. The actual separate CodeQL service check 112609510697 succeeds on this exact head with zero annotations. On that prior head, all service checks succeeded, including Build Check, migration smoke, dependency review, governance, every sales cell and the required storyboard floors. The first /si attempt failed during npm ci with ECONNRESET before any scenarios ran; one normal targeted retry completed successfully through installation, storyboards and required floors, with the original failure retained. Other workflows pass on their first attempt. Required formal non-author maintainer review and a fresh main/migration fence remain prerequisites for merge.

The production audit is intentionally blocking for high/critical advisories and lookup failures. The exact workflow command exits 0 with no high/critical findings; eight moderate and one low finding remain visible. The full development graph still has 44 advisories, including an optional Mintlify-only legacy MCP copy. Local hooks use the supported SKIP_REPO_SYNC=true docs cache. The local advisory storyboard matrix may be skipped explicitly; authoritative CI retains every required floor and assertion.

The credential comparison currently casts the UUID key to text, so owner sign-in assertions may scan the context table; an indexed predicate optimization is a separate follow-up. Captured timestamp text also assumes consistent database session settings and fails closed if those differ. No customer grant operation, production credential change, URL-key migration, deployment or historical-cause claim is included. Addresses #6054, #7828, #7823 and #7830; remaining replay/runtime work is tracked separately under #7899.

Current-main cleanup qualification (2026-10-09)

Refreshed with main at 4d45452d5b24ec5b27cb0ac6512ae563b77fabac. Both merge conflicts were resolved using main’s exact two test files; the existing 60-second compiler deadline remains unchanged. Main already uses migration 617 for adopted bylaws, so the two unmerged OAuth migrations are now 618 and 619, with SQL bytes preserved and integration references updated. Dependent #8012 must restack and renumber its migration 619 to the next free number (expected 620).

Normal pre-commit checks passed: 1,106 root tests, 740 server unit files (12,367 passed, 31 skipped), boundary guards, server typecheck and rollout test-aware typecheck. The migration regression suite also passed all 26 tests. Earlier interrupted runs, the migration collision failure and a local documentation-cache disk exhaustion are retained in the workspace receipts; required root/server tests, guards and typechecks ran unchanged. The local doc cache uses the supported Docker-style no-Git reader, with actual refreshed AdCP source docs.

Three failed Sales shards on the old GitHub run never started: GitHub reported five runner acquisition failures per job. That does not qualify the source. Fresh current-head CI, CodeQL and human workflow review remain required. Read-only Sonnet review verified SDK15 can refresh during discovery, but the server has no fenced SDK-refresh persistence adapter. Enabling that refresh could consume a rotated refresh grant without saving its replacement, so the existing bearer-only probe behavior is retained pending a proper persisted-storage design.

Local push qualification: all 49 navigation checks passed after fetching the current stable origin/3.2.x reference; the earlier failure came from a stale local ref, with no docs source change required. The advisory matrix passed /signals (54 clean, 123 passing steps), including its required exact governance routing and wholesale checks. The subsequent isolated Sales cases took roughly30–40 seconds each. The remaining local current/3.0-compatibility matrix was deferred using the explicitly documented loaded-VM ADCP_SKIP_STORYBOARD_MATRIX=1 option in .agents/playbook.md. Normal version, changeset and docs push checks passed. No complete local Sales/compatibility pass is claimed; fresh authoritative GitHub storyboard and compatibility gates remain required before merge.

aao-secretariat[bot]
aao-secretariat Bot previously approved these changes Oct 6, 2026

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ladon verdict: Approve

Approve — clean server/app/Addie/deps PR with no blocking findings.

Checked against the decision table top-down:

  • No critical/high/medium findings (row 1, 4, 5, 8 — no fire).
  • gated_paths: false, so row 2 does not apply despite review_decision: REVIEW_REQUIRED.
  • high_risk: true but all reasons are (modified) with no medium-or-higher finding on those files — row 3 (deleted) and row 5 (modified + medium) do not fire. New-file/modified high-risk globs alone are not escalation-worthy.
  • No no-auto-approve team match (row 7 — no fire).
  • No prior decision (row 6 — no fire).
  • No static/schemas/source/** surface touched, so schema↔docs coherence, changeset-scope, oneOf, released-artifact-immutability, and 3.1.x gates do not apply. The body correctly declines a changeset per repo rules for an app/Addie/deps PR.

Falls through to row 9 → approve.

Substantive review confirms the three fixes land with regression tests: hostedCapabilityDiscoveryOptions target-pinning (compliance-testing.ts:65), atomic OAuth client-credential reset (agent-context-db.ts:1040, harmless given the non-null auth_token_encrypted resolver guard), and the fail-closed idempotent DELETE /connect route (registry-api.ts:9582). The audit rewrite is read-only (REPEATABLE READ READ ONLY, 30s statement_timeout, --apply throws before connecting, identifiers quoted from information_schema). proxy-addr 2.0.7→2.0.8 bump carries a CVE regression test. No certification self-report route, no money/auth-bypass surface.

aao-secretariat[bot]
aao-secretariat Bot previously approved these changes Oct 6, 2026

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ladon verdict: Approve

Approve.

This is a subsequent pass on PR #7968 (prior decision: approve, clean). The only delta is the OpenAPI delete operation for removeAgentAuthToken on /api/registry/agents/{encodedUrl}/connect in static/openapi/registry.yaml. It is coherent with the already-reviewed route handler in registry-api.ts: path, params (encodedUrl, org), bearerAuth/oauth2 security, and the 204/400/401/403/500 response set all match.

This touches the platform registry API surface, not the AdCP protocol schema under static/schemas/source/**, so no changeset, wire-shape, oneOf, or schema↔docs coherence concern applies. No breaking-class protocol change is present.

Decision table: no critical/high/medium findings (row 1 N/A). gated_paths is false (row 2 N/A). high_risk is true but all reasons are (modified) with no medium-or-higher finding, and none are (deleted) (rows 3–5 N/A). Prior decision was approve, not escalate (row 6 N/A). No no-auto-approve team match (row 7 N/A). Zero medium findings (row 8 N/A). Falls through to row 9 → approve.

aao-secretariat[bot]
aao-secretariat Bot previously approved these changes Oct 6, 2026

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ladon verdict: Approve

Approve — clean subsequent pass.

This is a subsequent review on top of a prior approve. The delta since the last head is entirely a merge of main — each change maps to an already-reviewed, already-merged commit (#7936 print_metrics, #7965 budget periods, #7946 version envelope, #7895 operation_id, #7950 provenance hoist). The PR's own 20-file changeset (compliance/credentials/probes/URL-audit) is unchanged from the previously-clean review. The reviewer did coverage on the largest delta logic (governance-budget-periods matchBudgetPeriod handling and build-schemas hoistBySourceIdentity guards) and found nothing actionable.

No critical/high/medium findings in this run; no prior blockers to re-evaluate.

Decision table: Row 1 (no critical/high) — no. Row 2 (gated_paths) — gated_paths is false, so N/A despite review_decision=REVIEW_REQUIRED. Row 3 (deleted high-risk) — no deletions. Rows 4/5 (medium findings) — no medium findings. Row 6 (sticky escalate) — prior was approve, N/A. Row 7 (no-auto-approve team) — no match. Row 8 (3+ medium) — none. Falls through to Row 9 → approve.

high_risk is true only via (modified) entries under server/src/addie/** and server/src/routes/**, but with no medium-or-higher findings on those files the modifications are presumed safe and the flag alone does not escalate.

@bokelley
bokelley marked this pull request as draft October 7, 2026 02:07
@bokelley bokelley changed the title fix(compliance): correct hosted credentials, probes, and URL audit fix(registry): bind OAuth issuers and adopt SDK 15 Oct 7, 2026
@bokelley
bokelley marked this pull request as ready for review October 7, 2026 02:14
Comment thread server/src/routes/agent-oauth.ts Fixed

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ladon verdict: Escalate to human review

Escalate — gated path requires human/CODEOWNERS review.

This PR modifies .github/workflows/build-check.yml, which matches a deterministic hard approval gate (gated_paths: true). The current review_decision is REVIEW_REQUIRED, not APPROVED, so the gate is not satisfied and the PR cannot be auto-approved (decision table row 2).

Findings: Clean pass. The reviewer found no Critical/High/Medium defects in the owner-OAuth hardening delta (CAS state machine, encrypted staging and bound-reuse refusal, issuer-binding migrations 617/618, opt-in owner-readiness throw, error classification, ownership-gated DELETE connect route). The two disclosed follow-ups (UUID-cast/timestamp-session) fail closed and are noted in the PR body. The new migrations 617/618 are (added) (not escalation-worthy on the flag alone), and the modified dist/** and server/src/addie/** files carry no medium-or-higher findings, so the high-risk flag alone does not escalate.

Escalation reasons:

  • .github/workflows/build-check.yml is under a hard approval gate and review_decision is REVIEW_REQUIRED. A human/CODEOWNERS approval is required before this PR can merge.

Note: the prior run approved on an earlier head, but this run's gated-path + non-approved review status forces escalation per row 2.

Why human review

  • .github/workflows/build-check.yml is under a hard approval gate (gated_paths: true) and review_decision is REVIEW_REQUIRED — human/CODEOWNERS approval is required before merge.
  • This PR touches a path under a hard, non-overridable approval gate (.github/workflows/build-check.yml (modified) matches .github/workflows/**) and the current GitHub review decision is 'REVIEW_REQUIRED', not APPROVED. This is a hard gate enforced in code — Ladon cannot auto-approve until a human/CODEOWNERS approval is recorded, regardless of how clean the diff is.

@aao-secretariat aao-secretariat Bot added the ladon/needs-human-review Ladon has escalated this PR for human review. label Oct 7, 2026

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ladon verdict: Escalate to human review

Escalate — hard approval gate not satisfied.

This PR modifies .github/workflows/build-check.yml, which is under a hard, deterministic approval gate (gated_paths: true). The current review_decision is unknown/none — not APPROVED. Per decision rule row 2, Ladon cannot auto-approve until a human/CODEOWNERS approval is recorded, regardless of how clean the diff is.

Escalation reasons

  • .github/workflows/build-check.yml (modified) is under a hard approval gate (gated_paths: true) and review_decision is not APPROVED. Human/CODEOWNERS approval is required before merge.

The reviewer reported a clean delta: the agent-oauth.ts changes (ownerReauthorizationRequired/providerErrorCode hoisting) are behavior-preserving extractions, the publicOAuthCode string-type guard correctly maps array-valued error to the authorization_failed fallback, and the remaining delta is test coverage for real security branches. No Critical/High/Medium findings were surfaced. The two new migrations (617, 618) are additions. This matches the prior pass, which also had no blockers.

Once a human/CODEOWNERS approval moves review_decision to APPROVED, the gate lifts and this clean diff can fall through to approval.

Why human review

  • .github/workflows/build-check.yml (modified) is under a hard approval gate (gated_paths: true) and review_decision is not APPROVED — human/CODEOWNERS approval required before merge.
  • This PR touches a path under a hard, non-overridable approval gate (.github/workflows/build-check.yml (modified) matches .github/workflows/**) and the current GitHub review decision is 'unknown', not APPROVED. This is a hard gate enforced in code — Ladon cannot auto-approve until a human/CODEOWNERS approval is recorded, regardless of how clean the diff is.

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ladon verdict: Escalate to human review

Escalate — hard approval gate not satisfied.

This PR modifies .github/workflows/build-check.yml, which is under a hard, non-overridable approval gate (gated_paths: true). The current review_decision is REVIEW_REQUIRED, not APPROVED. Per decision rule row 2, Ladon cannot auto-approve until a human/CODEOWNERS approval is recorded — regardless of how clean the diff is.

The reviewer returned a clean pass with no Critical/High/Medium findings. The property-grain delivery conformance feature, A2A signing errata + vectors, and controller-seeding gate are all already on main (confirmed absent from the PR delta). The genuine PR-authored content (OAuth issuer binding + SDK 15) is unchanged since the prior clean review. No blocking code-level findings exist.

Escalation reasons:

  • .github/workflows/build-check.yml (modified) is under a hard approval gate (gated_paths: true) and review_decision is REVIEW_REQUIRED, not APPROVED. Human/CODEOWNERS approval is required before merge.

This is consistent with the prior escalate decision, which stands because the gated-path condition remains unsatisfied.

Why human review

  • .github/workflows/build-check.yml (modified) matches a hard approval gate (.github/workflows/**) and review_decision is REVIEW_REQUIRED, not APPROVED — human/CODEOWNERS approval required before merge.
  • This PR touches a path under a hard, non-overridable approval gate (.github/workflows/build-check.yml (modified) matches .github/workflows/**) and the current GitHub review decision is 'REVIEW_REQUIRED', not APPROVED. This is a hard gate enforced in code — Ladon cannot auto-approve until a human/CODEOWNERS approval is recorded, regardless of how clean the diff is.

@bokelley
bokelley merged commit 5607468 into main Oct 9, 2026
62 checks passed
@bokelley
bokelley deleted the bokelley/bootstrap-v9 branch October 9, 2026 09:04
bokelley added a commit that referenced this pull request Oct 18, 2026
* fix(registry): key agents by AdCP URL canonicalization

The registry keyed agents by `lower(trim(agent_url))` with every trailing
slash stripped. AdCP URL canonicalization lowercases only the scheme and
host; path case and a non-root trailing slash are significant. The old key
therefore merged agents the spec says are distinct — `/tenants/Acme/mcp` and
`/tenants/acme/mcp` shared one key, so an authorization, a compliance badge
or an ownership claim could attach to the wrong agent — and failed to merge
agents the spec says are the same (`:443`, dot segments, `%7E`, IDN hosts).
After #7829 it is also an active matching regression: an agent served at
`/mcp/` stops matching in find_agents_for_property.

registryAgentUrlKey (server/src/db/registry-agent-url-key.ts) is now the one
implementation, delegating to canonicalTargetUri from @adcp/sdk/signing with
one registry-local rule: a root-served agent with no query loses its `/`, so
those keys stay byte-identical across the migration. canonicalizeAgentUrl is
a re-export, so every call site moves together, and the read-only audit from
#7968 imports the same function instead of carrying a copy.

SQL no longer canonicalizes agent URLs anywhere — the spec algorithm needs
IDN A-labels, dot-segment resolution and selective percent-decoding. Seven
queries in federated-index-db.ts take an app-computed key parameter; four
were restructured, including moving signing_keys_pinned out of the manifest
JSONB walk and giving reconcileAdagentsAuthorizations a FOR UPDATE
transaction in place of its single-statement form.

Migration 625 relaxes both CHECK constraints (NOT VALID, so a legacy key the
new shape rejects cannot fail the deploy), adds the key columns to
caa_emit_event's modified-event detection so a rewrite reaches change-feed
consumers, and folds both sides of the suppress join for bad_actor overrides
— exact equality would let a publisher lift a ban by editing one character
of path case.

The data rewrite is migrate-registry-agent-url-keys.ts: dry-run by default,
refusing to write while any store has a merge, a chain, an unkeyable row, an
unmodelled unique index, or a stranded suppression. Tables are discovered
from information_schema and must appear in REWRITE_STORES or
REPORT_ONLY_STORES, so a new store can be neither silently rewritten nor
silently left on the old key.

Three deliberate divergences from the comparer rules in
docs/reference/url-canonicalization, all because this is a producer-side key
rather than a signature comparison: userinfo is rejected rather than
stripped, a U-label host is converted rather than rejected, and query
percent-encoding is normalized where the SDK's 3.2 profile preserves raw
bytes for signature fidelity.

Refs #7830

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* test(registry): repin the canonicalization tests to spec semantics

Five integration tests asserted the pre-#7830 key: that a path-case or
trailing-slash variant collapses onto the same agent. Under AdCP URL
canonicalization it does not, so they now vary only what the key still
folds — scheme and host case, a default port, surrounding whitespace — and
member-agents-api gains a case proving `/mcp`, `/MCP` and `/mcp/` register
as three separate agents rather than upserting onto each other.

Regenerates static/openapi/registry.yaml for the agent_url parameter
description.

Refs #7830

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(registry): fold a trailing slash into the agent identity key

Maintainer decision on #7830: /mcp and /mcp/ are the same agent for
registry identity. The production collision listing bears it out — every
one of the 47 key collisions is a trailing-slash pair, root or non-root,
and there is not a single case-only, port, http/https or fragment variant
among them.

registryAgentUrlKey now strips trailing slashes from the path, on top of
canonicalTargetUri's scheme/host case, default port, dot segments and
percent-encoding. The one exception is a root path carrying a query, where
the slash stays so the query still reads as a query. This diverges from
docs/reference/url-canonicalization deliberately, and only for identity.

AUTHORIZATION MATCHING IS UNCHANGED. AgentValidator and everything that
decides whether an adagents.json entry authorizes an agent keep comparing
spec-exactly, with the trailing slash significant (#7829). The seam is
AgentConfig.declared_url: set only where the key folded something away, and
read through declaredAgentUrl() by find_agents_for_property and
properties.ts. registry-identity-vs-authorization.test.ts pins both halves
— a manifest listing /mcp/ authorizes /mcp/ and not /mcp, while the two key
identically. Every store and code path the key touches is classified as
identity, authorization or raw-matched in the helper's header.

Collisions are now resolved rather than blocked. registry-key-stores.ts
declares a per-table merge policy: which row survives and how each column
composes. Compliance status follows the freshest check; registry metadata
takes the conservative value for every gate it holds; a badge keeps the
active one over a revoked one; a ban can never be downgraded to a
correction; an authorization merge unions validity but never the grant.
No value is dropped silently — every merge lists the surviving row, the
rows that do not, and every field whose value the merged row does not
carry. agent_contexts and member_profiles.agents still have no policy and
still block, because a wrong merge there hands over credentials or
ownership.

The production gate is exact now. registry-agent-url-key-sql.ts is a SQL
twin of the key, held to the TypeScript helper by a corpus test, and
audit-registry-key-collisions.ts groups by it per table per unique index.
The old coarse gate rtrimmed every trailing slash and so reported path-case
variants as merge risks; this one reports exactly the groups Postgres would
reject, labelled by whether the migration rewrites that store.

Migration 625's CHECK follows the key: no trailing slash on the path
anywhere, with the root-plus-query exception.

`declared_url` is member-supplied and reaches the validator, so the
visibility gate only accepts it when it keys back to the same agent.
Otherwise a member could claim their own agent's identity and a
well-authorized agent's declared URL, and the directory would report theirs
as authorized wherever that one is.

Refs #7830

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(registry): keep the partial-index predicate through a key merge

The merge re-read in planMerges fetched rows by key and scope columns but
dropped the unique index's partial predicate. idx_caa_unique_active and
idx_aao_unique_active only constrain live rows, so the plan counted the
collision from active rows alone while the re-read pulled in every
tombstoned and superseded row sharing the same key and scope.

rankRows would then happily crown a dead row — a superseded bad_actor
override outranks a live correction, a soft-deleted authorization with a
fresh updated_at outranks the live grant — and applyMerges deleted the
live rows as losers. That drops an authorization or lifts a ban. The
DELETE and UPDATE omitted the predicate too, so they could reach rows the
plan never looked at.

MergeAction now carries the predicate and all three statements apply it,
so the group the plan describes and the group the apply touches are the
same set by construction.

The regression test seeds two live catalog_agent_authorizations rows plus
a tombstone on the same key and scope holding the freshest updated_at of
the three — the exact ranking trap. Reverting the fix makes it fail with
both live rows in loserKeys.

Found by the PR reviewer.

Refs #7830

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(registry): answer directory authorization reads spec-exactly

Maintainer decision on the open item in #8249. catalog_agent_authorizations
keeps keying by identity — the indexes stay on agent_url_canonical and the
folded key does the lookup work — but every per-agent read that answers "is
this agent authorized" now restricts to the raw agent_url values that are
spec-exactly the same agent. A publisher that authorized
https://a.example/mcp/ has not authorized https://a.example/mcp, and the
directory can no longer say otherwise in either direction.

specExactAgentUrls(agentUrl) resolves it: one indexed read of the distinct
raw spellings under the key, filtered through isSpecExactAgentMatch, passed
to the query as AND v.agent_url = ANY($n::text[]). A single agent has a
handful of spellings, so this is one small indexed read whatever the
registry's size, and an empty result correctly matches nothing.

Nine read sites carry it: getDomainsForAgent, getPublishersForAgentDetail,
bulkGetFirstAuthForAgents, getPropertiesForAgent,
getPropertiesForAgentDomain, getPublisherDomainsForAgent,
getAuthorizationSource, isPropertyAuthorizedForAgent, and
AuthorizationSnapshotDatabase.getNarrow.

validator.ts's normalizeUrl now calls through to the same specExactAgentUrl
the directory uses, so the two implementations cannot drift — which is the
actual guarantee being asked for.

getAllAgentDomainPairs is deliberately not filtered: it is the crawler's
bulk snapshot for diffing agent.discovered / agent.removed, an identity
enumeration rather than a per-agent authorization answer.

registry-directory-spec-exact.test.ts covers one case per read site plus a
cross-check that the directory and the AgentValidator agree. Neutering the
filter makes all ten fail.

The snapshot endpoint resolves against whichever relation its include mode
reads: an include=effective pull surfaces phantom rows from the override
layer that have no base row at all, so resolving against the base table
would filter every one of them out. The existing sync-endpoint test caught
exactly that.

Read-side only: no key, migration, merge policy or stored value changes, so
the collision gate and dry-run outputs are unaffected.

Refs #7830

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ladon/needs-human-review Ladon has escalated this PR for human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants