Skip to content

fix(registry): resolve notification owners through the registry identity key - #8325

Merged
bokelley merged 2 commits into
mainfrom
fix/8321-notification-owner-url-key
Oct 19, 2026
Merged

bokelley merged 2 commits into
mainfrom
fix/8321-notification-owner-url-key

Conversation

@bokelley

@bokelley bokelley commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

resolveAgentOwnerUserIds in server/src/notifications/compliance.ts matched owners by the raw agent_url, while the registry identity key folds a non-root trailing slash (#7830): /mcp and /mcp/ are one agent. An owner whose member profile holds the other spelling matched nothing, so every owner notification the registry sends about that agent was dropped — compliance regression and recovery, verification badge earned and lost, the heartbeat-timeout notice from #8319, and the extended-outage alert. It failed closed and silently: no DM, no error, indistinguishable from "nobody registered this agent".

The unfolded rows are not only historical. Most writers key agents[].url first (routes/member-agents.ts, the member create/update paths in routes/member-profiles.ts), but the admin PUT /api/admin/member-profiles/:id handler still writes agents through unkeyed, so new ones keep appearing — tracked separately in #8322.

Fix

registryAgentUrlKeySpellings (new, in server/src/db/registry-agent-url-key.ts) returns every spelling that folds to one agent's identity key. SQL may not canonicalize agent URLs (module header), so a JSONB-keyed store cannot fold the stored side in the query; it can only ask for the spellings that fold to the same key. The set is:

  • the key,
  • the key's path carrying the slash the fold removed — put back on the path, not on the end of the key, so .../mcp?t=1 yields .../mcp/?t=1 and never a slash inside the query; the root-with-query case is the mirror, where the sibling is the spelling without the slash the key keeps,
  • the caller's own spelling when it differs from both.

Every returned spelling is re-verified to key back to the same identity before it is returned, so a lookup built from the set can never reach a second agent. It is deliberately not a complete inverse of the key — host case, default port, dot segments, IDN and the pre-#7830 whole-URL lowercase are migration territory (scripts/migrate-registry-agent-url-keys.ts), not read-side guesses.

The owner lookup ORs one mp.agents @> $N::jsonb per spelling so the GIN index on member_profiles.agents (migration 014) still serves it; the clause is assembled from placeholder indexes only, with no caller text reaching the SQL text. Org scoping is unchanged, and declared_url is not consulted — that is the spec-exact AUTHORIZATION spelling (#7829) and must never decide identity.

Three smaller corrections in the same function, each flagged in review:

  • DISTINCT — two orgs can co-claim one agent and a user can belong to both, which previously burned two of the five slots on one person.
  • ORDER BY om.workos_user_id — LIMIT 5 was otherwise truncating planner-dependently, and silently dropping the true owner for a co-claimant is the same fail-quiet class this PR exists to close.
  • The swallowed-error log moves debug → warn, since the callers read an empty result as "nobody owns this agent".

isAgentPublic folds the same way. It gates the shared-channel post; leaving it raw would suppress the post for exactly the agents this fix reaches. It cannot newly disclose a private agent: the gate is "some owner listed this agent public", and every spelling it now matches is the same agent by the identity key's own definition.

Tests

  • server/tests/unit/compliance-notification-owner-spelling.test.ts — all four notification types with an owner profile storing the trailing-slash spelling, plus the mirror direction (caller holds the slash, profile holds the key), the exact spelling set asked for, org scoping, and a declared_url negative.
  • server/tests/integration/compliance-notification-owner-url-key.test.ts — the real SQL against Postgres. The unit test mocks query, so it cannot catch a placeholder-count slip or a bad ::text[] cast, and both notifier queries swallow every error. Covers both spelling directions, two orgs with different spellings, the public/private channel gate, and the negative case for a different agent sharing the URL prefix.
  • server/tests/unit/registry-agent-url-key.test.ts — the helper's contract, including a loop asserting every returned spelling keys back to the input's identity.

All of these fail if the fold is removed (verified by reverting it locally: 6/7 unit and 5/6 integration go red).

Notes for reviewers

  • No changeset. Server-only; node scripts/check-changeset-protocol-scope.cjs origin/main passes with no protocol surface touched.
  • The fix is deliberately reader-local. services/agent-ownership.ts, badge-issuance.ts, verification-profile-db.ts and compliance-db.ts have the same raw-match shape, but they are authorization predicates — widening them with an identity-fold helper is what registryAgentUrlKey's own doc comment forbids. Their asymmetry (DM says "your agent", dashboard 403s) is the safe direction. That, plus the unkeyed admin writer, is Agent-URL identity reads match the stored agents[].url raw, and the admin profile writer stores it unkeyed #8322.
  • isAgentPublic has no org scoping. Pre-existing, extended in reach by the fold: any profile in any org marking any matching spelling public opens the shared-channel gate. Called out explicitly because it is a disclosure gate, not because this PR changed its scoping.
  • No hooks skipped. The pre-commit suite ran in full; ADCP_TIMEOUT_SCALE=8 was set to stretch the kill budget on a loaded sandbox, which only moves the deadline and never weakens what runs. The pre-push storyboard matrix skipped itself (no training-agent or compliance changes).

Reviewed before opening by the code-reviewer and security-reviewer subagents; every finding is either fixed above or answered in these notes.

Closes #8321

🤖 Generated with Claude Code


Open workspace in Conductor

…ity key

`resolveAgentOwnerUserIds` matched owners by the raw `agent_url` while the
registry identity key folds a non-root trailing slash (#7830): `/mcp` and
`/mcp/` are one agent. An owner profile holding the other spelling matched
nothing, so compliance regression/recovery, verification badge changes, the
heartbeat-timeout notice from #8319, and extended-outage alerts all failed
closed and silently — no DM, no error.

The notifiers now resolve recipients through every spelling that folds to the
agent's identity key. SQL may not canonicalize agent URLs, so the stored side
cannot be folded in the query; the new `registryAgentUrlKeySpellings` returns
the key, the key's path carrying the slash the fold removed, and the caller's
own spelling, each verified to key back to the same identity so a lookup can
never reach a second agent. Org scoping is unchanged, and `declared_url` is
not consulted — that is the spec-exact authorization spelling (#7829) and must
never decide identity.

`isAgentPublic` folds the same way: it gates the shared-channel post, and
leaving it raw would suppress the post for exactly the agents this reaches.
The owner lookup also gains `DISTINCT` (two orgs can co-claim one agent) and
an `ORDER BY`, so the `LIMIT 5` cap no longer truncates planner-dependently,
and its swallowed-error log moves from debug to warn — the callers read an
empty result as "nobody owns this", so a silent query failure is
indistinguishable from a correct silence.

Unit tests pin which spellings are asked for; an integration test runs the
real SQL against Postgres, including the negative case for a different agent
sharing the URL prefix. Both fail if the fold is removed.

Readers in `services/agent-ownership.ts`, `badge-issuance.ts`,
`verification-profile-db.ts` and `compliance-db.ts` have the same shape, as
does the admin `PUT /api/admin/member-profiles/:id` writer that still stores
`agents[].url` unkeyed. Those are authorization predicates and a writer, not
notification delivery, and are tracked in #8322 rather than widened here.

Closes #8321

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
aao-secretariat[bot]
aao-secretariat Bot previously approved these changes Oct 19, 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 — server-only compliance notification fix (#8321) with no blocking or medium findings.

What I checked:

  • The change folds the trailing-slash agent URL spelling (#7830) so resolveAgentOwnerUserIds and isAgentPublic resolve through registryAgentUrlKeySpellings. The helper re-keys every returned spelling back to the same identity (registry-agent-url-key.ts:61), so it cannot widen past a single agent.
  • Both SQL rewrites are placeholder-parameterized only (compliance.ts:113-131, :160) — no injection surface. DISTINCT/ORDER-BY-on-selected-column is valid.
  • Error handling: the debug→warn upgrade on the owner lookup is correct (empty result = "nobody owns this"); isAgentPublic's silent catch remains fail-closed (no disclosure). No durable/billing path hidden.
  • declared_url correctly never consulted for identity (#7829).
  • No protocol surface touched (static/schemas/source/**, docs/reference, dist artifacts) → no changeset required, consistent with the changeset-scope rule.
  • Test coverage is sound: the asked/requestedAgentUrls harness turns every assertion red if the fold is removed; root, root-with-query, and non-root+query slash cases are covered.

No critical/high/medium findings. high_risk is false, gated_paths is false, no author team gate, no prior decision. Note: review_decision is REVIEW_REQUIRED, but row 2 only applies when gated_paths is true (it is false here), so no gate forces escalate. Falls through to row 9 → approve.

… substring

CodeQL's `js/incomplete-url-substring-sanitization` fired on
`requestedAgentUrls(params).includes(URL)` in the #8321 unit test. The receiver
is a `string[]`, so `includes` was already an exact element match and the alert
is a false positive — but `some((url) => url === …)` says that unambiguously
and costs nothing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@bokelley bokelley added the ladon/force-review Force Ladon to review the next eligible PR event label Oct 19, 2026 — with conductor.build App

@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 — server-only compliance notification fix, no blocking or medium findings.

This PR resolves compliance notification owners through the registry identity key so a profile holding the alternate trailing-slash spelling of a folded agent still receives the DM. The reviewer verified:

  • registryAgentUrlKeySpellings (registry-agent-url-key.ts:46-63) re-checks every returned spelling via registryAgentUrlKey(sibling) === key, so the set can never leak to a second agent; the root-with-query mirror case inverts correctly.
  • The owner lookup builds its OR-ed @> clause from placeholder indexes only (no caller text in SQL), the GIN index still serves it, and DISTINCT + ORDER BY om.workos_user_id makes LIMIT 5 deterministic.
  • Swallowed-error log correctly moved debug→warn; isAgentPublic folds the same way and fails closed.
  • No protocol surface touched (static/schemas/source/**, docs/reference, dist artifacts all untouched), so the no-changeset claim holds. Largest file is a 251-line test whose assertions match the helper's two-spelling output.

Decision table: no critical/high/medium findings. gated_paths is false, so row 2 (REVIEW_REQUIRED) does not fire. high_risk is false. No no-auto-approve team match. Prior decision was already approve. Falls through to row 9 → approve.

@bokelley
bokelley merged commit eec2d05 into main Oct 19, 2026
35 checks passed
@bokelley
bokelley deleted the fix/8321-notification-owner-url-key branch October 19, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ladon/force-review Force Ladon to review the next eligible PR event

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notification owner lookup matches raw agent_url, missing owners after trailing-slash folding

2 participants