Repository navigation
feat(admin): transfer_brand_ownership tool for brand registry - #3159
Merged
Merged
Conversation
Adds an admin-only Addie tool that moves a brand domain from one WorkOS org to another, writing a full-row revision snapshot before updating workos_organization_id. Eliminates direct database surgery for acquisitions, org renames, and "original uploader left" cases. Refs #3152 https://claude.ai/code/session_01XmWfbQQkuuX3DB8VpukZsu
This was referenced Apr 25, 2026
Security/code review on #3159 surfaced four real items, all addressed: * Tool added to TOOL_SETS.admin.tools so the router actually surfaces it to Sonnet. Without this, the handler was registered but functionally unreachable through routed paths — same bug class as #2998. * new_org_id validated against `^org_[A-Z0-9]{20,}$` so a typo can't silently orphan a brand under a non-existent org id (no FK to catch it — workos_organization_id is a WorkOS string, not a local row). * reason capped at 1000 chars after the floor check so a prompt-injected long reason can't bloat the brand_revisions audit trail to MB. * Existence check on new_org_id against organizations table inside the transaction; rejects unowned brands (claim path, not transfer) and rejects same-org transfers; canonicalization moved into the DB method so future callers can't pass raw `Foo.COM` and miss the row. Return signature tightened: oldOrgId is now `string` (non-null) since unowned brands are rejected upstream. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bokelley
marked this pull request as ready for review
April 25, 2026 16:20
bokelley
added a commit
that referenced
this pull request
Apr 25, 2026
…n relinquish (#3168) * fix(brand-registry): file escalation on cross-org dispute + clear manifest on relinquish Two follow-ons to the transfer-tool work in #3159: - Brand-ownership disputes route through escalations now. The bare 403 from updateBrandIdentity becomes a category=needs_human_action ticket with the caller org, owner org, and brand domain in addie_context. Web route returns 409+escalation_id; chat tool replies "we filed it" with the ticket number. Admins resolve via the existing transfer_brand_ownership tool. - Relinquishing a hosted brand now clears brand_manifest. Before, only ownership fields were cleared, so a later soft-claim silently inherited the prior org's logos, colors, agents, and narrative copy. The row resets to a clean discovered state. BrandIdentityError gained a `code` discriminator and `meta` payload so callers can tell cross_org_ownership apart from validation errors. Closes the second part of #3152. Soft-claim with verified-domain takeover is still parked — pointer-only domain verification isn't strong enough to gate provenance changes without a real challenge/response. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Address review feedback on dispute escalation flow Three small items from code-reviewer on #3168, all addressed: * Chat false-promise on escalation failure. The previous code told the user "they'll resolve it and follow up" even when createEscalation rejected — a confidently false promise. Now branches on the null return: ticket-id message on success, "please email support" on silent failure. Web side now also flips its message text based on whether the escalation actually filed. * Tightened BrandIdentityError meta typing. Switched from Record<string, unknown> to a per-code interface (BrandIdentityErrorMetaByCode). Added an isCrossOrgOwnership() type guard so catch sites narrow both the discriminator and the meta payload — err.meta.brandDomain is now typed as string instead of unknown. Catches typos at compile time. * Caller email + display name added to addie_context so admins reading the escalation know who's asking without joining against a user table. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Flag-for-adoption + sensitive_topic categorization on dispute escalations Replaces the hard-reset behavior in #3168's first commit with the flag-for-adoption design adtech-product-expert recommended in review. * Migration 430 adds manifest_orphaned + prior_owner_org_id columns to brands. * deleteHostedBrand now sets manifest_orphaned=true and stashes the prior owner instead of clearing the brand_manifest. Paired with is_public=false so public reads still don't surface the orphaned identity, and resolveBrand in member-profiles.ts skips orphaned rows. * updateBrandIdentity gains an adoptPriorManifest flag. When the claimed brand is orphaned: default = clear and start fresh (safe against silent inheritance); opt-in = keep prior manifest and merge new claimant's logo/color over it (acquisition/handoff case). Either branch clears the orphan flag and reasserts is_public=true. Plumbed through to the PUT /brand-identity body as adopt_prior_manifest and surfaced in the response as adopted_prior_manifest. Escalation framing changes per adtech-product-expert review: * category switched from needs_human_action to sensitive_topic — these are governance/legal decisions, not routine triage. * Summary and addie_context rephrased to not presume bad faith. The dispute could equally be an acquisition, naming overlap, or someone backfilling on behalf of the registered org. Self-service "publish brand.json to auto-resolve" hint deferred until that path actually exists — filed as #3176. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Address review feedback: close orphan-leak vectors, force explicit decision Security review surfaced two H findings: the verify-by-pointer route bypassed the orphan logic (claimed-but-orphan = new owner with prior manifest), and two unauthenticated registry-resolve routes leaked the orphaned manifest before any claim. Code review surfaced a misleading result field. Adtech-product review pushed for explicit-decision-required on claim time. Changes: * claimOrphanedHostedBrand new DB method that atomically asserts ownership, marks verified, clears the orphan flag, and (default) resets the prior manifest. Verify-by-pointer route now uses this when hosted.manifest_orphaned is true. Without this, an org publishing a brand.json pointer at a relinquished domain became the verified owner with the prior org's logos still attached. * Public read paths now filter orphaned + non-public: - /api/brands/resolve and /api/brands/resolve/bulk - /api/me/community-profile/:slug brand resolution in http.ts - /api/referral/:code referrer logo lookup * HOSTED_BRAND_COLUMNS includes manifest_orphaned + prior_owner_org_id so every getHostedBrandByDomain caller can branch on orphan state. HostedBrand interface gained the matching optional fields. * brand-feeds getBrandForEdit rejects orphaned brands so feed/property edits can't write into the prior owner's manifest fields during the pre-claim window. * updateBrandIdentity now requires the orphan-adoption decision to be explicit. When manifest_orphaned and adoptPriorManifest is undefined, throws BrandIdentityError(409, 'orphan_manifest_decision_required') with the prior owner's org id in meta. Web route returns 409 with prior_owner_org_id in the body; chat tool replies with the choice question and prompts the user to re-run with adopt_prior_manifest set explicitly. * Result fields renamed: adoptedOrphanedManifest (which fired even on clear) split into claimedOrphanedBrand + keptPriorManifest. Web response now exposes claimed_orphaned_brand + kept_prior_manifest. * Cross-org dispute escalation summary now names the incumbent org too — "Brand ownership review: {domain} — claim by {claimant} vs current owner {incumbent}" — so admins triaging the queue see both parties at a glance. * update_company_logo tool gains an adopt_prior_manifest input so members can opt in via chat after the orphan-decision question. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #3152
Summary
Adds
transfer_brand_ownershipto Addie's admin tool panel. Admins can now move a brand domain from one WorkOS org to another via a single tool call, with a full-row revision snapshot written tobrand_revisionsbefore the ownership update. Eliminates direct database surgery for acquisitions, org renames, and "original uploader left" cases.What ships in this PR:
BrandDatabase.transferBrandOwnership(domain, newOrgId, reason, editor)—SELECT * FOR UPDATE→ revision INSERT →UPDATE workos_organization_id→ COMMITtransfer_brand_ownershipadmin tool inADMIN_TOOLS+ handler increateAdminToolHandlers--emptychangeset (server-only, no protocol impact)What is deferred (needs more design — see issue):
claim_disputed_brandmember tool — experts agree this should be adispute_type: 'brand_ownership'variant on the existing escalation schema, not a standalone MCP tool or new servicedeleteHostedBrandclearsworkos_organization_idbut notbrand_manifest, so an incoming org would inherit the prior org's brand data silently; (2)generateVerificationTokenis orphaned (no caller) — domain verification is currently pointer-only and can't safely gate a takeoverNon-breaking justification
Adds a new admin tool; no public schema or API surface changed. Existing callers unaffected.
Pre-PR review
SELECT id, workos_organization_id→SELECT *so revision snapshot captures full row; also addededitor.namepassthrough and normalizeddomain.toLowerCase()to one call)old_org_idin response is warranted,reasonmin-length bumped to 20 charsNits (not fixed, noted for follow-up):
escalation_idinput field would let Addie pass the ticket ref directly into the revisionedit_summaryrather than holding it across two tool callsreason.length < 20is still permissive; could tighten further if abuse observed in practiceSession: https://claude.ai/code/session_01XmWfbQQkuuX3DB8VpukZsu