Skip to content

fix(server): emit agent_visibility_gate on profile response (#4159 follow-up) - #4509

Merged
bokelley merged 1 commit into
mainfrom
bokelley/fix-public-toggle-greyed
May 14, 2026
Merged

bokelley merged 1 commit into
mainfrom
bokelley/fix-public-toggle-greyed

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

Real escalation from Affinity Answers (Builder member) today: the "Public" visibility toggle on /dashboard/agents was greyed out despite their primary brand domain being verified.

Root cause. Stage 2 of #4159 (PR #4313) dropped member_profiles.primary_brand_domain and updated the bootstrap POST to re-derive the field via the resolver. The GET handler at member-profiles.ts:744 was missed — it returned the raw MemberProfile row without the re-derived field. The dashboard at dashboard-agents.html:1135 keyed its "is Public allowed?" gate on the presence of that field, so the toggle silently greyed out for every Builder/Member/Leader with a verified primary domain since #4313 shipped. Santhosh just happened to escalate.

Fix (two layers)

Layer 1 — restore the GET response. GET /api/me/member-profile (dev-mode + prod paths) now re-derives primary_brand_domain via getBrandPrimaryDomain(orgId) and merges it onto the returned profile, the same way the bootstrap POST already does via toSpecMemberProfile. This alone unblocks Santhosh and every other affected member, plus restores member-profile.html's brand-section display which had been silently broken too.

Layer 2 — eliminate the bug class. Adds computeAgentVisibilityGate({ hasApiAccess, brandPrimaryDomain }) next to the existing gateAgentVisibilityForCaller. Returns { can_publish_publicly, reasons: ('tier_required' | 'brand_domain_required')[] }. The GET response emits this as agent_visibility_gate. The dashboard's renderVisibilitySelector binds the toggle's disabled state and the upsell/nudge copy directly to that gate — same two preconditions the /publish endpoint already enforces server-side. The reverse-engineering from data-shape presence is gone, as is the redundant /api/brands/discovered/.../edit-status fetch the dashboard never actually used for its self-hosted vs community value.

Layer 3 — regression guard. Unit tests for the new helper (six cases) and integration tests in agent-visibility-e2e.test.ts that hit GET /api/me/member-profile for all four gate combinations. A failing GET-shape test would have caught the #4313 regression on day one.

Expert review notes

  • code-reviewer: gate predicate accurately mirrors both write-time enforcement paths; company_standard correctly maps to Builder. Asked for the changeset (added), the load-gap default question (addressed — defaults to brand_domain_required so the brand nudge renders during the sub-second load), and the deterministic-order assertion (addressed — .sort() dropped from the integration test).
  • adtech-product-expert: asked to update the upsell copy from "Upgrade to Professional" to "Upgrade to a paid AAO tier" (matches the disabled-state list and survives pricing changes) — done. Also flagged that is_primary doesn't imply verified — out of scope for this PR (matches today's write-side enforcement); worth a follow-up issue once PR feat(member): self-service domain add+verify via WorkOS DNS challenge #4440's verification flow is universal.

Test plan

  • npm run test:server-unit for agent-visibility-gate.test.ts — 16 pass (10 existing + 6 new)
  • npm run typecheck clean
  • CI: test:server-integration runs the new GET-shape tests against a real Postgres
  • Manual: Santhosh's affinityanswers.com toggle flips Public after deploy

🤖 Generated with Claude Code

…llow-up)

Stage 2 of #4159 (PR #4313) dropped `member_profiles.primary_brand_domain`
and updated the bootstrap POST to re-derive the field via the resolver.
The GET handler was missed, so the dashboard's "Public" visibility
toggle — which keyed off the presence of that field — silently greyed
out for every Builder/Member/Leader with a verified primary domain.
Affinity Answers escalated today.

Two-layer fix:

- GET /api/me/member-profile now re-derives `primary_brand_domain` and
  also emits `agent_visibility_gate: { can_publish_publicly, reasons[] }`,
  computed by a shared helper alongside `gateAgentVisibilityForCaller`.
  Same two preconditions the /publish endpoint enforces (tier +
  primary brand domain).

- dashboard-agents.html binds the toggle's disabled state and upsell
  copy directly to the server-computed gate. The reverse-engineered
  inference from data-shape presence — and the redundant /edit-status
  fetch the dashboard never actually used for its `self-hosted` vs
  `community` value — are gone.

Tests pin the predicate (unit) and the wire contract (integration) so
future schema changes can't silently flip the UI again.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley merged commit 868fac3 into main May 14, 2026
13 checks passed
@bokelley
bokelley deleted the bokelley/fix-public-toggle-greyed branch May 14, 2026 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant