Skip to content

Admin Feature Flags ​

Path: apps/admin (Feature Flags UI + routes) · packages/capabilities (flagship-api, PLATFORM_FLAGS)
Status: Landed in #174 (merged 2026-09-30). Superseded: the admin Flags page and Flagship are removed by #982 (merged) — manage flags in PostHog.

Staff admin → Feature Flags (historical) managed Flagship flags used across the platform (for example studio gates like studio_header_navigation). Catalog keys live in PLATFORM_FLAGS in @brilliant/capabilities; the admin can also create keys that are not yet in the catalog.

What staff can do ​

CapabilityBehaviour
Gradual release %One percentage of all users; sticky per user via Flagship targetingKey. Lives in the drawer's Gradual release block.
Direct targetingUser and tenant pickers in a Direct targeting block. Targets are compiled ahead of the rollout rule so a percentage can never shadow them.
Released columnDerived from configured rules (e.g. 0%, 40% rollout · 1 user configured, Targeted, Rule-based). Configuration, not a measured audience — header tooltip says so.
Create flagsKey, type, description, default (non-boolean), reason. New flags start disabled with no rules. Catalog keys keep catalog type; missing catalog keys offered as quick-pick chips. Uncatalogued flags show Not in code — nothing evaluates them until registered in PLATFORM_FLAGS.
Delete flagsOnly when disabled. Server re-reads and returns 409 flag_active if still enabled. UI Delete disabled for active / missing flags; confirm with audit reason.

Targeting shape (monday-style) ​

  • Gradual release and direct targeting work at the same time in the drawer.
  • Compile order when saving: users → tenants → everyone-with-rollout → advanced; priorities are renumbered. Unrepresentable rules are preserved verbatim.
  • No environment rules in the UI: each env has its own Flagship app, so /api/flags/envs and the env picker are gone. A leftover env rule shows as a read-only Advanced rule with a Remove button.

API & contracts ​

  • POST /api/flags, DELETE /api/flags/:key (apps/admin routes + lib/flag-routes.ts).
  • List merges every Flagship flag with the catalog (catalogued field). Key gate is Flagship key pattern / Object.hasOwn — not “must already be in PLATFORM_FLAGS”.
  • Create-on-miss in enable/disable is limited to catalog keys and a Flagship 404. It used to fire on any error, so a transient Flagship 500 could overwrite an existing flag with catalog defaults and wipe its rules. Non-404 Flagship errors are now 502.
  • PutFlagInputSchema (flagship-api.ts): any Flagship-pattern key; catalog keys type-pinned; uncatalogued keys need same-typed variations (variationType()).
  • Contract flagship-delete-disabled-only: delete only when disabled.
  • Contract audit-before-flagship-write: a Flagship read may precede the audit (duplicate check, current description); no write may precede it (avoids auditing a “create” that then 409s).

Catalog flags that gate product features ​

Each catalog key is a boolean, default off, owned by brilliant-admin. Turn one on per tenant or user from this admin page.

