Repository navigation
fix(registry): resolve notification owners through the registry identity key - #8325
Conversation
…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]>
There was a problem hiding this comment.
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
resolveAgentOwnerUserIdsandisAgentPublicresolve throughregistryAgentUrlKeySpellings. 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_urlcorrectly 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/requestedAgentUrlsharness 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]>
There was a problem hiding this comment.
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 viaregistryAgentUrlKey(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, andDISTINCT+ORDER BY om.workos_user_idmakesLIMIT 5deterministic. - Swallowed-error log correctly moved debug→warn;
isAgentPublicfolds 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.
Problem
resolveAgentOwnerUserIdsinserver/src/notifications/compliance.tsmatched owners by the rawagent_url, while the registry identity key folds a non-root trailing slash (#7830):/mcpand/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[].urlfirst (routes/member-agents.ts, the member create/update paths inroutes/member-profiles.ts), but the adminPUT /api/admin/member-profiles/:idhandler still writesagentsthrough unkeyed, so new ones keep appearing — tracked separately in #8322.Fix
registryAgentUrlKeySpellings(new, inserver/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:.../mcp?t=1yields.../mcp/?t=1and 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,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::jsonbper spelling so the GIN index onmember_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, anddeclared_urlis 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 5was 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.debug→warn, since the callers read an empty result as "nobody owns this agent".isAgentPublicfolds 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 adeclared_urlnegative.server/tests/integration/compliance-notification-owner-url-key.test.ts— the real SQL against Postgres. The unit test mocksquery, 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
node scripts/check-changeset-protocol-scope.cjs origin/mainpasses with no protocol surface touched.services/agent-ownership.ts,badge-issuance.ts,verification-profile-db.tsandcompliance-db.tshave the same raw-match shape, but they are authorization predicates — widening them with an identity-fold helper is whatregistryAgentUrlKey'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.isAgentPublichas no org scoping. Pre-existing, extended in reach by the fold: any profile in any org marking any matching spellingpublicopens the shared-channel gate. Called out explicitly because it is a disclosure gate, not because this PR changed its scoping.ADCP_TIMEOUT_SCALE=8was 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-reviewerandsecurity-reviewersubagents; every finding is either fixed above or answered in these notes.Closes #8321
🤖 Generated with Claude Code
Open workspace in Conductor