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
| Capability | Behaviour |
|---|---|
| Gradual release % | One percentage of all users; sticky per user via Flagship targetingKey. Lives in the drawer's Gradual release block. |
| Direct targeting | User and tenant pickers in a Direct targeting block. Targets are compiled ahead of the rollout rule so a percentage can never shadow them. |
| Released column | Derived from configured rules (e.g. 0%, 40% rollout · 1 user configured, Targeted, Rule-based). Configuration, not a measured audience — header tooltip says so. |
| Create flags | Key, 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 flags | Only 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/envsand 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/adminroutes +lib/flag-routes.ts).- List merges every Flagship flag with the catalog (
cataloguedfield). Key gate is Flagship key pattern /Object.hasOwn— not “must already be inPLATFORM_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.
| Flag | Gates | Status |
|---|---|---|
studio_header_navigation | Project switcher, app switcher, refresh button in the studio header (Control plane) | Landed |
mcp_server | MCP OAuth consent and every MCP tool call (MCP server) | Removed by #982 (MCP always on) |
agents | Agents 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) |
workflows | Workflows 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_published | Whether 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 aftersessionMiddlewareand returns403 {error:"feature_disabled"}unless the flag evaluates to exactlytruefor the session's tenant and user. A lookup failure, timeout, type mismatch, or missingFLAGSbinding falls back to the catalog default (off) and refuses. Same response shape as themcp_servergate. - 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/meloads, 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
internalGuardengine routes inworkflows-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).
Linking to a flag's drawer (#923, merged)
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.
Related
- Monorepo layout (
apps/admin) · Admin Secrets · Secrets & environments · Control plane (flag-gated studio chrome) · MCP server · Workflows · Agents - Plan epic:
docs/plans/admin.mdin the monorepo
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.
| Piece | Detail |
|---|---|
| Evaluated by | Billing lifecycle job, per tenant, only when that tenant's hosting-grace deadline has passed |
| Context | tenantId, userId = tenantId, env = BRILLIANT_ENV (same shape as require-flag.ts) |
| On | Suspend without unpublishing (appsKept: true in the audit row) |
| Off / not created yet | Unpublish + suspend; the job logs billing.keep_apps_flag_not_found with a count |
| Unreadable | Postpone 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/:keyrefreshes 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 inpackages/capabilities(Effect-free). Only the control-plane worker reads flags, viaPOST {POSTHOG_HOST}/flags/?v=2with existingPOSTHOG_TOKEN. - Catalog is four flags:
studio_header_navigation,agents,workflows,billing_keep_apps_published.mcp_serveris removed (MCP always on; optionalMCP_DISABLED=truekill switch).studio_admin_banner_testalso 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-unpublishesunchanged. Strict read also fails on degradederrorsWhileComputingFlags(unless the flag says true) and onflags_quota_limited. A flag disabled in PostHog drops out of the answer and reads like deleted.- Targeting in PostHog: flags exist in staging project
666164and prod664776, group-aggregated ontenant, at 0%. To turn one on for a tenant: release condition on grouptenant,$group_key= tenant id, plusenv(prod/staging). Side envs share the staging project. - Rollout still pending: deploy control plane first, then
infrawithallow-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
664776at 0% before enabling anywhere in prod. - Not everything in #989 is behind this flag: the
/pricingrestyle and single-app build attribution ship on deploy (details).
Product UI: Studio billing UI (#989).