FlagGatesStatus
studio_header_navigationProject switcher, app switcher, refresh button in the studio header (Control plane)Landed
mcp_serverMCP OAuth consent and every MCP tool call (MCP server)Removed by #982 (MCP always on)
agentsAgents settings section, mobile Agents tab, the Agent dock, the session /agents* API, and adding an agent participant to a thread (Agents)Landed in #505 (merged 2026-10-06)
workflowsWorkflows settings section, mobile More sheet row, the app editor workflow index (#964), the session /workflows API, and conductor's internal workflow builder API (Workflows)Landed in #505 (merged 2026-10-06)
billing_keep_apps_publishedWhether a tenant's apps stay published when its 14-day hosting grace ends; read strictly by the billing lifecycle job (below)Landed in #920 (merged 2026-10-14)

Gating pattern (from #505, merged): hide on the UI, error on the API, both fail closed.

  • API: control-plane middleware requireFlag(key) (apps/control-plane/src/middleware/require-flag.ts) runs right after sessionMiddleware and returns 403 {error:"feature_disabled"} unless the flag evaluates to exactly true for the session's tenant and user. A lookup failure, timeout, type mismatch, or missing FLAGS binding falls back to the catalog default (off) and refuses. Same response shape as the mcp_server gate.
  • UI: the nav hides the entry point, and FlagGatedPage (apps/control-plane/web/src/components/settings/FlagGatedPage.tsx) wraps the route so a direct link shows a plain "not available" notice instead of mounting the page and firing its data fetches. It shows a skeleton until /me loads, so the notice doesn't flash.
  • Internal routes with no session: requireFlagForTenant(key, getTenantId) (same file) gates service-to-service routes by tenant. It asks Flagship with the tenant id as both tenant and user, since there is no real user, and returns the same 403. It must run after whatever middleware resolves the workspace or tenant.
  • Execution stays ungated: the internalGuard engine routes in workflows-engine.ts (fire, timeline, charge) don't check the flag, so a workflow enabled before the flag was turned off keeps running on schedule. Builder routes (create, edit, test-run, enable) are gated; execution is not.
  • Both flags default to off for everyone. Nothing shows until a tenant or user is flagged on here.

Not claimed (explicit non-goals in #174) ​

  • Released column does not query a live population.
  • Uncatalogued flags are not read by product code until added to PLATFORM_FLAGS.
  • Phone layout quirks of the admin shell are out of scope (staff desktop surface).

Since #923 (merged 2026-10-15), the open targeting drawer is the flag search param: /flags?flag=<key> opens that flag's drawer, and closing it clears the param. The row still comes from the flags query, so a key that is not in the list opens nothing. Details and the other admin URL params: Admin client state.

billing_keep_apps_published (#920, merged) ​

PR #920 (opened 2026-10-14 13:40 IDT by yoni-monday, merged 2026-10-14 14:20 IDT, merge b3f014bf) added this boolean catalog flag (default off, owner brilliant-admin) and removed the Config key BILLING_KEEP_APPS_PUBLISHED from #916.

PieceDetail
Evaluated byBilling lifecycle job, per tenant, only when that tenant's hosting-grace deadline has passed
ContexttenantId, userId = tenantId, env = BRILLIANT_ENV (same shape as require-flag.ts)
OnSuspend without unpublishing (appsKept: true in the audit row)
Off / not created yetUnpublish + suspend; the job logs billing.keep_apps_flag_not_found with a count
UnreadablePostpone this tenant only; other tenants in the batch continue. After 3 unreadable answers in a row the rest of the run is postponed without asking

getFlagStrict (new in @brilliant/capabilities, next to getFlag) returns { ok: true, value, notFound? } or { ok: false, reason } instead of collapsing failures to the code default. Use it wherever acting on a guessed default would be harmful. FLAG_NOT_FOUND gives the default with notFound: true; other error codes, wrong type, a throw, or a timeout are unreadable. Lifecycle uses a 3 s timeout on this path. No FLAGS binding gives the default; a binding without getBooleanDetails is unreadable. Contract @cc keep-apps-flag-unreadable-never-unpublishes.

Operator after deploy: staging and prod each have their own Flagship app (side envs use staging's). In each environment's admin › Flags, staging then prod, create billing_keep_apps_published from the catalog, add a rule for env and/or tenantIds, and enable it. Until it exists in an environment it reads as off there.

Full product rules: Billing: keeping apps published via Flagship (#920).

Drawer edits and saves run on a state machine (#926, merged) ​

Since #926 (merged 2026-10-15 10:33 IDT), the targeting drawer's draft and save run in flagDrawerMachine (apps/admin/web/src/features/flags/) instead of component state. The save rules staff see are the same and are now in one place (flagDraftIssue):

  • A save needs a reason (it goes to the audit log), targeting that compiles, an existing variation for every rule and the default, and the off variation as default whenever the gradual release is under 100%. A refused save stays on the form with the message and sends nothing.
  • Any targeting edit turns the flag on, and a rollout under 100% switches the default to off. Removing a leftover advanced rule does not turn the flag on.
  • A successful PUT /api/flags/:key refreshes the flag list and that flag's changelog and closes the drawer. A rejected PUT keeps the drawer open with the server's error.

Machine details: Admin client state.

Planned replacement by PostHog (#948–#982, stack complete) ​

The PostHog PR stack replaced Flagship with PostHog and removed the admin's Flags page. Steps 1–6 are all merged (#948, #953, #959, #971, #977, #982). Flags are managed in PostHog, not here. See PostHog — Step 6.

Feature flags move to PostHog (#982, merged) ​

#982 "PostHog 6/6: feature flags from PostHog, Flagship and the admin Flags page removed, MCP always on" (merged 2026-10-16 05:47 IDT by yoni-monday, merge 94410daa, head cfa4986b).

What landed. The admin Flags page is gone. Feature flags are evaluated and managed in PostHog. Flagship REST client, routes, changelog, tests, nav entry and admin.flag.* audit allowlist entries are deleted. The HTML sections above describe the Flagship UI as it existed before this cutover (kept for history).

  • Evaluation lives in apps/control-plane/src/flags.ts (Effect service: Flags, flagsLayer / makeFlags, FlagsUnreadable). The catalog stays in packages/capabilities (Effect-free). Only the control-plane worker reads flags, via POST {POSTHOG_HOST}/flags/?v=2 with existing POSTHOG_TOKEN.
  • Catalog is four flags: studio_header_navigation, agents, workflows, billing_keep_apps_published. mcp_server is removed (MCP always on; optional MCP_DISABLED=true kill switch). studio_admin_banner_test also went.
  • getFlag / getAllFlags: 10s in-isolate cache, ~800ms timeout, failure → catalog default (false). /me = one request for all flags.
  • getFlagStrict (billing): 3s, no cache, failure → ok: false (does not unpublish); missing from PostHog → off (notFound). Contract @cc keep-apps-flag-unreadable-never-unpublishes unchanged. Strict read also fails on degraded errorsWhileComputingFlags (unless the flag says true) and on flags_quota_limited. A flag disabled in PostHog drops out of the answer and reads like deleted.
  • Targeting in PostHog: flags exist in staging project 666164 and prod 664776, group-aggregated on tenant, at 0%. To turn one on for a tenant: release condition on group tenant, $group_key = tenant id, plus env (prod/staging). Side envs share the staging project.
  • Rollout still pending: deploy control plane first, then infra with allow-deletes (destroys Flagship apps). Do not destroy Flagship before the new worker is live.

Full design: PostHog — Step 6 (#982, merged). MCP: MCP always on. Billing targeting: Billing.

billing_studio_ui (#989, merged) ​

PR #989 (merged 2026-10-17 08:27 IDT by yoni-monday, merge 3b46067e) adds catalog flag billing_studio_ui to PLATFORM_FLAGS (packages/capabilities/src/flags.ts): boolean, default off, owner brilliant-admin. It's the fifth catalog flag after #982 (repo gotchas/data.md lists five). When on, studio shows Settings › Plans, Settings › Usage and the trial-ending banner (owners and admins). Off hides those entry points only; the billing API is unchanged, and a return from Stripe Checkout still reaches Plans even if the flag was turned off meanwhile.

  • Staging: exists in PostHog project 666164, targeted on the tenant's $group_key.
  • Prod: not created yet. Create it in project 664776 at 0% before enabling anywhere in prod.
  • Not everything in #989 is behind this flag: the /pricing restyle and single-app build attribution ship on deploy (details).

Product UI: Studio billing UI (#989).