Repository navigation
fix(server): emit agent_visibility_gate on profile response (#4159 follow-up) - #4509
Merged
Merged
Conversation
…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]>
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.
Summary
Real escalation from Affinity Answers (Builder member) today: the "Public" visibility toggle on
/dashboard/agentswas greyed out despite their primary brand domain being verified.Root cause. Stage 2 of #4159 (PR #4313) dropped
member_profiles.primary_brand_domainand updated the bootstrap POST to re-derive the field via the resolver. The GET handler atmember-profiles.ts:744was missed — it returned the rawMemberProfilerow without the re-derived field. The dashboard atdashboard-agents.html:1135keyed 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-derivesprimary_brand_domainviagetBrandPrimaryDomain(orgId)and merges it onto the returned profile, the same way the bootstrap POST already does viatoSpecMemberProfile. This alone unblocks Santhosh and every other affected member, plus restoresmember-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 existinggateAgentVisibilityForCaller. Returns{ can_publish_publicly, reasons: ('tier_required' | 'brand_domain_required')[] }. The GET response emits this asagent_visibility_gate. The dashboard'srenderVisibilitySelectorbinds the toggle'sdisabledstate and the upsell/nudge copy directly to that gate — same two preconditions the/publishendpoint already enforces server-side. The reverse-engineering from data-shape presence is gone, as is the redundant/api/brands/discovered/.../edit-statusfetch the dashboard never actually used for itsself-hostedvscommunityvalue.Layer 3 — regression guard. Unit tests for the new helper (six cases) and integration tests in
agent-visibility-e2e.test.tsthat hitGET /api/me/member-profilefor all four gate combinations. A failing GET-shape test would have caught the #4313 regression on day one.Expert review notes
company_standardcorrectly maps to Builder. Asked for the changeset (added), the load-gap default question (addressed — defaults tobrand_domain_requiredso the brand nudge renders during the sub-second load), and the deterministic-order assertion (addressed —.sort()dropped from the integration test).is_primarydoesn't implyverified— 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-unitforagent-visibility-gate.test.ts— 16 pass (10 existing + 6 new)npm run typecheckcleantest:server-integrationruns the new GET-shape tests against a real Postgres🤖 Generated with Claude Code