Public: anyone can read this; the crew can change it.

Feature flags with live A/B baked in: code-declared flags, per-forge, per-user and percentage values, each variant's use measured, flag debt in the gate #1356

Closed opened this in answer to
Closed without merging

The forge now has code-declared flags with live A/B read-outs, but the apps half of the issue is not built. The new flag tests pass, but only with a temporary local edit to src/http/server.ts.

Notes

stopped closed without shipping deploy bdd84f2

opened this

The forge now has code-declared flags with live A/B read-outs, but the apps half of the issue is not built. The new flag tests pass, but only with a temporary local edit to src/http/server.ts. The sandbox here refuses the unix-socket listen in serve(), so I swapped it for a TCP port to run the server tests, then reverted it. tsc is clean.

What changed

  • Declarations: src/core/flag_decls.ts holds every flag, each with a name, a one-line why, variants, a default and an owner issue. The first flag is ui.density (comfortable or compact), owned by #1137. It sets data-density on <html>, with a small CSS rule for the compact side.
  • Values and counting: src/core/flags.ts reads with flag(ctx, "name"). A viewer's variant is the first match of user, role (admin, agent, member), percentage, whole forge, then default. Percentages hash flag plus viewer, so a person always lands on the same side. Rules come from an in-process snapshot that refreshes every 3 seconds. Use is counted once per request per flag and written in batches every 5 seconds. Migration 73 adds the flag_rule and flag_use tables.
  • Settings → Flags (admin): src/web/pages/flags.ts lists each flag with its default, live values and requests per variant for 7 and 30 days. It has forms to set and remove values, plus a "Make the winner" button. The routes are in src/http/server.ts and the nav link is in origins.ts.
  • Gate: scripts/flag-debt.ts fails on a declared flag nothing reads and on a read of an undeclared name. It also checks name format. An undeclared read throws at runtime too. test/flags.test.ts is added to GATE.
  • Tests: they cover the debt check, a 1000-viewer percentage split within ±50 that is stable per viewer, precedence, and rule validation. They also cover read-out counts matching flag_use, the 7/30-day window, admin-only access, a cross-origin refusal, and the winner replacing all other rules.
  • Docs: docs/FLAGS.md.

Left out

  • Apps: the template flags file, FORGE_FLAGS_URL, the one-file client and the per-app settings page. A client with no server behind it would be dead code, and the app-side declarations need their own design. It needs its own issue.
  • Winner button: the default lives in code, so the button cannot edit it or open a pull. It sets the forge-wide value, drops the other rules, and tells the admin to open the pull that makes the winner the default and removes the losing path.
  • Counts: these are requests per variant, not unique viewers. Signed-out viewers see only forge rules or the default, since there is nothing stable to hash.

Failing check on main: test/check-list.test.ts already fails on this branch. test/chaos.test.ts, test/fuzz-found.test.ts and test/fuzz-parsers.test.ts are in neither GATE nor EXCLUDED. They came in with the last merge, and I did not touch them. Whoever owns them needs to place them.

To try it: sign in as an admin, open /settings/flags, set compact for 40% of viewers, and load a few pages. The counts show up in the table. bun scripts/flag-debt.ts is the debt check.

Closes #1137

commented

I merged origin/main into the branch and renumbered my flags migration to 74, since main now has its own migration 73 (OAuth authorization codes, #971). That conflict in src/core/schema.ts was why the check said the branch didn't merge. The merge is pushed, so the check should now run again.

Main's migration 73 is untouched and the flag tables follow it as migration 74. I didn't need to change any other code in the merge.

test/schema-migrations.test.ts and test/kernel.test.ts pass here. test/flags.test.ts could not run in this sandbox: it needs to listen on a unix socket and got EPERM. That failure is the sandbox's limit, not the code, so the forge's check is the first real run of the flag tests on the merged tree. I didn't run the full suite.

This pull adds code-declared feature flags with live A/B. The admin can set a flag per forge, user, role or percentage. Each variant that runs is counted per day. The values and counts live in two new tables, flag_rule and flag_use. If they are lost, every flag returns to its declared default.

To try it, open the preview at https://lab--1356--forge-trevato-apps.open-platform.sh once it is up.

🤖 Generated with Claude Code

commented

Parked by the crew: the check failed ("the board > signed in: a bare page, four live regions, dark by default") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs