Skip to content

feat(feature-flags): admin pages, writes and audit (3/7) - #536

Merged
aixle-com[bot] merged 3 commits into
developfrom
feature/feature-flags-admin
Oct 21, 2026
Merged

aixle-com[bot] merged 3 commits into
developfrom
feature/feature-flags-admin

Conversation

@aixle-com

@aixle-com aixle-com Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Feature flags 3/7 (board task #168, design docs/research/technical-feature-flags-system-design-research-2026-10-21.md §3.1, §3.3, §6.1, §7.1, §7.2). Super admins can now change flags from /admin; company admins still never see them.

  • FeatureFlags::Admin (app/services/feature_flags/admin.rb): set_global, clear_global, set_override, remove_override, turn_off_everywhere, plus prune for orphaned rows (feature_flag.pruned, §7.2). Each one takes actor: and a required reason:. It writes the rows and exactly one Audit in one transaction:
    • auditable is the flag row, associated is the company for overrides, user is true_user, and comment is the reason;
    • audited_changes is { "enabled" => [old, new] }, and turn-off-everywhere also stores the removed overrides.
    • After the transaction it logs the change with the tagged logger and calls FeatureFlags.version_token.bump, through ActiveRecord.after_all_transactions_commit. So a caller's surrounding transaction delays the bump until it commits, and a rollback drops it.
  • Refusals raise new errors in the FeatureFlags namespace, WriteRefused and EnvLocked < WriteRefused. Nothing is written when there is no reason, the flag is ENV-locked, the key is undeclared, a global flag is given an override, or the override to remove does not exist.
  • Pages: Admin::FeatureFlagsController and Admin::FeatureFlagOverridesController are custom pages, not Administrate dashboards.
    • GET /admin/feature_flags has one row per declared flag with key, description, owner, kind, scope, default, ENV ("locked by FEATURE_X"), global value, override counts (on/off), the value for companies without an override, and badges (past remove-by, same everywhere 30+ days). Orphaned rows are listed with a delete action that needs a reason.
    • GET /admin/feature_flags/:key has the source matrix with the winner highlighted, the global control (on / off / use default) with a reason, Turn off everywhere, the overrides table (ENV-shadowed overrides marked), a company search showing explain for each match, Add override, and the audit history newest first. ENV-locked flags render every control inside <fieldset disabled> and name the variable.
    • There is a "Feature flags" link in the admin navigation, and a "Feature overrides" panel on /admin/companies/:id.
  • FeatureFlags::Overview is the read model behind both pages.
  • CHANGELOG has an entry under Added (Admin).

Decision to review: the pages resolve against the committed rows

The admin pages use the same FeatureFlags::Resolver that Feature.explain uses, but over FeatureFlag.load_snapshot instead of the process's cached FeatureFlags.store snapshot. The cached snapshot can lag a write by the store's refresh interval (5 s), or by max staleness (60 s) while Redis is down. Showing it would let an admin save a change and then see the old value on the page the save redirects to. FeatureFlags::Store is unchanged. The pages do not touch the pinned Current.feature_snapshot (decision #45822), and they add no re-read anywhere a request or job checks a flag.

Smaller choices

  • An ENV-locked flag refuses all five writes, including removing an override. This matches "controls disabled, write endpoints refuse changes". Orphan pruning is the only write that ignores ENV, because the key is not declared.
  • Every write updates the flag row's updated_at and updated_by, override writes included. "Same everywhere 30+ days" counts from that timestamp. For a flag with no row it counts from introduced:, and with neither it shows no badge.
  • Changing an existing override replaces its reason and records the admin as its created_by (who set the current value).
  • FakeFeatureFlagVersionToken gained a bumps count and an on_bump hook, used to show that the bump happens after commit.

Type of change

  • New feature

How was this tested?

  • test/services/feature_flags/admin_test.rb uses real rows and the version-token fake. It covers each write and its audit shape, the bump happening after commit (open transaction count at bump time), the bump being deferred inside a caller's transaction and dropped on rollback, the reason being required for every write, the ENV lock refusing every write, a failure inside the transaction leaving no rows, no audit and no bump, and pruning.
  • test/services/feature_flags/overview_test.rb covers an empty registry, flags with no rows, ENV locks and counts from the rows, both badges, and orphans.
  • test/integration/admin/feature_flags_test.rb covers company admins and employees getting the /admin rejection on every route with nothing written, an empty registry, flags without rows, ENV-locked controls being disabled and the write endpoints refusing, turn off everywhere, search, check, add and remove override, a global flag refusing an override, orphan listing and deletion, and the company panel.
  • Run on a Coder workspace (aixle-prod-69c1fb03) in the docker-compose.ci.yml web image, after bin/vite build:
    • full bin/rails test on f61f3a31: 8708 runs, 0 failures, 0 errors, 3 skips (the Redis-only version-token cases);
    • brakeman on f61f3a31: 0 warnings;
    • on the head, dd4baa86 (which only fixes lambda spacing in a test): rubocop on the 11 changed Ruby files reports no offenses, and test/services/feature_flags + test/integration/admin/feature_flags_test.rb give 113 runs, 0 failures.
  • ESLint, tsc and Vitest were not run: no frontend files changed.

How to test manually: declare a flag in config/feature_flags.yml (copy one from test/fixtures/files/feature_flags_registry.yml), sign in as a super admin and open /admin/feature_flags. Open the flag, set the global value with a reason, search a company, add an override, then use Turn off everywhere. The History table records each step. Restart with FEATURE_<KEY>=off: the page shows the lock and every control is disabled.

Related issues

Board task #168 (Feature flags 3/7). Parent research #164. It builds on #166 / #530 (tasks 1 and 2), and task 6 (pilot ops flag) waits for this one.

Checklist

  • All commits are signed off for the DCO (git commit -s).
  • Tests added.
  • User-visible change has an entry under [Unreleased] in CHANGELOG.md.
  • Conventional commit messages.
  • make check_all: not run as one command. The backend parts (full rails suite, rubocop on the changed files, brakeman) ran separately on Coder, see above. No frontend changes.

aixle-developer-agent added 3 commits October 21, 2026 17:40
…s panel (3/7)

Super admins change flags from /admin/feature_flags only. Every write goes through FeatureFlags::Admin, which records one Audit in the write's transaction and bumps the version token after commit, so other processes reload only a change that exists.

Signed-off-by: aixle-developer-agent <[email protected]>
@aixle-com
aixle-com Bot marked this pull request as ready for review October 21, 2026 18:10
@aixle-com
aixle-com Bot merged commit 1f4ca0b into develop Oct 21, 2026
17 checks passed
artempartos added a commit that referenced this pull request Oct 22, 2026
…rs-without-channels-audit

* origin/develop:
  feat(feature-flags): admin pages, writes and audit (3/7) (#536)

# Conflicts:
#	CHANGELOG.md
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.

0 participants