Skip to content

Brand-domain resolver returns root domain but prior brand.json revisions live at www.* (Stage 2 #4159 drift) #4448

Closed

Description

@bokelley

Symptom

After the Stage 2 column drop (#4313, 5163d21425), getBrandPrimaryDomain(orgId) reads only organization_domains.is_primary=true. For some orgs that previously curated brand.json content at www.<domain>, the resolver now returns <domain> (no www), so the publish path writes manifest updates to a different registry row than the user has been editing.

Repro (Affinity Answers, escalation #334)

  • organization_domains row: affinityanswers.com, is_primary: true, verified: true, source: workos (created 2026-03-10).
  • brand_revisions for editor [email protected] (admin endpoint /api/admin/accounts/{orgId}/registry-activity):
    • 2026-05-04 05:46 — "Published brand agent to brand.json" on www.affinityanswers.com
    • 2026-05-04 12:39 — "Removed brand agent from brand.json" on www.affinityanswers.com
    • 2026-05-05 05:09 — "Published brand agent to brand.json" on www.affinityanswers.com
  • Their public website returns 404 at https://www.affinityanswers.com/brand.json (WordPress, no self-hosted brand.json); the AAO registry hosts the manifest. https://affinityanswers.com/brand.json returns 301 to www.
  • Current member-profile JSONB agent state: visibility: members_only. Not published.

applyAgentVisibility (member-profiles.ts:1412-1444) now resolves the brand-primary to affinityanswers.com, then calls brandDb.getDiscoveredBrandByDomain('affinityanswers.com'). If no row exists at that exact domain, the post-commit brandDb.updateManifestAgents('affinityanswers.com', ...) will either create a new empty row at the root domain — orphaning the prior www.* manifest the user had been curating — or fail outright depending on the table's constraints.

Why pre-Stage 2 it worked

The dropped member_profiles.primary_brand_domain column on this org likely held www.affinityanswers.com (the domain the brand registry crawler had previously seeded). The publish path read that column directly, so all prior writes consistently landed on the same brand row. Post-#4313 the resolver authority shifted to organization_domains.is_primary, which was populated by WorkOS domain verification at the root domain — no www.

Impact

  • Member publish flow appears to succeed but writes to a different brand row than the user previously curated, fracturing manifest state.
  • /api/me/agents/:index/check will report not_found because the agent is no longer in the manifest at the resolved domain.
  • Almost certainly affects orgs beyond Affinity — any org whose previous primary_brand_domain had a www prefix and whose WorkOS-verified domain is the root.

Proposed fix

  1. Audit: SQL across brand_revisions joined against organization_domains to find orgs with prior revisions on www.<domain> but organization_domains.is_primary=true on <domain> (or vice versa).
  2. Backfill: for affected orgs, decide canonical domain (prefer the one with revision history when there's no conflict), and either flip organization_domains.is_primary or merge the www.* brand row into the root row.
  3. Forward fix: the brand-domain resolver could optionally canonicalize www-stripping when the root has no brand row but www.<root> does — but the cleaner path is data-side reconciliation, not a runtime fallback.

References

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions