Skip to content

feat(feature-flags): registry, resolver and Feature facade (1/7) - #526

Merged
NOX73 merged 4 commits into
developfrom
feature/feature-flags-registry
Oct 21, 2026
Merged

NOX73 merged 4 commits into
developfrom
feature/feature-flags-registry

Conversation

@aixle-com

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

Copy link
Copy Markdown
Contributor

Board task #166 — first of the seven feature flag tasks from the research in #164 (report, PR #525).

What changed

  • config/feature_flags.yml — the registry, shipped empty (only a commented schema).
  • FeatureFlags::Registry — loads the YAML once at boot, validates and freezes it. Fails boot (InvalidRegistry, every problem listed at once) on: a key not matching /\A[a-z][a-z0-9_]*\z/; a key mapping into FEATURE_FLAGS_* (flags, flags_*); a missing description/owner/kind/scope/default; bad values for those; a release flag without remove_by; an unknown attribute.
  • FeatureFlags::EnvSource — the ENV lock layer, read from the new feature_flags: block in config/settings.yml (env, refresh_interval_seconds, max_staleness_seconds), so app/** never reads ENV. on|true|1 / off|false|0, case-insensitive and trimmed; empty = unset; anything else fails boot (InvalidEnv) naming the variable. A FEATURE_* variable for an undeclared key only warns.
  • FeatureFlags::Resolver — pure function of registry + ENV source + snapshot: ENV > company override > (reserved: rollout %) > global > declared default. company: required for company-scoped flags (nil legal, skips the override step); passing it to a global flag raises ArgumentError; undeclared key raises FeatureFlags::UnknownFlag.
  • Feature.enabled?(key, company:) / Feature.explain(key, company:) — explain returns a FeatureFlags::Resolution (value, deciding source, env_var, shadowed layers). No disabled?, setters or block form. Unknown key raises in development/test; elsewhere returns false and reports to Sentry.
  • FeatureFlags::Snapshot + FeatureFlags::MemoryStore — the snapshot interface the resolver reads; the in-memory store is the only store until task 2.
  • Boot — config/initializers/feature_flags.rb calls FeatureFlags.boot! after initialization. Undeclared FEATURE_* → one Rails.logger.warn + Rails.error.report per variable; both new sources (feature_flags.unknown_flag, feature_flags.undeclared_env) are added to the Sentry forwarding list in config/initializers/sentry.rb.
  • Tests helpers — test/support/feature_flags_helper.rb, included in ActiveSupport::TestCase (so integration and system tests too): store reset in setup; with_feature, with_feature(..., company:), stub_feature_env, plus with_feature_registry to declare test-only flags. No DB/Redis/real ENV; no vendor stubbing or any_instance.
  • Docs — docs/reference/configuration.md gets a Feature flags section with FEATURE_<KEY>, FEATURE_FLAGS_REFRESH_INTERVAL, FEATURE_FLAGS_MAX_STALENESS; portal copy refreshed (byte-identical, as docs:sync_config_reference writes it).

Decisions

  • Unknown keys are lenient outside Rails.env.local?, so staging behaves like production.
  • Invalid values are only rejected for declared flags; a variable for an undeclared key warns whatever its value (removing a flag must not need an infra change).
  • Unknown registry attributes fail boot, to catch typos; env_setting is not accepted yet (task 6 adds it).
  • Resolution#shadowed never lists the declared default.
  • No CHANGELOG entry: the registry is empty, so there is no user- or operator-visible change yet.

How to test

docker compose exec -T web bin/rails test test/services/feature_test.rb test/services/feature_flags test/config/configuration_reference_test.rb
docker compose exec -T web bundle exec rubocop

Tests cover every row of §3.3 and all 11 worked examples of §3.4 using test/fixtures/files/feature_flags_registry.yml (the shipped registry is empty).

Not in this PR

DB tables/models, Redis version token, Current.feature_snapshot (task 2); admin pages (3); frontend payload (4); lifecycle tooling and developer guide (5).

…acade

First of the seven feature flag tasks (#166, design in #164). The registry ships empty, so nothing changes in behaviour.

Signed-off-by: Aixle-Developer-Agent <[email protected]>
Comment thread test/support/feature_flags_helper.rb Resolved
Comment thread app/services/feature.rb Resolved
Comment thread app/services/feature_flags/registry.rb Resolved
Aixle-Developer-Agent added 3 commits October 21, 2026 13:16
…keys once

- config/settings/test.yml empties feature_flags.env, and the per-test setup
  resets the ENV layer with the store, so a FEATURE_* value in the shell, CI
  or .env never reaches a test; stub_feature_env is the only way to lock one.
- Feature reports an undeclared key to Sentry once per key per process
  instead of on every call; it still reads as off every time.

Signed-off-by: Aixle-Developer-Agent <[email protected]>
…tever it holds

Signed-off-by: Aixle-Developer-Agent <[email protected]>
@NOX73
NOX73 merged commit 6d96fab into develop Oct 21, 2026
16 checks passed
@NOX73
NOX73 deleted the feature/feature-flags-registry branch October 21, 2026 13:31
artempartos added a commit to Hitin/flow that referenced this pull request Oct 21, 2026
* commit '2ecb0ecb':
  fix(admin): keep form fields dark after a Turbo visit (AixleHQ#533)
  feat(overview): rename Total Spend card to Token Cost (AixleHQ#532)
  fix(admin): preload company session limits on the companies index (AixleHQ#523)
  fix(board): keep the board settings gear on the toolbar row (AixleHQ#524)
  feat(capacity): give every AWS Marketplace company at least 3 workers (AixleHQ#531)
  fix(mcp): refuse token changes while impersonating; error on a token no company accepts (AixleHQ#528)
  feat(feature-flags): registry, resolver and Feature facade (1/7) (AixleHQ#526)
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